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

Papy Zigzag 120-12 EA

Papy Zigzag 120-12 EA结合四个指标的信号进行智能交易,其中KD、ZigZag指标MT4自定义指标中带有,CZI、FLAT指标在
MT4指标下可以找到下载。

Papy Zigzag 120-12 EA交易图表界面:Papy Zigzag 120-12 EA

Papy Zigzag 120-12 EA源码:

//+------------------------------------------------------------------+
//|                                        Papy Zigzag 120-12 EA.mq4 |
//|                               Copyright @2009, TradingSytemForex |
//+------------------------------------------------------------------+
#property copyright "Copyright @2009, TradingSytemForex"
#property link "http://www.125808047.com"

#define EAName "Papy Zigzag 120-12 EA"

extern string S1a="---------------- Stoch Filter Settings";
extern int StochKP=250;
extern int StochDP=34;
extern int StochSP=3;
extern int StochLevel=50;

extern string S1b="---------------- ZigZag 240 Settings";
extern bool Main=true;
extern bool CloseAtReverse=true;
extern int TimeFrame1=0;
extern int ExtDepth1=240;
extern int ExtDeviation1=5;
extern int ExtBackstep1=3;

extern string S1c="---------------- ZigZag 24 Settings";
extern bool Signal=true;
extern int TimeFrame3=0;
extern int ExtDepth3=24;
extern int ExtDeviation3=5;
extern int ExtBackstep3=3;

extern string S1d="---------------- ZigZag 24 Settings";
extern bool CloseAtIntermediate=true;
extern int TimeFrame2=0;
extern int ExtDepth2=12;
extern int ExtDeviation2=5;
extern int ExtBackstep2=3;

extern string S2="---------------- Money Management";
extern int ReculPips1=100;
extern int ReculPips2=50;
extern double Lots1=0.01;//|----------------------lots size zigzag 120
extern double Lots2=0.01;//|----------------------lots size zigzag 12
extern bool Increment=true;//|------------------increment lots size
extern double IncrementLots=0.01;//|--------------lots size increment
extern double SecureProfit=10;//|-----------------secure profit when conditions are met
extern bool RiskMM=false;//|---------------------risk management
extern double RiskPercent=1;//|------------------risk percentage

extern string S3="---------------- Order Management";
extern int StopLoss=0;//|------------------------stop loss
extern int TakeProfit=0;//|----------------------take profit
extern bool HideSL=false;//|---------------------hide stop loss
extern bool HideTP=false;//|---------------------hide take profit
extern int TrailingStop=0;//|--------------------trailing stop
extern int TrailingStep=0;//|--------------------trailing step
extern int BreakEven=0;//|-----------------------break even
extern int MaxOrders1=10;//|---------------------maximum orders allowed zz 120
extern int MaxOrders2=10;//|---------------------maximum orders allowed zz 12
extern int Slippage=3;//|------------------------slippage
extern int Magic1=20091;//|----------------------magic number 1
extern int Magic2=20092;//|----------------------magic number 2

extern string S6="---------------- Extras";
extern bool Hedge=false;//|----------------------enter an opposite trade
extern int HedgeSL=0;//|-------------------------stop loss
extern int HedgeTP=0;//|-------------------------take profit
extern bool ReverseSystem=false;//|--------------buy instead of sell, sell instead of buy

datetime PreviousBarTime1;
datetime PreviousBarTime2;

double maxEquity,minEquity,Balance=0.0;
int ZigZag1=0,ZigZag2=0,ZigZag3=0;

double point; int digits;
bool cg = false;
int OnInit()
  {
if(Digits<4){ point=0.01; digits=2;}
else{ point=0.0001;digits=4;}
  return(0);
}

