Author: Copyright 2019, K&S
Profit factor:
0.00
5 Views
0 Downloads
0 Favorites
KS-ADX.2
ÿþ//+------------------------------------------------------------------+

//|                                                     KS-ADX.2.mq4 |

//|                                              Copyright 2019, K&S |

//|                                                  http://An-SM.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright 2019, K&S"

#property link      "https://An-SM.ru"

#property version   "2.00"

#property strict

//--- input parameters

input    ENUM_TIMEFRAMES      timeframe_all=60;

input    int      period_all     = 26;

input    int      lineUpUp       = 30;    // 5@E=89 ?@545; :>@84>@0

input    int      lineUp         = 25;    // 86=89 ?@545; :>@84>@0

input    int      lineDn         = 15;    // 5@5A5G5=85 ADX 8 (DI+ || DI-)

extern   double   Lot            = 0.01;  //  07<5@ ;>B0

input    int      TP             = 0;     // @8 0 70:@KB85 ?> B@59;8=3C

extern   bool     opentype1      = true;  // B:@KB85 ?> B8?C 1

input    int      SL             = 0;     // !B>?;>AA 4;O 1 B8?0 (0 ?> D@0:B0;C)

extern   bool     opentype2      = true;  // B:@KB85 ?> B8?C 2

input    int      SL2            = 0;     // !B>?;>AA 4;O 2 B8?0

extern   int      slippage       = 3;     // @>A:0;L7K20=85

extern   int      tral           = 150;   // "@59;8=3 2 ?8?A0E

extern   int      Magic          = 0;

extern   bool     profit_test    = true;  // >=B@>;8@>20BL ?@>D8B?

extern   double   procent        = 25;    // @>F5=B ?@>A04:8



extern   bool     celebrate      = true;  // 5 B>@3>20BL 2 ?@074=8:8 8 ?>A;54=89 45=L

extern   bool     hour_00        = true;

extern   bool     hour_01        = true;

extern   bool     hour_02        = true;

extern   bool     hour_03        = true;

extern   bool     hour_04        = true;

extern   bool     hour_05        = true;

extern   bool     hour_06        = true;

extern   bool     hour_07        = true;

extern   bool     hour_08        = true;

extern   bool     hour_09        = true;

extern   bool     hour_10        = true;

extern   bool     hour_11        = true;

extern   bool     hour_12        = true;

extern   bool     hour_13        = true;

extern   bool     hour_14        = true;

extern   bool     hour_15        = true;

extern   bool     hour_16        = true;

extern   bool     hour_17        = true;

extern   bool     hour_18        = true;

extern   bool     hour_19        = true;

extern   bool     hour_20        = true;

extern   bool     hour_21        = true;

extern   bool     hour_22        = true;

extern   bool     hour_23        = true;





datetime TimeBar=0;

double MINLOT,MAXLOT;

double lastFractalUp,lastFractalDn;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- create timer

   EventSetTimer(60);

   MINLOT = MarketInfo(Symbol(),MODE_MINLOT);

   MAXLOT = MarketInfo(Symbol(),MODE_MAXLOT);



//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//--- destroy timer

   EventKillTimer();



  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//---

   double MaxOrderBuy=0,MinOrderSell=0,MinOrderBuy=0,MaxOrderSell=0,OL=0,LB=0,LS=0,PB=0,PS=0;

   double Profit=0,ProfitB=0,ProfitS=0,tSL=0,tTP=0;

   double pips=0;

   int i=0,b=0,s=0,tip;

   double OOP;

   bool tmp;

//int i,b=0,s=0,tip;



   if(iFractals(NULL,timeframe_all,MODE_UPPER,2) > 0) lastFractalUp = iFractals(NULL,timeframe_all,MODE_UPPER,2);

   if(iFractals(NULL,timeframe_all,MODE_LOWER,2) > 0) lastFractalDn = iFractals(NULL,timeframe_all,MODE_LOWER,2);



   if(TimeBar == iTime(NULL,timeframe_all,0)) return;

   double   Lots=0,RSI1=0,RSI0=0,ADXm1=0,ADXp1=0,ADXg1=0,ADXm2=0,ADXp2=0,ADXg2=0,ADXm3=0,ADXp3=0,ADXg3=0,

   MACDm0=0,MACDs0=0,MACDm1=0,MACDs1=0,

   EnvH=0,EnvL=0,BolM=0,ibu=0,ibe=0,FracUp=0,FracDn=0;



