淘客熙熙

主题:外汇交易者聚集地 讨论帖1 -- 江阔云低

共:💬17 🌺18
全看分页树展 · 主题 跟帖
家园 今后计算机取代人主导外汇交易是一个长期的趋势

特别是需要盯盘的日内交易,长期由人操作身体吃不消。

用计算机语言构造交易计划这个早就有了。

这是MT4的Expert Advisors自带的一段示范程序,以移动平均线作为下单指标

//+------------------------------------------------------------------+

//| Moving Average.mq4 |

//| Copyright 2005, MetaQuotes Software Corp. |

//| http://www.metaquotes.net/ |

//+------------------------------------------------------------------+

#define MAGICMA 20050610

extern double Lots = 0.1;

extern double MaximumRisk = 0.02;

extern double DecreaseFactor = 3;

extern double MovingPeriod = 12;

extern double MovingShift = 6;

//+------------------------------------------------------------------+

//| Calculate open positions |

//+------------------------------------------------------------------+

int CalculateCurrentOrders(string symbol)

{

int buys=0,sells=0;

//----

for(int i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)

{

if(OrderType()==OP_BUY) buys++;

if(OrderType()==OP_SELL) sells++;

}

}

//---- return orders volume

if(buys>0) return(buys);

else return(-sells);

}

//+------------------------------------------------------------------+

//| Calculate optimal lot size |

//+------------------------------------------------------------------+

double LotsOptimized()

{

double lot=Lots;

int orders=HistoryTotal(); // history orders total

int losses=0; // number of losses orders without a break

//---- select lot size

lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);

//---- calcuulate number of losses orders without a break

if(DecreaseFactor>0)

{

for(int i=orders-1;i>=0;i--)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }

if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;

//----

if(OrderProfit()>0) break;

if(OrderProfit()<0) losses++;

}

if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

}

//---- return lot size

if(lot<0.1) lot=0.1;

return(lot);

}

//+------------------------------------------------------------------+

//| Check for open order conditions |

//+------------------------------------------------------------------+

void CheckForOpen()

{

double ma;

int res;

//---- go trading only for first tiks of new bar

if(Volume[0]>1) return;

//---- get Moving Average

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

//---- sell conditions

if(Open[1]>ma && Close[1]<ma)

{

res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);

return;

}

//---- buy conditions

if(Open[1]<ma && Close[1]>ma)

{

res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);

return;

}

//----

}

//+------------------------------------------------------------------+

//| Check for close order conditions |

//+------------------------------------------------------------------+

void CheckForClose()

{

double ma;

//---- go trading only for first tiks of new bar

if(Volume[0]>1) return;

//---- get Moving Average

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);

//----

for(int i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;

//---- check order type

if(OrderType()==OP_BUY)

{

if(Open[1]>ma && Close[1]<ma) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);

break;

}

if(OrderType()==OP_SELL)

{

if(Open[1]<ma && Close[1]>ma) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);

break;

}

}

//----

}

//+------------------------------------------------------------------+

//| Start function |

//+------------------------------------------------------------------+

void start()

{

//---- check for history and trading

if(Bars<100 || IsTradeAllowed()==false) return;

//---- calculate open orders by current symbol

if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();

else CheckForClose();

//----

}

//+------------------------------------------------------------------+

有C语言基础上手很快。我就自学了2个周业余时间基本就完全上手。但调制优化到赚钱花了半年时间,这个急不来。

Expert Advisors计算机交易有两大好处。第一就是你能用几年的历史数据来检验自己的交易系统,优化参数,毕竟同一种货币对的主要操盘手们不会都换人,他们总体的操作风格是稳定的。第二就是完全的机械操作下单,像海龟交易法这种就可以完全计算机化,而且24小时在线,不受人的精神体力限制,不受贪婪恐惧的影响。

我个人的建议是,就算不用机器下单,但一定要用程序和历史数据来检验一下自己的交易系统,用自己的钱和时间来检验有点不划算。

关键词(Tags): #外汇交易 EA通宝推:我爱莫扎特,
全看分页树展 · 主题 跟帖


有趣有益,互惠互利;开阔视野,博采众长。
虚拟的网络,真实的人。天南地北客,相逢皆朋友

Copyright © cchere 西西河