void OnTick(void)
  {
   if(TrailingStop>0)MoveTrailingStop();

   if(BreakEven>0)MoveBreakEven();

   int limit=1;
   for(int i=1;i<=limit;i++)
   {
      double Last_BUY_OpenPrice1=0;
      double Last_SELL_OpenPrice1=0;
      int BUY_OpenPosition1=0;
      int SELL_OpenPosition1=0;
      int TOTAL_OpenPosition1=0;
      int cnt1=0;
   
      for (cnt1=0;cnt1<OrdersTotal();cnt1++) 
      {
         cg = OrderSelect(cnt1,SELECT_BY_POS,MODE_TRADES);
         if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic1&&OrderCloseTime()==0)
         {
            TOTAL_OpenPosition1++;
            if (OrderType()==OP_BUY) 
            {
               BUY_OpenPosition1++;
               Last_BUY_OpenPrice1=OrderOpenPrice();
            }
            if (OrderType()==OP_SELL) 
            {
               SELL_OpenPosition1++;
               Last_SELL_OpenPrice1=OrderOpenPrice();
            }
         }
      }
      
      double Last_BUY_OpenPrice2=0;
      double Last_SELL_OpenPrice2=0;
      int BUY_OpenPosition2=0;
      int SELL_OpenPosition2=0;
      int TOTAL_OpenPosition2=0;
      int cnt2=0;
   
      for (cnt2=0;cnt2<OrdersTotal();cnt2++) 
      {
         cg = OrderSelect(cnt2,SELECT_BY_POS,MODE_TRADES);
         if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic2&&OrderCloseTime()==0)
         {
            TOTAL_OpenPosition2++;
            if (OrderType()==OP_BUY) 
            {
               BUY_OpenPosition2++;
               Last_BUY_OpenPrice2=OrderOpenPrice();
            }
            if (OrderType()==OP_SELL) 
            {
               SELL_OpenPosition2++;
               Last_SELL_OpenPrice2=OrderOpenPrice();
            }
         }
      }
 
      double STO1=iStochastic(NULL,0,StochKP,StochDP,StochSP,MODE_SMA,0,MODE_MAIN,0);
      double STO2=iStochastic(NULL,0,StochKP,StochDP,StochSP,MODE_SMA,0,MODE_SIGNAL,0);
      
      ZigZag1=CheckZigZag240(TimeFrame1);
      ZigZag2=CheckZigZag24(TimeFrame2);
      ZigZag3=CheckZigZag12(TimeFrame3);

double CZ=0,A=0,B=0,C=0,D=0,E=0,F=0; 
int Flat = 3;
A= iCustom(NULL,0,"CZI",7,0);
B= iCustom(NULL,0,"CZI",7,1);
C= iCustom(NULL,0,"CZI",7,2);
D= iCustom(NULL,0,"CZI",7,4);
E= iCustom(NULL,0,"CZI",7,5);
F= iCustom(NULL,0,"CZI",7,6);

double F1 = iCustom(NULL, 0, "FLAT", 0, 12, 26, 9, 300, 2, 1);
if (F1 > 350.0) F1 = 0;