//BolM = iBands(NULL,timeframe_all,period_all,otklonenie,0,PRICE_CLOSE,MODE_MAIN,2);

//EnvH = iEnvelopes(NULL,timeframe_all,period_all,MODE_SMA,0,PRICE_CLOSE,otklonenie,MODE_UPPER,2);

//EnvL = iEnvelopes(NULL,timeframe_all,period_all,MODE_SMA,0,PRICE_CLOSE,otklonenie,MODE_LOWER,2);

//FracUp = iFractals(NULL,timeframe_all,MODE_UPPER,2);

//FracDn = iFractals(NULL,timeframe_all,MODE_LOWER,2);

   ADXg1= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_MAIN,1);

   ADXp1= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_PLUSDI,1);

   ADXm1= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_MINUSDI,1);

   ADXg2= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_MAIN,2);

   ADXp2= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_PLUSDI,2);

   ADXm2= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_MINUSDI,2);

   ADXg3= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_MAIN,3);

   ADXp3= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_PLUSDI,3);

   ADXm3= iADX (NULL,timeframe_all,period_all,PRICE_CLOSE,MODE_MINUSDI,3);



//Print(FracUp," - ",FracDn);

//Print("FracDn<BolL ",Low[1]," < ", BolL,"    | ADX0<line ",ADX0," < ",line,"   | ADXm>line ",ADXm," > ",line);



//@>25@:0 CA;>289 4;O >B:@KB8O 2 BUY 20@80=B 1

   if(opentype1 && !celebrate_endday() && hour_test() && ADXg3<ADXg2 && ADXg2<ADXg1 && 

      ADXm2>ADXg2 && ADXm1<ADXg1 && ADXg2<lineDn && ADXp2>lineUp && ADXp2<lineUpUp && 

      //iWPR(NULL,timeframe_all,period_all*2,1) < -20 && iWPR(NULL,timeframe_all,period_all*2,1) > -50)

      iATR(NULL,timeframe_all,period_all,3)<iATR(NULL,timeframe_all,period_all,1))

     {

        {

         Lots=NormalizeDouble(Lot,Digits);



         if(Lots>MAXLOT) Lots = MAXLOT;

         if(Lots<MINLOT) Lots = MINLOT;



         tSL=0;



         if(SL==0) tSL=NormalizeDouble(lastFractalDn,Digits);

         else tSL=NormalizeDouble(Ask-SL*Point,Digits);

         if(Ask-tSL<MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) tSL=NormalizeDouble(Ask-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point,Digits);

         //Print("Ask - ",Ask,"  SL - ",NormalizeDouble(Ask-SL*Point,Digits),"  TP - ",NormalizeDouble(Ask+TP*Point,Digits));

         //Print("tSL - ",tSL, "    Ask - ",Ask,"    MinSL - ",MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);

         if(TP!=0) tTP = NormalizeDouble(Ask+TP*Point,Digits);

            else tTP = 0;

         if(Check_SL_TP(ORDER_TYPE_BUY,tSL,tTP) && CheckMoneyForTrade(NULL,Lots,OP_BUY))

         {

            if(OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),slippage,tSL,tTP,"ADX.1",Magic,0,CLR_NONE)==-1)

               Print("H81:0 ",GetLastError()," >B:@KB8O >@45@0 ");

            else TimeBar=iTime(NULL,timeframe_all,0);

         }

        }

     }



//@>25@:0 CA;>289 4;O >B:@KB8O 2 SELL 20@80=B 1

   Lots=0;

