诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

MACD_signal EA

MACD_signal EA是结合MACD和ATR信号开发的MT4智能交易系统。

MACD_signal EA源码:

   //+------------------------------------------------------------------+
   //|                                                  MACD_signal.mq4 |
   //|                                                           tom112 |
   //+------------------------------------------------------------------+
   #property copyright "tom112"
   #property link "http://www.125808047.com/"
   
   input double TakeProfit = 200;
   input double Lots = 0.1;
   input double TrailingStop = 100;
   input int Pfast=7;
   input int Pslow=36;
   input int Psignal=7;
   input double LEVEL=0.001;
   double Points;
   bool cg = false;
   
   int init()
   {
   Points = MarketInfo (Symbol(), MODE_POINT);
   
   return(0);
   }
   
   int deinit()
   {
   Comment("www.125808047.com");
   return(0);
   }
   
   void OnTick(void)
   {
   double MacdCurrent=0, MacdPrevious=0, SignalCurrent=0;
   double SignalPrevious=0, MaCurrent=0, MaPrevious=0;
   int cnt=0, total;
   double Tv[2][500] ;
   double Range, rr, Delta, Delta1;
   
   if(Bars<100)
   {
   Print("bars less than 100");
   return;
   }
   if(TakeProfit<10)
   {
   Print("TakeProfit less than 10");
   return; 
   }
   Range = iATR(NULL,0,200,1);
   rr = Range*LEVEL;
   Delta=iMACD(NULL,0,Pfast,Pslow,Psignal,PRICE_CLOSE,MODE_MAIN,0)-
   iMACD(NULL, 0 ,Pfast,Pslow,Psignal,PRICE_CLOSE,MODE_SIGNAL,0);
   Delta1=iMACD(NULL,0,Pfast,Pslow,Psignal,PRICE_CLOSE,MODE_MAIN,1)-
   iMACD(NULL, 0 ,Pfast,Pslow,Psignal,PRICE_CLOSE,MODE_SIGNAL,1);
   
   if(OrdersTotal()<1) 
   {
   
   if(AccountFreeMargin()<(1000*Lots))
   {
   Print("We have no money");
   return; 
   }
   
   if( Delta>rr && Delta1<rr )
   {
   cg = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Points,"macd signal",16384,0,Red); 
   if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
   return; 
   }
   if( Delta < -rr && Delta1 > -rr )
   {
   cg = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Points,"macd sample",16384,0,Red);
   if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
   return; 
   }
   
   return;
   }
   
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
   cg = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if(OrderType()<=OP_SELL && 
   OrderSymbol()==Symbol()) 
   {
   if(OrderType()==OP_BUY) 
   {
   if(Delta<0)
   {
   cg = OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
   }
   if(TrailingStop>0) 
   { 
   if(Bid-OrderOpenPrice()>Points*TrailingStop)
   {
   if(OrderStopLoss()<Bid-Points*TrailingStop)
   {
   cg = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Points*TrailingStop,OrderTakeProfit(),0,Red);
   }
   }
   }
   }
   else
   {
   if(Delta > 0)
   {
   cg = OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); 
   }
   if(TrailingStop>0)
   {
   if((OrderOpenPrice()-Ask)>(Points*TrailingStop))
   {
   if(OrderStopLoss()==0.0 || 
   OrderStopLoss()>(Ask+Points*TrailingStop))
   {
   cg = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Points*TrailingStop,OrderTakeProfit(),0,Red);
   }
   }
   }
   }
   }
   }
   }
打赏
版权所有转载请注明标题及链接:峰汇在线 » MACD_signal EA
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