if ( F1==1 && (A==1||B==1||C==1||D==1||E==1||F==1))Flat = 1;
else Flat = 0;
        
      string BUY1="false";string SELL1="false";
      string SignalBUY1="false";string SignalSELL1="false";
      
      if(Main&&ZigZag1>0&&ZigZag3>0&&(BUY_OpenPosition1==0||((Last_BUY_OpenPrice1-Ask)>(ReculPips1*point)))&&STO1<STO2&&STO1<StochLevel&&STO2<StochLevel)BUY1="true";
      if(Main&&ZigZag1<0&&ZigZag3<0&&(SELL_OpenPosition1==0||((Bid-Last_SELL_OpenPrice1)>(ReculPips1*point)))&&STO1>STO2&&STO1>StochLevel&&STO2>StochLevel)SELL1="true";
      
      if(BUY1=="true"/*&&MABUY=="true"*/)if(ReverseSystem)SignalSELL1="true";else SignalBUY1="true";
      if(SELL1=="true"/*&&MASELL=="true"*/)if(ReverseSystem)SignalBUY1="true";else SignalSELL1="true";

      string BUY2="false";string SELL2="false";
      string SignalBUY2="false";string SignalSELL2="false";
      
      if(Signal&&ZigZag1>0&&ZigZag3>0&&(BUY_OpenPosition2==0||((Last_BUY_OpenPrice2-Ask)>(ReculPips2*point))))BUY2="true";
      if(Signal&&ZigZag1<0&&ZigZag3<0&&(SELL_OpenPosition2==0||((Bid-Last_SELL_OpenPrice2)>(ReculPips2*point))))SELL2="true";
      
      if(BUY2=="true")if(ReverseSystem)SignalSELL2="true";else SignalBUY2="true";
      if(SELL2=="true")if(ReverseSystem)SignalBUY2="true";else SignalSELL2="true";
      
   }

   if(RiskMM){CalculateMM1();CalculateMM2();}
   double LotsMB=0,LotsMS=0,LotsIB,LotsIS=0;
   if(Increment)
   {
      LotsMB=Lots1+(IncrementLots*BUY_OpenPosition1);LotsMS=Lots1+(IncrementLots*SELL_OpenPosition1);
      LotsIB=Lots2+(IncrementLots*BUY_OpenPosition2);LotsIS=Lots2+(IncrementLots*SELL_OpenPosition2);
   }
   else
   {
      LotsMB=Lots1;LotsMS=Lots1;LotsIB=Lots2;LotsIS=Lots2;
   }

   double SL,TP,SLH,TPH;
   int Ticket,TicketH,Expire=0;
   
   if(TOTAL_OpenPosition1<MaxOrders1)
   {  
      if(SignalBUY1=="true"&& Flat == 1)
      {
         if(HideSL==false&&StopLoss>0){SL=Ask-StopLoss*point;/*OPP=Bid-StopLoss*point;SLP=Bid;*/}else {SL=0;/*SLP=0;*/}
         if(HideTP==false&&TakeProfit>0){TP=Ask+TakeProfit*point;/*TPP=Bid-(TakeProfit*2)*point;*/}else {TP=0;/*TPP=0;*/}
         if(HideSL==false&&HedgeSL>0)SLH=Bid+HedgeSL*point;else SLH=0;
         if(HideTP==false&&HedgeTP>0)TPH=Bid-HedgeTP*point;else TPH=0;
         
         Ticket=OrderSend(Symbol(),OP_BUY,LotsMB,Ask,Slippage,SL,TP,EAName,Magic1,0,Lime);
         if(Hedge)TicketH=OrderSend(Symbol(),OP_SELL,LotsMS,Bid,Slippage,SLH,TPH,EAName,Magic1,0,Magenta);
      }
      if(SignalSELL1=="true"&& Flat == 1)
      {
         if(HideSL==false&&StopLoss>0){SL=Bid+StopLoss*point;/*OPP=Ask+StopLoss*point;SLP=Ask;*/}else {SL=0;/*SLP=0;*/}
         if(HideTP==false&&TakeProfit>0){TP=Bid-TakeProfit*point;/*TPP=Ask+(TakeProfit*2)*point;*/}else {TP=0;/*TPP=0;*/}
         if(HideSL==false&&HedgeSL>0)SLH=Ask-HedgeSL*point;else SLH=0;
         if(HideTP==false&&HedgeTP>0)TPH=Ask+HedgeTP*point;else TPH=0;
         
         Ticket=OrderSend(Symbol(),OP_SELL,LotsMS,Bid,Slippage,SL,TP,EAName,Magic1,0,Magenta);
         if(Hedge)TicketH=OrderSend(Symbol(),OP_BUY,LotsMB,Ask,Slippage,SLH,TPH,EAName,Magic1,0,Lime);
      }
   }
   
   if(TOTAL_OpenPosition2<MaxOrders2)
   {  
      if(SignalBUY2=="true" && Flat == 1)
      {
         if(HideSL==false&&StopLoss>0){SL=Ask-StopLoss*point;/*OPP=Bid-StopLoss*point;SLP=Bid;*/}else {SL=0;/*SLP=0;*/}
         if(HideTP==false&&TakeProfit>0){TP=Ask+TakeProfit*point;/*TPP=Bid-(TakeProfit*2)*point;*/}else {TP=0;/*TPP=0;*/}
         if(HideSL==false&&HedgeSL>0)SLH=Bid+HedgeSL*point;else SLH=0;
         if(HideTP==false&&HedgeTP>0)TPH=Bid-HedgeTP*point;else TPH=0;
         
         Ticket=OrderSend(Symbol(),OP_BUY,LotsIB,Ask,Slippage,SL,TP,EAName,Magic2,0,Blue);
         if(Hedge)TicketH=OrderSend(Symbol(),OP_SELL,LotsIS,Bid,Slippage,SLH,TPH,EAName,Magic2,0,Red);
      }
      if(SignalSELL2=="true" && Flat == 1)
      {
         if(HideSL==false&&StopLoss>0){SL=Bid+StopLoss*point;/*OPP=Ask+StopLoss*point;SLP=Ask;*/}else {SL=0;/*SLP=0;*/}
         if(HideTP==false&&TakeProfit>0){TP=Bid-TakeProfit*point;/*TPP=Ask+(TakeProfit*2)*point;*/}else {TP=0;/*TPP=0;*/}
         if(HideSL==false&&HedgeSL>0)SLH=Ask-HedgeSL*point;else SLH=0;
         if(HideTP==false&&HedgeTP>0)TPH=Ask+HedgeTP*point;else TPH=0;
         
         Ticket=OrderSend(Symbol(),OP_SELL,LotsIS,Bid,Slippage,SL,TP,EAName,Magic2,0,Red);
         if(Hedge)TicketH=OrderSend(Symbol(),OP_BUY,LotsIB,Ask,Slippage,SLH,TPH,EAName,Magic2,0,Blue);
      }
   }
   
   if(Hedge==false)
   {
      if((CloseAtIntermediate&&ZigZag2<0&&AccountEquity()>(AccountBalance()+SecureProfit))||(CloseAtReverse&&ZigZag1<0)||(OrderMagicNumber()==Magic1&&ReverseSystem==false&&HideSL&&StopLoss>0&&OrderType()==OP_BUY&&(OrderOpenPrice()-Ask)/point>=StopLoss)||(OrderMagicNumber()==Magic1&&ReverseSystem==false&&HideTP&&TakeProfit>0&&OrderType()==OP_BUY&&(Bid-OrderOpenPrice())/point>=TakeProfit)||(OrderMagicNumber()==Magic1&&ReverseSystem&&HideSL&&StopLoss>0&&OrderType()==OP_SELL&&(Bid-OrderOpenPrice())/point>=StopLoss)||(OrderMagicNumber()==Magic1&&ReverseSystem&&HideTP&&TakeProfit>0&&OrderType()==OP_SELL&&(OrderOpenPrice()-Ask)/point>=TakeProfit))
      {
         if(ReverseSystem)CloseSellOrders(Magic1);else CloseBuyOrders(Magic1);
      }
      if((CloseAtIntermediate&&ZigZag2>0&&AccountEquity()>(AccountBalance()+SecureProfit))||(CloseAtReverse&&ZigZag1>0)||(OrderMagicNumber()==Magic1&&ReverseSystem==false&&HideSL&&StopLoss>0&&OrderType()==OP_SELL&&(Bid-OrderOpenPrice())/point>=StopLoss)||(OrderMagicNumber()==Magic1&&ReverseSystem==false&&HideTP&&TakeProfit>0&&OrderType()==OP_SELL&&(OrderOpenPrice()-Ask)/point>=TakeProfit)||(OrderMagicNumber()==Magic1&&ReverseSystem&&HideSL&&StopLoss>0&&OrderType()==OP_BUY&&(OrderOpenPrice()-Ask)/point>=StopLoss)||(OrderMagicNumber()==Magic1&&ReverseSystem&&HideTP&&TakeProfit>0&&OrderType()==OP_BUY&&(Bid-OrderOpenPrice())/point>=TakeProfit))
      {
         if(ReverseSystem)CloseBuyOrders(Magic1);else CloseSellOrders(Magic1);
      }
      if((CloseAtIntermediate&&ZigZag2<0&&AccountEquity()>(AccountBalance()+SecureProfit))||(CloseAtReverse&&ZigZag1<0)||(OrderMagicNumber()==Magic2&&ReverseSystem==false&&HideSL&&StopLoss>0&&OrderType()==OP_BUY&&(OrderOpenPrice()-Ask)/point>=StopLoss)||(OrderMagicNumber()==Magic2&&ReverseSystem==false&&HideTP&&TakeProfit>0&&OrderType()==OP_BUY&&(Bid-OrderOpenPrice())/point>=TakeProfit)||(OrderMagicNumber()==Magic2&&ReverseSystem&&HideSL&&StopLoss>0&&OrderType()==OP_SELL&&(Bid-OrderOpenPrice())/point>=StopLoss)||(OrderMagicNumber()==Magic2&&ReverseSystem&&HideTP&&TakeProfit>0&&OrderType()==OP_SELL&&(OrderOpenPrice()-Ask)/point>=TakeProfit))
      {
         if(ReverseSystem)CloseSellOrders(Magic2);else CloseBuyOrders(Magic2);
      }
      if((CloseAtIntermediate&&ZigZag2>0&&AccountEquity()>(AccountBalance()+SecureProfit))||(CloseAtReverse&&ZigZag1>0)||(OrderMagicNumber()==Magic2&&ReverseSystem==false&&HideSL&&StopLoss>0&&OrderType()==OP_SELL&&(Bid-OrderOpenPrice())/point>=StopLoss)||(OrderMagicNumber()==Magic2&&ReverseSystem==false&&HideTP&&TakeProfit>0&&OrderType()==OP_SELL&&(OrderOpenPrice()-Ask)/point>=TakeProfit)||(OrderMagicNumber()==Magic2&&ReverseSystem&&HideSL&&StopLoss>0&&OrderType()==OP_BUY&&(OrderOpenPrice()-Ask)/point>=StopLoss)||(OrderMagicNumber()==Magic2&&ReverseSystem&&HideTP&&TakeProfit>0&&OrderType()==OP_BUY&&(Bid-OrderOpenPrice())/point>=TakeProfit))
      {
         if(ReverseSystem)CloseBuyOrders(Magic2);else CloseSellOrders(Magic2);
      }
   }
   else
   {
      if((OrderMagicNumber()==Magic1&&HideSL&&StopLoss>0&&OrderType()==OP_BUY&&(OrderOpenPrice()-Ask)/point>=StopLoss)||(OrderMagicNumber()==Magic1&&HideTP&&TakeProfit>0&&OrderType()==OP_BUY&&(Bid-OrderOpenPrice())/point>=TakeProfit))
      {
         CloseBuyOrders(Magic1);
      }
      if((OrderMagicNumber()==Magic1&&HideSL&&StopLoss>0&&OrderType()==OP_SELL&&(Bid-OrderOpenPrice())/point>=StopLoss)||(OrderMagicNumber()==Magic1&&HideTP&&TakeProfit>0&&OrderType()==OP_SELL&&(OrderOpenPrice()-Ask)/point>=TakeProfit))
      {
         CloseSellOrders(Magic1);
      }
      if((OrderMagicNumber()==Magic2&&HideSL&&StopLoss>0&&OrderType()==OP_BUY&&(OrderOpenPrice()-Ask)/point>=StopLoss)||(OrderMagicNumber()==Magic2&&HideTP&&TakeProfit>0&&OrderType()==OP_BUY&&(Bid-OrderOpenPrice())/point>=TakeProfit))
      {
         CloseBuyOrders(Magic2);
      }
      if((OrderMagicNumber()==Magic2&&HideSL&&StopLoss>0&&OrderType()==OP_SELL&&(Bid-OrderOpenPrice())/point>=StopLoss)||(OrderMagicNumber()==Magic2&&HideTP&&TakeProfit>0&&OrderType()==OP_SELL&&(OrderOpenPrice()-Ask)/point>=TakeProfit))
      {
         CloseSellOrders(Magic2);
      }
   }

   int err=0;
   if(Ticket<0)
   {
      if(GetLastError()==134)
      {
         err=1;
         Print("Not enough money!");
      }
      return;
   }
}