//Print("FracUp>BolH ",High[1]," > ", BolH,"    | ADX0<line ",ADX0," < ",line,"   | ADXp>line ",ADXp," > ",line);

   if(opentype1 && !celebrate_endday() && hour_test() && ADXg3<ADXg2 && ADXg2<ADXg1 && 

      ADXp2>ADXg2 && ADXp1<ADXg1 && ADXg2<lineDn && ADXm2>lineUp && ADXm2<lineUpUp && 

      //iWPR(NULL,timeframe_all,period_all*2,1) < -50 && iWPR(NULL,timeframe_all,period_all*2,1) > -80)

      iATR(NULL,timeframe_all,period_all,3)>iATR(NULL,timeframe_all,period_all,1))

     {

        {

         Lots=NormalizeDouble(Lot,Digits);



         if(Lots>MAXLOT) Lots = MAXLOT;

         if(Lots<MINLOT) Lots = MINLOT;



         tSL=0;

         if(SL==0) tSL=NormalizeDouble(lastFractalUp,Digits);

         else tSL=NormalizeDouble(Bid+SL*Point,Digits);

         if(tSL-Bid<MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) tSL=NormalizeDouble(Bid+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point,Digits);

         //Print("Bid - ",Bid,"  SL - ",NormalizeDouble(Bid+SL*Point,Digits),"  TP - ",NormalizeDouble(Bid-TP*Point,Digits));

         //Print("tSL - ",tSL, "    Bid - ",Bid,"    MinSL - ",MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);

         if(TP!=0) tTP = NormalizeDouble(Bid-TP*Point,Digits);

            else tTP = 0;

         if(Check_SL_TP(ORDER_TYPE_SELL,tSL,tTP) && CheckMoneyForTrade(NULL,Lots,OP_SELL))

         {

            if(OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),slippage,tSL,tTP,"ADX.1",Magic,0,CLR_NONE)==-1)

               Print("H81:0 ",GetLastError()," >B:@KB8O >@45@0 ");

            else TimeBar=iTime(NULL,timeframe_all,0);

         }

        }

     }

//@>25@:0 CA;>289 4;O >B:@KB8O 2 BUY 20@80=B 2

//Print("ADXm1-",ADXm1,"   ADXm2-",ADXm2,"   ADXm3-",ADXm3);

//Print("ADXp1-",ADXp1,"   ADXp2-",ADXp2,"   ADXp3-",ADXp3);

//Print("ADXg1-",ADXg1,"   ADXg2-",ADXg2,"   ADXg3-",ADXg3);

   if(opentype2 && !celebrate_endday() && hour_test() && ADXg3<ADXg2 && ADXg2<ADXg1 && 

      ADXm2>ADXg2 && ADXm1<ADXg1 && ADXg1>lineUp && ADXp1<lineDn && 

      //iWPR(NULL,timeframe_all,period_all,1) < -80)

      iATR(NULL,timeframe_all,period_all,3)<iATR(NULL,timeframe_all,period_all,1))

     {

        {

         Lots=NormalizeDouble(Lot,Digits);



         if(Lots>MAXLOT) Lots = MAXLOT;

         if(Lots<MINLOT) Lots = MINLOT;



         tSL=0;



         if(SL2==0) tSL=0;

         else tSL=NormalizeDouble(Ask-SL2*Point,Digits);

         if(tSL!=0 && Ask-tSL<MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) tSL=NormalizeDouble(Ask-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point,Digits);

         //Print("Ask - ",Ask,"  SL - ",NormalizeDouble(Ask-SL*Point,Digits),"  TP - ",NormalizeDouble(Ask+TP*Point,Digits));

         //Print("tSL - ",tSL, "    Ask - ",Ask,"    MinSL - ",MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);

         if(TP!=0) tTP = NormalizeDouble(Ask+TP*Point,Digits);

            else tTP = 0;

         if(Check_SL_TP(ORDER_TYPE_BUY,tSL,tTP) && CheckMoneyForTrade(NULL,Lots,OP_BUY))

         {

            if(OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),slippage,tSL,tTP,"ADX.2",Magic,0,CLR_NONE)==-1)

               Print("H81:0 ",GetLastError()," >B:@KB8O >@45@0 ");

            else TimeBar=iTime(NULL,timeframe_all,0);

         }

        }

     }



//@>25@:0 CA;>289 4;O >B:@KB8O 2 SELL 20@80=B 2

   Lots=0;

