外汇EA
MQ5源码共享
回复:0  浏览:893
  • 楼主admin 圈主
  • 2020-01-01 14:26
Night Scalper Multi 是一个多币种夜间剥头皮EA交易,它在小范围内交易直到终端时间零点,范围(r)是使用布林带指标确定的。BBHandle=iBands(symb,0,per,0,dev,0);   CopyBuffer(BBHandle,1,0,1,up);   CopyBuffer(BBHandle,2,0,1,dn);   double r=up[0]-dn[0];
仓位的建立是在Start指定的小时数之后建立的, 并且该交易品种不能有已经建立的仓位。if(CountTrades(symb) 1 TimeCurrent() StringToTime(s))
如果价格低于布林带的下方边界,并且通道宽度小于Razmah变量指定的范围,就买入。if(Ask dn[0] r razmah*_Point) trade.PositionOpen(symb,0,Lot,Ask,Ask-stop*_Point,Ask+take*_Point);
如果价格高于布林带的上方边界,并且通道宽度小于Razmah变量指定的范围,就卖出。if(Bid up[0] r razmah*_Point) trade.PositionOpen(symb,1,Lot,Bid,Bid+stop*_Point,Bid-take*_Point);
仓位是通过止损关闭或者在零点后强制关闭。else if(CountTrades(symb) 0 TimeCurrent() StringToTime(s)) CloseAll(symb);
交易是通过SymbolTrade函数完成的,并且使用了СTrade类:void SymbolTrade(string symb,int stop,int take,int per,double dev,double razmah,int start) {   string s=(string)start+ :00 ;   double Ask=SymbolInfoDouble(symb,SYMBOL_ASK);   double Bid=SymbolInfoDouble(symb,SYMBOL_BID);   BBHandle=iBands(symb,0,per,0,dev,0);   CopyBuffer(BBHandle,1,0,1,up);   CopyBuffer(BBHandle,2,0,1,dn);   double r=up[0]-dn[0];   if(CountTrades(symb) 1 TimeCurrent() StringToTime(s))   {     if(Ask dn[0] r razmah*_Point) trade.PositionOpen(symb,0,Lot,Ask,Ask-stop*_Point,Ask+take*_Point);     if(Bid up[0] r razmah*_Point) trade.PositionOpen(symb,1,Lot,Bid,Bid+stop*_Point,Bid-take*_Point);   }   else if(CountTrades(symb) 0 TimeCurrent() StringToTime(s)) CloseAll(symb); }
交易的操作是在新柱上进行的。if(bars!=Bars(NULL,0))   {     if(Symbol1!= ) SymbolTrade(Symbol1,StopLoss1,TakeProfit1,BBPeriod1,BBDev1,Razmah1,Start1);     if(Symbol2!= ) SymbolTrade(Symbol2,StopLoss2,TakeProfit2,BBPeriod2,BBDev2,Razmah2,Start2);     if(Symbol3!= ) SymbolTrade(Symbol3,StopLoss3,TakeProfit3,BBPeriod3,BBDev3,Razmah3,Start3);     ...   }   bars=Bars(NULL,0);
设置:input string Symbol1   = USDCAD ;      // 交易品种1名称input int    StopLoss1   = 370;         // 止损1input int    TakeProfit1 = 20;          // 获利1input int    BBPeriod1   = 40;          // 布林带周期数1input double BBDev1     = 1;         // 布林带偏移1input double Razmah1   = 450;         // 布林带宽度点数1input int    Start1     = 19;          // 起始时间1input string Symbol2   = GBPUSD ;      // 交易品种2名称input int    StopLoss2   = 450;         // 止损2input int    TakeProfit2 = 80;          // 获利2input int    BBPeriod2   = 8;         // 布林带周期数2input double BBDev2     = 1;         // 布林带偏移2input double Razmah2   = 200;         // 布林带宽度点数2input int    Start2     = 20;          // 起始时间2input string Symbol3   = NZDUSD       // 交易品种3名称input int    StopLoss3   = 410;         // 止损3input int    TakeProfit3 = 40;          // 获利3input int    BBPeriod3   = 4;         // 布林带周期数3input double BBDev3     = 1.2;         // 布林带偏移3input double Razmah3   = 450;         // 布林带宽度点数3input int    Start3     = 19;          // 起始时间3input string Symbol4   =           // 交易品种4名称input int    StopLoss4   = 500;         // 止损4input int    TakeProfit4 = 40;          // 获利4input int    BBPeriod4   = 24;          // 布林带周期数4input double BBDev4     = 1;         // 布林带偏移4input double Razmah4   = 200;         // 布林带宽度点数4input int    Start4     = 20;          // 起始时间4input string Symbol5   =           // 交易品种5名称input int    StopLoss5   = 500;         // 止损5input int    TakeProfit5 = 40;          // 获利5input int    BBPeriod5   = 24;          // 布林带周期数5input double BBDev5     = 1;         // 布林带偏移5input double Razmah5   = 200;         // 布林带宽度点数5input int    Start5     = 20;          // 起始时间5input string Symbol6   =           // 交易品种6名称input int    StopLoss6   = 500;         // 止损6input int    TakeProfit6 = 40;          // 获利6input int    BBPeriod6   = 24;          // 布林带周期数6input double BBDev6     = 1;         // 布林带偏移6input double Razmah6   = 200;         // 布林带宽度点数6input int    Start6     = 20;          // 起始时间6input string Symbol7   =           // 交易品种7名称input int    StopLoss7   = 500;         // 止损7input int    TakeProfit7 = 40;          // 获利7input int    BBPeriod7   = 24;          // 布林带周期数7input double BBDev7     = 1;         // 布林带偏移7input double Razmah7   = 200;         // 布林带宽度点数7input int    Start7     = 20;          // 起始时间7input string Symbol8   =           // 交易品种8名称input int    StopLoss8   = 500;         // 止损8input int    TakeProfit8 = 40;          // 获利8input int    BBPeriod8   = 24;          // 布林带周期数8input double BBDev8     = 1;         // 布林带偏移8input double Razmah8   = 200;         // 布林带宽度点数8input int    Start8     = 20;          // 起始时间8input string Symbol9   =           // 交易品种9名称input int    StopLoss9   = 500;         // 止损9input int    TakeProfit9 = 40;          // 获利9input int    BBPeriod9   = 24;          // 布林带周期数9input double BBDev9     = 1;         // 布林带偏移9input double Razmah9   = 200;         // 布林带宽度点数9input int    Start9     = 20;          // 起始时间9input double Lot       = 1;         // 交易量
图1. EA交易的结果。EURUSD, H1
图2. EA 交易在日志中的交易
Fig.3. 从 11.01.2016 到 13.09.2016.EA交易的优化结果USDCAD, GBPUSD, NZDUSD, H1