int CloseBuyOrders(int Magic)
{
  int result,total=OrdersTotal();

  for (int cnt=total-1;cnt>=0;cnt--)
  {
    cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol())
    {
      if(OrderType()==OP_BUY)
      {
        cg = OrderClose(OrderTicket(),OrderLots(),Bid,3);
        switch(OrderType())
        {
          case OP_BUYLIMIT:
          case OP_BUYSTOP:
          result=OrderDelete(OrderTicket());
        }
      }
    }
  }
  return(0);
}

int CloseSellOrders(int Magic)
{
  int result,total=OrdersTotal();

  for(int cnt=total-1;cnt>=0;cnt--)
  {
    cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol())
    {
      if(OrderType()==OP_SELL)
      {
        cg = OrderClose(OrderTicket(),OrderLots(),Ask,3);
        switch(OrderType())
        {
          case OP_SELLLIMIT:
          case OP_SELLSTOP:
          result=OrderDelete(OrderTicket());
        }
      }
    }
  }
  return(0);
}

void MoveTrailingStop()
{
   int cnt,total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic1)||(OrderMagicNumber()==Magic2)))
      {
         if(OrderType()==OP_BUY)
         {
            if(TrailingStop>0)  
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)<NormalizeDouble(Bid-point*(TrailingStop+TrailingStep),digits))||(OrderStopLoss()==0))
               {
                  cg = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-point*TrailingStop,digits),OrderTakeProfit(),0,Orange);
               }
            }
         }
         else 
         {
            if(TrailingStop>0)  
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)>(NormalizeDouble(Ask+point*(TrailingStop+TrailingStep),digits)))||(OrderStopLoss()==0))
               {
                  cg = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+point*TrailingStop,digits),OrderTakeProfit(),0,Orange);
               }
            }
         }
      }
   }
}

