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

CCI信号共振自动交易EA framework.mq4

framework 自动交易EA是采用三个不同时间周期的CCI信号为交易信号。

源码:

//+------------------------------------------------------------------+
//|                                                    framework.mq4 |
//|                                                     Ron Thompson |
//+------------------------------------------------------------------+
#property copyright "Ron Thompson"
#property link      "http://www.125808047.com"

extern double Lots = 0.1;
extern int    TakeProfit=255;
extern int    StopLoss=0;
extern int    Interval=1;
extern int       myCCIs=30;   //  5 days
extern int       myCCIl=150;  // 25 days

double barmove0 = 0;
double barmove1 = 0;
int         itv = 0;
bool    cg = false;
double Poin;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int OnInit()
{ 
   if (Point == 0.00001) Poin = 0.0001; //5 digits
   else if (Point == 0.001) Poin = 0.01; //3 digits
   else Poin = Point; //Normal
   itv=Interval;
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void OnTick()
{
   bool     found=false;
   bool     rising=false;
   bool    falling=false;
   bool      cross=false;

   double slA=0, slB=0, tpA=0, tpB=0;
   double p=Poin;
   
   double cCIs;
   double cCIm;
   double cCIf;
   
   int      cnt=0;

   barmove0=Open[0];
   barmove1=Open[1];

   itv++;

   tpA=Ask+(p*TakeProfit);
   slA=Ask-(p*StopLoss);
   tpB=Bid-(p*TakeProfit);
   slB=Bid+(p*StopLoss);
   if (TakeProfit==0) {tpA=0; tpB=0;}           
   if (StopLoss==0)   {slA=0; slB=0;}           
   
   cCIs=iCCI(Symbol(),0,125,PRICE_OPEN,0);
   cCIm=iCCI(Symbol(),0, 25,PRICE_OPEN,0);
   cCIf=iCCI(Symbol(),0,  5,PRICE_OPEN,0);

   if (cCIm<=0 && cCIs>=0 && cCIf>0) { rising=true; cross=true; Print("Rising  Cross");}
   if (cCIm>=0 && cCIs<=0 && cCIf<0) {falling=true; cross=true; Print("Falling Cross");}

   if (cross)
     {
      for(cnt=OrdersTotal();cnt>0;cnt--)
        {
        cg =  OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol())
           {
            if (OrderType()==0) {cg = OrderClose(OrderTicket(),Lots,Bid,3,White);}
            if (OrderType()==1) {cg = OrderClose(OrderTicket(),Lots,Ask,3,Red);}
            itv=0;
           }
        }
      if (rising)  cg = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,slA,tpA,"ZZZ100",11123,0,White);
      if (falling) cg = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,slB,tpB,"ZZZ100",11321,0,Red);
      itv=0;
     }
   
   found=false;
   for(cnt=OrdersTotal();cnt>0;cnt--)
     {
      cg = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol())
        {
         if (OrderType()==0)  //BUY
           {
            if (itv >= Interval)
              {
               cg = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,slA,tpA,"ZZZ100",11123,0,White);
               itv=0;
              }
           }
         if (OrderType()==1)  //SELL
           {
            if (itv >= Interval)
              {
               cg = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,slB,tpB,"ZZZ100",11321,0,Red);
               itv=0;
              }
           }
         found=true;
         break;
        }
     }
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » CCI信号共振自动交易EA framework.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