//Print("FracUp>BolH ",High[1]," > ", BolH,"    | ADX0<line ",ADX0," < ",line,"   | ADXp>line ",ADXp," > ",line);

   if(opentype2 && !celebrate_endday() && hour_test() && ADXg3<ADXg2 && ADXg2<ADXg1 && 

      ADXp2>ADXg2 && ADXp1<ADXg1 && ADXg1>lineUp && ADXm1<lineDn && 

      //iWPR(NULL,timeframe_all,period_all,1) > -20)

      iATR(NULL,timeframe_all,period_all,3)>iATR(NULL,timeframe_all,period_all,1))

     {

        {

         Lots=NormalizeDouble(Lot,Digits);



         if(Lots>MAXLOT) Lots = MAXLOT;

         if(Lots<MINLOT) Lots = MINLOT;



         tSL=0;

         if(SL2==0) tSL=0;

         else tSL=NormalizeDouble(Bid+SL2*Point,Digits);

         if(tSL!=0 && tSL-Bid<MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) tSL=NormalizeDouble(Bid+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point,Digits);

         //Print("Bid - ",Bid,"  SL - ",NormalizeDouble(Bid+SL*Point,Digits),"  TP - ",NormalizeDouble(Bid-TP*Point,Digits));

         //Print("tSL - ",tSL, "    Bid - ",Bid,"    MinSL - ",MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);

         if(TP!=0) tTP = NormalizeDouble(Bid-TP*Point,Digits);

            else tTP = 0;

         if(Check_SL_TP(ORDER_TYPE_SELL,tSL,tTP) && CheckMoneyForTrade(NULL,Lots,OP_SELL))

         {

            if(OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),slippage,tSL,tTP,"ADX.2",Magic,0,CLR_NONE)==-1)

               Print("H81:0 ",GetLastError()," >B:@KB8O >@45@0 ");

            else TimeBar=iTime(NULL,timeframe_all,0);

         }

        }

     }



//@>25@:0 =0 B@59;8=3

   for(i=0; i<OrdersTotal(); i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && Magic==OrderMagicNumber())

           {

            tip = OrderType();

            OOP = NormalizeDouble(OrderOpenPrice(),Digits);

            OL=OrderLots();

            if(tip==OP_BUY)

              {

               PB+=OOP*OL; LB+=OL;

               ProfitB+=OrderProfit()+OrderCommission()+OrderSwap();

               b++;

               if(ProfitB>0 && Bid>NormalizeDouble((OOP+(tral+5)*Point),Digits))

                 {

                  if(OrderStopLoss()<OrderOpenPrice() || OrderStopLoss()==0)

                    {

                     if(OrderStopLoss()!=NormalizeDouble((OOP+tral*Point),Digits))

                       {

                        tSL = NormalizeDouble((OOP+tral*Point),Digits);

                        tTP = OrderTakeProfit();

                        if(Check_SL_TP(ORDER_TYPE_BUY,tSL,tTP))

                           tmp=OrderModify(OrderTicket(),OrderOpenPrice(),tSL,tTP,OrderExpiration(),clrNONE);

                       }

                    }

                  else

                  if(OrderStopLoss()!=NormalizeDouble((OrderStopLoss()+(5)*Point),Digits))

                    {

                     tSL = NormalizeDouble((OrderStopLoss()+(5)*Point),Digits);

                     tTP = OrderTakeProfit();

                     if(Check_SL_TP(ORDER_TYPE_BUY,tSL,tTP))

                        tmp=OrderModify(OrderTicket(),OrderOpenPrice(),tSL,tTP,OrderExpiration(),clrNONE);

                    }

                  if(GetLastError()==4051) Print("H81:0 ",GetLastError()," tral >@45@0 BUY");

                 }

              }

            if(tip==OP_SELL)

              {

               PS+=OOP*OL; LS+=OL;

               ProfitS+=OrderProfit()+OrderCommission()+OrderSwap();

               s++;

               if(ProfitS>0 && Ask<NormalizeDouble((OOP -(tral+5)*Point),Digits))

                 {

                  //Print(Ask," < ",NormalizeDouble((OOP - (tral+5)*Point),Digits));

                  //Print(OrderStopLoss()," > ",OrderOpenPrice());

                  if(OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)

                    {

                     if(OrderStopLoss()!=NormalizeDouble((OOP-tral*Point),Digits))

                       {

                        tSL = NormalizeDouble((OOP-tral*Point),Digits);

                        tTP = OrderTakeProfit();

                        if(Check_SL_TP(ORDER_TYPE_SELL,tSL,tTP))

                           tmp=OrderModify(OrderTicket(),OrderOpenPrice(),tSL,tTP,OrderExpiration(),clrNONE);

                       }

                    }

                  else

                    {

                     //Print(OrderStopLoss()," != ",NormalizeDouble((OrderStopLoss() - (5)*Point),Digits));

                     if(OrderStopLoss()!=NormalizeDouble((OrderStopLoss() -(5)*Point),Digits))

                       {

                        tSL = NormalizeDouble((OrderStopLoss() -(5)*Point),Digits);

                        tTP = OrderTakeProfit();

                        if(Check_SL_TP(ORDER_TYPE_SELL,tSL,tTP))

                           tmp=OrderModify(OrderTicket(),OrderOpenPrice(),tSL,tTP,OrderExpiration(),clrNONE);

                       }

                    }

                  if(GetLastError()==4051) Print("H81:0 ",GetLastError()," tral >@45@0 SELL");

                 }

              }

           }

        }

     }

   // 0:@KB85 2A5E BUY ?@8 ?@>D8B5 <5=55 procent

   if (profit_test && ProfitB < -procent*AccountBalance()/100)

   {

      //Print(ProfitB,"  <  ",procent," / ",100," * ",AccountBalance()," = ",-procent*AccountBalance()/100);

      for (i=0; i<OrdersTotal(); i++)

      {    

         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

         { 

            if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())

            { 

               tip = OrderType(); 

               if (tip==OP_BUY)             

               {

                  tmp = OrderClose(OrderTicket(),OrderLots(),Bid,slippage,clrNONE);

               }

            }

          }

       }

   }

   // 0:@KB85 2A5E SELL ?@8 ?@>D8B5 <5=55 procent

   if (profit_test && ProfitS < -procent*AccountBalance()/100)

   {

      //Print(ProfitS,"  <  ",procent," / ",100," * ",AccountBalance()," = ",-procent*AccountBalance()/100);

      for (i=0; i<OrdersTotal(); i++)

      {    

         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

         { 

            if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())

            { 

               tip = OrderType(); 

               if (tip==OP_SELL)             

               {

                  tmp = OrderClose(OrderTicket(),OrderLots(),Ask,slippage,clrNONE);

               }

            }

          }

       }

   }  

  }//>=5F F8:;0

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