void MoveBreakEven()
{
   int cnt,total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic1)||(OrderMagicNumber()==Magic2)))
      {
         if(OrderType()==OP_BUY)
         {
            if(BreakEven>0)
            {
               if(NormalizeDouble((Bid-OrderOpenPrice()),digits)>BreakEven*point)
               {
                  if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),digits)<0)
                  {
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*point,digits),OrderTakeProfit(),0,Orange);
                  }
               }
            }
         }
         else
         {
            if(BreakEven>0)
            {
               if(NormalizeDouble((OrderOpenPrice()-Ask),digits)>BreakEven*point)
               {
                  if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),digits)<0)
                  {
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*point,digits),OrderTakeProfit(),0,Orange);
                  }
               }
            }
         }
      }
   }
}

void CalculateMM1()
{
   double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
   double MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);
   Lots1=AccountFreeMargin()/100000*RiskPercent;
   Lots1=MathMin(MaxLots,MathMax(MinLots,Lots1));
   if(MinLots<0.1)Lots1=NormalizeDouble(Lots1,2);
   else
   {
     if(MinLots<1)Lots1=NormalizeDouble(Lots1,1);
     else Lots1=NormalizeDouble(Lots1,0);
   }
   if(Lots1<MinLots)Lots1=MinLots;
   if(Lots1>MaxLots)Lots1=MaxLots;
}

