当前位置:首页 > 学习资料 > EA那些事 > 正文

EA:趋势加码ea

2019-11-21 14:32:21

ea描述: 趋势加码,适合5000美金以上的,通过计算指标得出多空信号,然后趋势加码。ea源码:extern bool auto_close_order = f

ea描述:

        趋势加码,适合5000美金以上的,通过计算指标得出多空信号,然后趋势加码。

ea源码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

extern bool auto_close_order = false;

// user inputextern double Lots=0.1;              // how many lots to trade at a time 

extern int    MA1_Period=50;extern int    MA2_Period=150;



extern int    MA3_Period=10;extern int    MA4_Period=20;



 int    MA_Price = PRICE_OPEN; int    MA_Mode  = MODE_SMA;

extern double ProfitMade=100;          // how much money do you expect to makeextern double LossLimit=115;          // how much loss can you tolorate//extern int    BasketProfit=10;        // if equity reaches this level, close trades//extern int    BasketLoss=9999;        // if equity reaches this negative level, close trades

extern int    PLBreakEven=9999;       // set break even when this many pips are made (999=off)
       int    Slippage=2;             // how many pips of slippage can you tolorate// naming and numberingint      MagicNumber  = 200601182020; // allows multiple experts to trade on same accountstring   TradeComment = "Divergence_07_";

// Bar handlingdatetime bartime=0;                   // used to determine when a bar has movedint      bartick=0;                   // number of times bars have movedint      objtick=0;                   // used to draw objects on the chartint      tickcount=0;

// Trade controlbool TradeAllowed=true;               // used to manage trades







int init()  {   int    i;   string o;      //remove the old objects    for(i=0; i<Bars; i++)      {      o=DoubleToStr(i,0);      ObjectDelete("myx"+o);      ObjectDelete("myz"+o);     }   objtick=0;

   ObjectDelete("Cmmt");   ObjectCreate( "Cmmt", OBJ_TEXT, 0, Time[20], High[20]+(5*Point) );   ObjectSetText("Cmmt","Divergence=X.XXXX",10,"Arial",White);

   Print("Init happened ",CurTime());   Comment(" ");  }

//+----------------+//| Custom DE-init |//+----------------+// Called ONCE when EA is removed from chart