bool Check_SL_TP(ENUM_ORDER_TYPE type,double ttSL,double ttTP)

  {

//--- ?>;CG8< C@>25=L SYMBOL_TRADE_STOPS_LEVEL

   int stops_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);

   //if(stops_level!=0)

   //  {

   //   PrintFormat("SYMBOL_TRADE_STOPS_LEVEL=%d: StopLoss 8 TakeProfit 4>;6=K 1KBL"+

   //               " =5 1;865 %d ?C=:B>2 >B F5=K 70:@KB8O",stops_level,stops_level);

   //  }

//---

   bool SL_check=false,TP_check=false;

//--- ?@>25@O5< B>;L:> 420 B8?0 >@45@>2

   switch(type)

     {

      //--- >?5@0F8O ?>:C?:0

      case  ORDER_TYPE_BUY:

        {

         //--- ?@>25@8< StopLoss

         if(ttSL!=0) SL_check=(Bid-ttSL>stops_level*_Point); else SL_check=true;

         if(!SL_check)

            PrintFormat("For order %s StopLoss=%.5f must be less than %.5f"+

                        " (Bid=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d ?C=:B>2)",

                        EnumToString(type),ttSL,Bid-stops_level*_Point,Bid,stops_level);

         //--- ?@>25@8< TakeProfit

         if(ttTP!=0) TP_check=(ttTP-Bid>stops_level*_Point); else TP_check=true;

         if(!TP_check)

            PrintFormat("For order %s TakeProfit=%.5f must be greater than %.5f"+

                        " (Bid=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d ?C=:B>2)",

                        EnumToString(type),ttTP,Bid+stops_level*_Point,Bid,stops_level);

         //--- 25@=5< @57C;LB0B ?@>25@:8

         return(SL_check&&TP_check);

        }

      //--- >?5@0F8O ?@>4060

      case  ORDER_TYPE_SELL:

        {

         //--- ?@>25@8< StopLoss

         if(ttSL!=0) SL_check=(ttSL-Ask>stops_level*_Point); else SL_check=true;

         if(!SL_check)

            PrintFormat("For order %s StopLoss=%.5f must be greater than %.5f "+

                        " (Ask=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d ?C=:B>2)",

                        EnumToString(type),ttSL,Ask+stops_level*_Point,Ask,stops_level);

         //--- ?@>25@8< TakeProfit

         if(ttTP!=0) TP_check=(Ask-ttTP>stops_level*_Point); else TP_check=true;

         if(!TP_check)

            PrintFormat("For order %s TakeProfit=%.5f must be less than %.5f "+

                        " (Ask=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d ?C=:B>2)",

                        EnumToString(type),ttTP,Ask-stops_level*_Point,Ask,stops_level);

         //--- 25@=5< @57C;LB0B ?@>25@:8

         return(TP_check&&SL_check);

        }

      break;

     }