void CalculateMM2()
{
   double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
   double MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);
   Lots2=AccountFreeMargin()/100000*RiskPercent;
   Lots2=MathMin(MaxLots,MathMax(MinLots,Lots2));
   if(MinLots<0.1)Lots2=NormalizeDouble(Lots2,2);
   else
   {
     if(MinLots<1)Lots2=NormalizeDouble(Lots2,1);
     else Lots2=NormalizeDouble(Lots2,0);
   }
   if(Lots2<MinLots)Lots2=MinLots;
   if(Lots2>MaxLots)Lots2=MaxLots;
}

int CheckZigZag240(int TimeFrame)
{
   int TradeBar=0;
   int Ret=0;
   int Limit=5000;
   int j=0;
   double Zig=0;

   for(int i=TradeBar;i<=Limit;i++)
   {
	  double Zig_Cur=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth1,ExtDeviation1,ExtBackstep1,0,i);
	  double Zig_Prev=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth1,ExtDeviation1,ExtBackstep1,0,i+1);
	  if(Zig_Cur>0)
	  {
	     j=i;
	     Zig=Zig_Cur;
	     break;
	  }
   }

   for(i=j+1;i<=Limit;i++)
   {
	  Zig_Cur=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth1,ExtDeviation1,ExtBackstep1,0,i);
	  Zig_Prev=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth1,ExtDeviation1,ExtBackstep1,0,i+1);
	  if(Zig_Cur>0)
	  {
	     break;
	  }
   }

   if(Zig>Zig_Cur)
   {
      Ret=-1;
   }
   if(Zig<Zig_Cur)
   {
      Ret=1;
   }
   return(Ret);
}