int deinit()  {   int    i;   string o;   //remove the old objects       for(i=0; i<Bars; i++)      {      o=DoubleToStr(i,0);      ObjectDelete("myx"+o);      ObjectDelete("myz"+o);     }   objtick=0;      Print("DE-Init happened ",CurTime());   Comment(" ");  }
int start()  {

  int sig=1;  //if(TimeHour(TimeCurrent()) >= 0 && TimeHour(TimeCurrent()) < 8)sig = 1;else sig = 2;

   double p=Point;   double spread=Ask-Bid;      int      cnt=0;   int      gle=0;   int      OrdersPerSymbol=0;

   // stoploss and takeprofit and close control   double SL=0;   double TP=0;   double CurrentProfit=0;   double CurrentBasket=0;      // direction control   bool BUYme=false;   bool SELLme=false;         // Trade stuff   double ma0;   double ma1;      double ma2;   double ma3;   double maHI;   double maLO;   double maOPEN;   double ma2_1,ma2_2;   // bar counting   if(bartime!=Time[0])      {      bartime=Time[0];      bartick++;       objtick++;      TradeAllowed=true;     }
   OrdersPerSymbol=0;   for(cnt=OrdersTotal();cnt>=0;cnt--)     {      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);      if( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)        {         OrdersPerSymbol++;

        }     }
   // high and low of [1] and open of [0] either above or below the MA   maHI=High[1];   maLO=Low[1];   maOPEN=Open[0];   ma0=iMA(Symbol(),0,MA1_Period,0,MA_Mode,MA_Price,1);   ma1=iMA(Symbol(),0,MA2_Period,0,MA_Mode,MA_Price,1);      ma2=iMA(Symbol(),0,MA3_Period,0,MA_Mode,MA_Price,1);   ma3=iMA(Symbol(),0,MA4_Period,0,MA_Mode,MA_Price,1);      ma2_1=iMA(Symbol(),0,MA3_Period,0,MA_Mode,MA_Price,0);   ma2_2=iMA(Symbol(),0,MA3_Period,0,MA_Mode,MA_Price,2);              double kdj1 = iStochastic(Symbol(),0,10,5,5,MODE_SMA,1,MODE_MAIN,1);   double kdj2 = iStochastic(Symbol(),0,10,5,5,MODE_SMA,1,MODE_SIGNAL,1);      
   if(auto_close_order){            if(ma2 > ma3)close_order(OP_SELL,0);            if(ma2 < ma3)close_order(OP_BUY,0);               }         if(maHI>ma0 && maLO>ma0 && maOPEN>ma0       && maHI>ma2  && maOPEN>ma2       && maOPEN>ma1 && ma0>ma1       && ma2 > ma3      && ma2_1>ma2 && ma2>ma2_2      //&& kdj1>kdj2 //&& kdj1<90

      ) BUYme=true;      if(maHI<ma0 && maLO<ma0 && maOPEN<ma0       && maLO<ma2 && maOPEN<ma2       && maOPEN<ma1 && ma0<ma1       && ma2 < ma3        && ma2_1<ma2 && ma2<ma2_2          //&& kdj1<kdj2 //&& kdj1>10

      ) SELLme=true;            if(TradeAllowed && BUYme)      {       close_order(OP_SELL,0);       //Ask(buy, long)      if(LossLimit ==0) SL=0; else SL=Ask-( (LossLimit +7)*Point );      if(ProfitMade==0) TP=0; else TP=Ask+( (ProfitMade+7)*Point );      OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,TradeComment,MagicNumber,White);      gle=GetLastError();      if(gle==0)        {         Print("BUY  Ask=",Ask," bartick=",bartick);         ObjectCreate("myx"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time[0], High[0]+(5*p));         ObjectSetText("myx"+DoubleToStr(objtick,0),"B",15,"Arial",Red);         bartick=0;         TradeAllowed=false;        }         else         {         Print("-----ERROR----- BUY  Ask=",Ask," error=",gle," bartick=",bartick);        }     }           //ENTRY SHORT (sell, Bid)   if(TradeAllowed && SELLme)     {     close_order(OP_BUY,0);      //Bid (sell, short)      if(LossLimit ==0) SL=0; else SL=Bid+((LossLimit+7)*Point );      if(ProfitMade==0) TP=0; else TP=Bid-((ProfitMade+7)*Point );      OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,TradeComment,MagicNumber,Red);      gle=GetLastError();      if(gle==0)        {         Print("SELL Bid=",Bid," bartick=",bartick);          ObjectCreate("myx"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time[0], High[0]+(5*p));         ObjectSetText("myx"+DoubleToStr(objtick,0),"S",15,"Arial",Red);         bartick=0;         TradeAllowed=false;        }         else         {         Print("-----ERROR----- SELL Bid=",Bid," error=",gle," bartick=",bartick);        }     }



 

        // CLOSE order if profit target made   for(cnt=OrdersTotal();cnt>=0;cnt--)     {      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);      if( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber )        {                 if(OrderType()==OP_BUY)           {            CurrentProfit=Bid-OrderOpenPrice() ;

            // modify for break even            if (CurrentProfit >= PLBreakEven*p && OrderOpenPrice()>OrderStopLoss())              {               SL=OrderOpenPrice()+(spread*2);               TP=OrderTakeProfit();               OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, White);               gle=GetLastError();               if(gle==0)                 {                  Print("MODIFY BREAKEVEN BUY  Bid=",Bid," bartick=",bartick);                   ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time[0], Low[0]-(7*p));                  ObjectSetText("myz"+DoubleToStr(objtick,0),"BE",15,"Arial",White);                 }                  else                  {                  Print("-----ERROR----- MODIFY BREAKEVEN BUY  Bid=",Bid," error=",gle," bartick=",bartick);                 }              }

                        if((ProfitMade>0 && CurrentProfit>=(ProfitMade*p)) || (LossLimit>0 && CurrentProfit<=((LossLimit*(-1))*p))  )              {               OrderClose(OrderTicket(),Lots,Bid,Slippage,White);               gle=GetLastError();               if(gle==0)                 {                  Print("CLOSE BUY  Bid=",Bid," bartick=",bartick);                   ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time[0], Low[0]-(7*p));                  ObjectSetText("myz"+DoubleToStr(objtick,0),"C",15,"Arial",White);                 }                  else                  {                  Print("-----ERROR----- CLOSE BUY  Bid=",Bid," error=",gle," bartick=",bartick);                 }              }                         } // if BUY         if(OrderType()==OP_SELL)           {

            CurrentProfit=OrderOpenPrice()-Ask;                        // modify for break even            if (CurrentProfit >= PLBreakEven*p && OrderOpenPrice()<OrderStopLoss())              {               SL=OrderOpenPrice()-(spread*2);               TP=OrderTakeProfit();               OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, Red);               gle=GetLastError();               if(gle==0)                 {                  Print("MODIFY BREAKEVEN SELL Ask=",Ask," bartick=",bartick);                  ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time[0], Low[0]-(7*p));                  ObjectSetText("myz"+DoubleToStr(objtick,0),"BE",15,"Arial",Red);                 }                  else                  {                  Print("-----ERROR----- MODIFY BREAKEVEN SELL Ask=",Ask," error=",gle," bartick=",bartick);                 }              }

            // did we make our desired SELL profit?            if( (ProfitMade>0 && CurrentProfit>=(ProfitMade*p)) || (LossLimit>0 && CurrentProfit<=((LossLimit*(-1))*p))  )              {               OrderClose(OrderTicket(),Lots,Ask,Slippage,Red);               gle=GetLastError();               if(gle==0)                 {                  Print("CLOSE SELL Ask=",Ask," bartick=",bartick);                  ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time[0], Low[0]-(7*p));                  ObjectSetText("myz"+DoubleToStr(objtick,0),"C",15,"Arial",Red);                 }                  else                  {                  Print("-----ERROR----- CLOSE SELL Ask=",Ask," error=",gle," bartick=",bartick);                 }                               }

           } //if SELL                   } // if(OrderSymbol)             } // for

  } // start()

int close_order(int cmd ,int type){  double pic;  if(cmd == OP_BUY)pic = Bid;else pic = Ask;  int i;  for(i=OrdersTotal();i>=0;i--)     {       OrderSelect(i, SELECT_BY_POS);   if(OrderSymbol() == Symbol()){          if(OrderType() == cmd){         if(type == 0)OrderClose(OrderTicket(),OrderLots(),pic,Slippage,Red);         if( type == 1){           if(OrderTakeProfit() > 0)OrderClose(OrderTicket(),OrderLots(),pic,Slippage,Red);              }          }          }                    }

 return(0);}

上一篇: 外汇ea:突破邮件通知系统

下一篇: 指标:多空信号提示器

声明本站分享的文章旨在促进信息交流,不以盈利为目的,本文观点与本站立场无关,不承担任何责任。部分内容文章及图片来自互联网或自媒体,版权归属于原作者,不保证该信息(包括但不限于文字、图片、图表及数据)的准确性、真实性、完整性、有效性、及时性、原创性等,如无意侵犯媒体或个人知识产权,请来电或致函告之,本站将在第一时间处理。未经证实的信息仅供参考,不做任何投资和交易根据,据此操作风险自担。本站拥有对此声明的最终解释权。