//--- 4;O >B;>65==KE >@45@>2 =C6=0 =5<=>3> 4@C30O DC=:F8O

   return false;

  }



bool CheckMoneyForTrade(string symb, double lots,int type)

  {

   double free_margin=AccountFreeMarginCheck(symb,type,lots);

   //-- 5A;8 45=53 =5 E20B05B

   if(free_margin<0)

     {

      string oper=(type==OP_BUY)? "Buy":"Sell";

      Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());

      return(false);

     }

   //-- ?@>25@:0 ?@>H;0 CA?5H=>

   return(true);

  }

//+------------------------------------------------------------------+

//| Timer function                                                   |

//+------------------------------------------------------------------+

void OnTimer()

  {

//---



  }

//+------------------------------------------------------------------+

bool celebrate_endday()

  {

   bool celeb=false;

   switch(Month())

     {

      case 1  : if(Day()>= 1 && Day() < 8) celeb = true; break;

      case 2  : if(Day() == 28 || Day() == 29) celeb = true; break;

      case 3  : if(Day() == 31) celeb = true; break;

      case 4  : if(Day() == 30) celeb = true; break;

      case 5  : if(Day() == 31) celeb = true; break;

      case 6  : if(Day() == 30) celeb = true; break;

      case 7  : if(Day() == 31) celeb = true; break;

      case 8  : if(Day() == 31) celeb = true; break;

      case 9  : if(Day() == 30) celeb = true; break;

      case 10 : if(Day() == 31) celeb = true; break;

      case 11 : if(Day() == 30) celeb = true; break;

      case 12 : if(Day()>23 && Day()<=31) celeb=true; break;

      default : celeb=false; break;

     }

   if(celebrate) return (celeb);

   else return (false);

  }

//Proverka po chasam

bool hour_test()

  {

   bool test=false;

   switch(Hour())

     {

      case  0: if(hour_00) test = true; break;

      case  1: if(hour_01) test = true; break;

      case  2: if(hour_02) test = true; break;

      case  3: if(hour_03) test = true; break;

      case  4: if(hour_04) test = true; break;

      case  5: if(hour_05) test = true; break;

      case  6: if(hour_06) test = true; break;

      case  7: if(hour_07) test = true; break;

      case  8: if(hour_08) test = true; break;

      case  9: if(hour_09) test = true; break;

      case 10: if(hour_10) test = true; break;

      case 11: if(hour_11) test = true; break;

      case 12: if(hour_12) test = true; break;

      case 13: if(hour_13) test = true; break;

      case 14: if(hour_14) test = true; break;

      case 15: if(hour_15) test = true; break;

      case 16: if(hour_16) test = true; break;

      case 17: if(hour_17) test = true; break;

      case 18: if(hour_18) test = true; break;

      case 19: if(hour_19) test = true; break;

      case 20: if(hour_20) test = true; break;

      case 21: if(hour_21) test = true; break;

      case 22: if(hour_22) test = true; break;

      case 23: if(hour_23) test = true; break;

     }

   if(test) return (true);

   else return (false);

  }

//+------------------------------------------------------------------+

//| Tester function                                                  |

//+------------------------------------------------------------------+

double GetRecoveryFactor(void)

  {

   double Res=0;

   double MaxDD=TesterStatistics(STAT_EQUITY_DD);

   if(MaxDD!=0)

      Res=TesterStatistics(STAT_PROFIT)/MaxDD;

   return(Res);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double OnTester(void)

  {

   return(GetRecoveryFactor());

  }

//+------------------------------------------------------------------+

Comments