int CheckZigZag24(int TimeFrame)
{
   int TradeBar=0;
   int Ret=0;
   int Limit=5000;
   int j=0;
   double Zig=0;

   for(int i=TradeBar;i<=Limit;i++)
   {
	  double Zig_Cur=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth2,ExtDeviation2,ExtBackstep2,0,i);
	  double Zig_Prev=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth2,ExtDeviation2,ExtBackstep2,0,i+1);
	  if(Zig_Cur>0)
	  {
	     j=i;
	     Zig=Zig_Cur;
	     break;
	  }
   }

   for(i=j+1;i<=Limit;i++)
   {
	  Zig_Cur=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth2,ExtDeviation2,ExtBackstep2,0,i);
	  Zig_Prev=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth2,ExtDeviation2,ExtBackstep2,0,i+1);
	  if(Zig_Cur>0)
	  {
	     break;
	  }
   }

   if(Zig>Zig_Cur)
   {
      Ret=-1;
   }
   if(Zig<Zig_Cur)
   {
      Ret=1;
   }
   return(Ret);
}

int CheckZigZag12(int TimeFrame)
{
   int TradeBar=0;
   int Ret=0;
   int Limit=5000;
   int j=0;
   double Zig=0;

   for(int i=TradeBar;i<=Limit;i++)
   {
	  double Zig_Cur=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth3,ExtDeviation3,ExtBackstep3,0,i);
	  double Zig_Prev=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth3,ExtDeviation3,ExtBackstep3,0,i+1);
	  if(Zig_Cur>0)
	  {
	     j=i;
	     Zig=Zig_Cur;
	     break;
	  }
   }

   for(i=j+1;i<=Limit;i++)
   {
	  Zig_Cur=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth3,ExtDeviation3,ExtBackstep3,0,i);
	  Zig_Prev=iCustom(NULL,TimeFrame,"ZigZag",ExtDepth3,ExtDeviation3,ExtBackstep3,0,i+1);
	  if(Zig_Cur>0)
	  {
	     break;
	  }
   }

   if(Zig>Zig_Cur)
   {
      Ret=-1;
   }
   if(Zig<Zig_Cur)
   {
      Ret=1;
   }
   return(Ret);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » Papy Zigzag 120-12 EA
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