Author: QstrCorp
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicatorRelative Vigor indexRelative strength index
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
qstr3_5
ÿþ//+------------------------------------------------------------------+

//|                                                        qstr3.mq4 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                             https://www.qstr.com |

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

#property copyright "QstrCorp"

#property link      "https://www.qstr.com"

#property version   "1.00"

#property strict



//--- input parameters

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

extern int                TakeProfit    = 1500;

extern int                StopLoss      = 500;

extern double Lots=1;     // 5AB:> 7040==>5 :>;8G. ;>B>2

extern double Prots=0.07;    // @>F5=B A2>1>4=KE A@54AB2



                             // 038G5A:89 =><5@ >B:@KB>3> >@45@0

extern int                Magic=12345;

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

sinput string             MA            = "0AB@>9:8 8=48:0B>@0 Moving average";

extern int                ma_period     = 20;

extern int                ma_shift      = 0;

extern ENUM_MA_METHOD     ma_method     = MODE_EMA;

extern ENUM_APPLIED_PRICE applied_price = PRICE_CLOSE;

extern int                shift         = 0;



extern int    Period_MA_1=14;      // 5@8>4  1

extern int    Period_MA_2=30;      // 5@8>4  2

extern int    Period_MA_3=120;      // 5@8>4  3

extern int    v14=5;                 // 8=. :>@>ABL 87<5=5=8O  2 ?C=:B0E =0 10@ :0: >?@545;5=85 D;5B0

extern int    v30=5;                 // 8=. :>@>ABL 87<5=5=8O  2 ?C=:B0E =0 10@ :0: >?@545;5=85 D;5B0

extern int    v120=5;                 // 8=. :>@>ABL 87<5=5=8O  2 ?C=:B0E =0 10@ :0: >?@545;5=85 D;5B0

extern int    n=12;                 // @0B=>ABL C<5=LH5=8O "$ 8 C25;8G5=8O ?5@8>40 ?@>AG5B0

extern double Rastvor    =28.0;    //  0AAB>O=85 <564C  



string

Symb;                            // A8<2>; 2K1@0==>3> >@45@0



int

cnt=0,                           // ><5@ >@45@0

Total,                           // >;8G5AB2> >@45@>2 2 >:=5 

Tip=-1,                          // "8? 2K1@0=. >@45@0 (B=0,S=1 -1 =5B >@45@0)

Ticket,                          // "8:5B >@45@0

Or=-1,                           // !>AB>O=85 -1 =5B =0H8E >@45@>2, 645< A83=0;0 >B:@KB8O 109 8;8 A5;;,

                                 // 0 >B:@KB >@45@ 109, 645< A83=0;0 70:@KB8O >@45@0 109, 

// 1 >B:@KB >@45@ A5;;, 645< A83=0;8 70:@KB8O A5;;

TrOr=-1,// !83=0; >B:@KB8O >@45@>2 ?>   

OpOr=-1,                         // !83=0; >B:@KB8O >@45@>2 -1 =5B, 0 109, 1 A5;;

ClOr=-1;                         // !83=0; 70:@KB8O >@45@0 -1 =5B, 0 109, 1 A5;;



double  MA14[26],MA30[26],MA120[26],RMA[26],//>10@=K5 7=0G5=8O  8 @07=8F0 14 8 30   

MA14n[26],MA30n[26],MA120n[26],RMAn[26],

VRMAn[26],// !:>@>ABL 87<5=5=8O @07=8FK 14 8 30    

VMA14[26],VMA30[26],VMA120[26],// !:>@>AB8 87<5=5=8O  2 ?C=:B0E =0 10@

VMA14s[26],VMA30s[26],VMA120s[26],

VMA14n[26],VMA30n[26],VMA120n[26],

VMA14ns[26],VMA30ns[26],VMA120ns[26],VM120n[26],



RVM[5],RVS[5],RRV[5],// >10@=K5 7=0G5=8O RVI 8 8E @07=8F0

RVMn[3],RVSn[3],RRVn[5],

RS5[5],RS14[5],RS30[5],RS5n[5],// >10@=K5 7=0G5=8O RSI5,RSI14,RSI30, 

RRS5_14[5],RRS5_30[5];        // >10@=K5 7=0G5=8O @07=8FK RSI5-RSI14 ,RSI5-RSI30,



int Tr=-1,TrV=-1,TrS=-1,          // =0G5=8O B@5=40 ,  ,  ! -1 D45B >6840=85, 0 225@E 09, 1 2=87 !5;;

    Tr0, Tr1 ,Tr2 ,Tr3 , Tr4;       // =0G5=8O B@5=40  ?>B8:>2> =0 5 B8:0E



double

MA_1_t,                          // =0G5=. _1 B5:CI55

MA_2_t,                          // =0G5=. _2 B5:CI55 

Lot,                             // >;8G. ;>B>2 2 2K1@0=.>@45@5

Lts,                             // >;8G. ;>B>2 2 >B:@K2.>@45@5

Min_Lot,                         // 8=8<0;L=>5 :>;8G5AB2> ;>B>2

Step,                            // (03 87<5=5=8O @07<5@0 ;>B0

Free,                            // "5:CI85 A2>1>4=K5 A@54AB20

One_Lot,                         // !B>8<>ABL >4=>3> ;>B0

Price,                           // &5=0 2K1@0==>3> >@45@0

SL,                              // SL 2K1@0==>3> >@45@0 

TP;                              // TP 2K1@0==>3> >@45@0

bool

Ans  =false,                     // B25B A5@25@0 ?>A;5 70:@KB8O

Cls_B=false,                     // @8B5@89 4;O 70:@KB8O  Buy

Cls_S=false,                     // @8B5@89 4;O 70:@KB8O  Sell

Opn_B=false,                     // @8B5@89 4;O >B:@KB8O  Buy

Opn_S=false,                     // @8B5@89 4;O >B:@KB8O  Sell

Work=true;                       // @8B5@89 @01>BK, 5A;8 :@8B8G5A:0O >H81:0 8;8 :>;8G5AB2> =0H8E >@45@>2 1>;55 1

bool sel=false;

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

//| Expert initialization function                                   |

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

int OnInit()

  {



   Countinit();



//--- create timer

   EventSetTimer(60);



//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//--- destroy timer

   EventKillTimer();



  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

   Total=Count();



// @5420@8B.>1@01>B:0

   if(Bars<Period_MA_2) // 54>AB0B>G=> 10@>2

     {

      Alert("54>AB0B>G=> 10@>2 2 >:=5. -:A?5@B =5 @01>B05B.");

      return;                                   // KE>4 87 start()

     }

   if(Work==false) // @8B8G5A:0O >H81:0

     {

      Alert("@8B8G5A:0O >H81:0. -:A?5@B =5 @01>B05B.");

      return;                                   // KE>4 87 start()

     }

//--------------------------------------------------------------- 4 --

// >B8:>2>5 ?@8A2>5=85 B@5=40    

   Tr4=Tr3;                                   

   Tr3=Tr2;

   Tr2=Tr1;

   Tr1=Tr0;

   Tr0=Tr;

// 2K7>2 DC=:F89 B@5=40, D;030 >B:@KB8O >@45@>2  

   Tr=IMA();

   TrOr=TROR();

   TrV=RVI();

   TrS=RSI();



  Print("Tr= ",Tr," 14[1]= ",MA14n[1]," < > ",MA14n[2]," V14[1]= ",VMA14n[1]," < > ",VMA14n[2]," < > ",VMA14n[3],

  " R[1]= ",RMAn[1]," < > ",RMAn[2]," < > ",RMAn[3]," 120[1]= ",MA120n[1]," < > ",MA120n[2]," V120[1]= ",VMA120n[1], "   " ,VM120n[1], "   " ,VMA120[1]," VR[1]= ",VRMAn[1]);

  

   Comment(">;-2> =0H8E >@45@>2 = ",Total," "8? = ",Tip,"  ",OrderType()," Or = ",Or," sel = ",sel,

           "Magic ",OrderMagicNumber(),"@45@>2 2A53> ",OrdersTotal()," 0@>2 ",Bars,"\n",

           ""@5=4 = ",Tr,"\n",

           "$;03 "   = ",TrOr,"\n",

           ""@5=4 RSI = ",TrS,"\n",

           "&5=0 Ask = ",Ask,"\n",

           " 07<5@ ?C=:B0 = ",Point,"\n",

           ">;8G5AB2> 7=0:>2, ?>A;5 70?OB>9 = ",Digits,"\n",

           "><5@ 2K1@0==. >@4 ",cnt," = ","\n",// .

           ""8:5B 2K1@0==. >@4 ",Ticket," = ",OrderTicket(),

           "&5=0 2K1@0==. >@4. ",Price," = ",OrderOpenPrice(),"\n",// 

           " SL 2K1@0==>3> >@4.  ",SL," = ",OrderStopLoss(),"\n",// 

           "TP 2K1@0==>3> >@4.  ",TP," = ",OrderTakeProfit(),"\n",// 

           ">;8G5AB2> ;>B>2  ",Lot," = ",OrderLots() // 



           );



//---

   if(Or==-1)

     {

      if(TrOr==0 //&& TrV==0 && TrS==0

         )

        {

         OpOr=0;

         Or=OpenOr(OpOr);



         return;

        }

      if(TrOr==1 //&& TrV==1 && TrS==1

         )

        {

         OpOr=1;

         Or=OpenOr(OpOr);



         return;

        }

      OpOr=-1;

      return;

     }



   if(Or==0)

     {

      if(Tr==0 || Tr0==0 || Tr1==0 || Tr2==0 // || Tr3==0 || Tr4==0 //&& TrV==0 && TrS==0

         )

        {

         return;

        }

      else

        {

         ClOr=0;

         Or=CloseOr(ClOr);

         return;

        }

     }



   if(Or==1)

     {

      if(Tr==1 || Tr0==1 || Tr1==1 || Tr2==1 // || Tr3==1 || Tr4==1 //&& TrV==1 && TrS==1

         )

        {

         return;

        }

      else

        {

         ClOr=1;

         Or=CloseOr(ClOr);

         return;

        }

     }



  }

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

//| Timer function                                                   |

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

void OnTimer()

  {

//---



  }

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

int Countinit() // !G5BG8: >@45@>2 ?@8 8=8F80;870F88, >72@0I05B :>;8G5AB2> >@45@>2 A =0H8< <038:

  {



   int Totalin=0;

   for(int cin=0; cin<OrdersTotal(); cin++)

     {

      if(sel=OrderSelect(cin,SELECT_BY_POS,MODE_TRADES))

        {

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

            Totalin++;

        }

     }

   if(Totalin>0) // 5 1>;55 >4=>3> >@45@0 A =0H8< <038: 2 =0G0;5 @01>BK M:A?5@B0

     {

      Alert(">;8G5AB2> >@45@>2 A =0H8< <038: = ",Totalin," ><5=O9B5 <038: 8;8 C40;8B5 >@45@0. -:A?5@B =5 @01>B05B.");

      Comment("I81:0 - :>;8G5AB2> >@45@>2 A =0H8< 038: = ",Totalin);

      Work=false;



      return(Totalin);                             // KE>4 87 Countinit()

     }

   Work=true;

   return(Totalin);

  }

//>=5F ?>4AG5B0 >@45@>2 ?@8 8=8F80;870F88 M:A?5@B0+------------------------------------------------------------------+

//|                                                                  |

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

int Count() // !G5BG8: >@45@>2, >72@0I05B :>;8G5AB2> >@45@>2 A =0H8< <038:

  {

   Total=0;

   Ticket=0;                  // ><5@ 2K1@0==. >@4.

   Symb="";                   //=AB@C<5=B >@45@0

   Tip=-1;                    // "8? 2K1@0==>3> >@4.

   Price=0;               // &5=0 2K1@0==. >@4.

   SL=0;                // SL 2K1@0==>3> >@4.

   TP=0;              // TP 2K1@0==>3> >@4.

   Lot=0;                    // >;8G5AB2> ;>B>2

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

     {

      if(sel=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))

        {

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

            Total++;

        }

     }

//   Alert(Total);

   if(Total>1) // 5 1>;55 >4=>3> >@4

     {

      Alert("@45@>2 A =0H8< <038: 1>;LH5 >4=>3> = ",Total," ><5=O9B5 <038: 8;8 C40;8B5 >@45@0. -:A?5@B =5 @01>B05B.");

      Comment("I81:0 2> 2@5<O @01>BK, :>;8G5AB2> >@45@>2 A =0H8< 038: = ",Total);

      Work=false;

      return(Total);                             // KE>4 87 Count()

     }

   if(Total==1)

     {

      Ticket=OrderTicket();                  // ><5@ 2K1@0==. >@4.

      Tip   =OrderType();                    // "8? 2K1@0==>3> >@4.

      Symb= Symbol();                        //=AB@C<5=B 2K1@0==>3> >@45@0;                   

      Price =OrderOpenPrice();               // &5=0 2K1@0==. >@4.

      SL    =OrderStopLoss();                // SL 2K1@0==>3> >@4.

      TP    =OrderTakeProfit();              // TP 2K1@0==>3> >@4.

      Lot   =OrderLots();                    // >;8G5AB2> ;>B>2

      if(Tip==OP_BUY)Or=0;

      if(Tip==OP_SELL)Or=1;

      if(Tip==OP_BUYSTOP)Or=4;

      if(Tip==OP_SELLSTOP )Or=5;

      Work=true;

      return(Total);                             // KE>4 87 Count()

     }

   if(Total==0)

     {

      Or=-1;

      Total=0;

      Ticket=0;                  // ><5@ 2K1@0==. >@4.

      Symb="";                   //=AB@C<5=B >@45@0

      Tip=-1;                    // "8? 2K1@0==>3> >@4.

      Price=0;               // &5=0 2K1@0==. >@4.

      SL=0;                // SL 2K1@0==>3> >@4.

      TP=0;              // TP 2K1@0==>3> >@4.

      Lot=0;                    // >;8G5AB2> ;>B>2

      Work=true;

     }

   return(Total);

  }

//>=5F ?>4AG5B0 >@45@>2+------------------------------------------------------------------+

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

//>4AG5B A:>;L7OI8E A@54=8E  ?>10@=>, 2>72@0I05B B@5=4 Tr -1 D;5B, 0 225@E 09, 1 2=87 !5;;

int IMA()

  {

   for(int i=1; i<22; i++)

     {

      MA14n[i]=NormalizeDouble((iMA(NULL,0,14*n,ma_shift,ma_method,applied_price,i)),7);

      MA14[i]=NormalizeDouble((iMA(NULL,Period()*n,14,ma_shift,ma_method,applied_price,i)),7);

      MA30n[i]=NormalizeDouble((iMA(NULL,0,30*n,ma_shift,ma_method,applied_price,i)),7);

      MA30[i]=NormalizeDouble ((iMA(NULL,Period()*n,30, ma_shift,ma_method,applied_price,i)),7);

      MA120n[i]=NormalizeDouble ((iMA(NULL,0,120*n, ma_shift,ma_method,applied_price,i)),7);

      MA120[i]=NormalizeDouble((iMA(NULL,Period()*n,120,ma_shift,ma_method,applied_price,i)),7);

     }

     

     for(int i=1; i<22; i++)

      {

      VMA14n[i]=NormalizeDouble(((MA14n[i]-MA14[i+1])/Point),2);

      VMA30n[i]=NormalizeDouble(((MA30n[i]-MA30[i+1])/Point),2);

      VM120n[i]=NormalizeDouble(((MA120n[i]-MA120n[i+1])/Point),2);

       VMA120n[i]=NormalizeDouble((((MA120n[i]-MA120n[i+1])/Point)*4),2);



      VMA14[i]=NormalizeDouble(((MA14[i]-MA14[i+1])/Point),5);

      VMA30[i]=NormalizeDouble(((MA30[i]-MA30[i+1])/Point),5);

      VMA120[i]=NormalizeDouble(((MA120[i]-MA120[i+1])/Point),5);



      VMA14s[i]=NormalizeDouble((MathAbs(((MA14[i]-MA14[i+4])/Point)/4)),5);

      VMA30s[i]=NormalizeDouble((MathAbs(((MA30[i]-MA30[i+4])/Point)/4)),5);

      VMA120s[i]=NormalizeDouble((MathAbs(((MA120[i]-MA120[i+4])/Point)/4)),5);

     

      VMA14ns[i]=NormalizeDouble((MathAbs((MA14n[i]-MA14[i+4])/Point)),5);

      VMA30ns[i]=NormalizeDouble((MathAbs((MA30n[i]-MA30[i+4])/Point)),5);

      VMA120ns[i]=NormalizeDouble((MathAbs((MA120n[i]-MA120[i+4])/Point)),5);

      

      RMA[i]=NormalizeDouble((MA14[i]-MA30[i])/Point,5);

      RMAn[i]=NormalizeDouble((MA14n[i]-MA30n[i])/Point,5);

      VRMAn[i]=NormalizeDouble((RMAn[i]-RMAn[i+1]),5);



     }

  // @>25@:0 CAB>9G82>3> B@5=40

   if(      RMAn[1]>=100 && VMA14n[1]>=16 && VMA120n[1]>=4

     )

     {

      Tr=0;

      return(Tr);

     }

  

   if(

     RMAn[1]<=-100 && VMA14n[1]<=-16 && VMA120n[1]<=-4

      )

     {

      Tr=1;

      return(Tr);

     }

 

   if(

      VMA120n[1] > 2&& 

      VMA14n[1] > 8 &&

      VRMAn[1] >= 0.5

      )

     {

      Tr=0;

      return(Tr);

     }

   if(

      VMA120n[1]<-2 &&

      VMA14n[1]<-8 &&

      VRMAn[1]<=-0.5

      )

     {

      Tr=1;

      return(Tr);

     }

   Tr=-1;



   return(Tr);

   

  }

 //>=5F ?>4AG5B0 +------------------------------------------------------------------+

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

  int TROR()

  {

   if(

     Tr==0 && Tr0==0 && Tr1==0 && Tr2==0 && ((Tr3==-1 && Tr4==-1) || (Tr3==1 && Tr4==1))

      )

     {

      TrOr=0;

      return(TrOr);

     }



   if(

     Tr==1 && Tr0==1 && Tr1==1 && Tr2==1 && ((Tr3==-1 && Tr4==-1) || (Tr3==0 && Tr4==0))

      )

     {

      TrOr=1;

      return(TrOr);

     }

   TrOr=-1;



   return(TrOr);

   

   

  }

//>=5F CG5B0 D;03> >B:@KB8O >@45@>2+------------------------------------------------------------------+

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

//>4AG5B RVI ?>10@=>, 2>72@0I05B A83=0; TRV -1 D;5B, 0 225@E 09, 1 2=87 !5;;



int RVI()

  {

   for(int i=0; i<3; i++)

     {

      RVM[i]=iRVI(NULL,0,10,MODE_MAIN,i);

      RVMn[i]=iRVI(NULL,Period()/2,10*2,MODE_MAIN,i);

      RVS[i]=iRVI(NULL,0,10,MODE_SIGNAL,i);

      RVSn[i]=iRVI(NULL,Period()/2,10*2,MODE_SIGNAL,i);

      RRV[i]=RVM[i]-RVS[i];

     }

   if(RVMn[1]>=RVMn[2] && RVM[1]>=RVM[2]

      //   && RVMn[1]>=RVSn[1]

      //  && RVM[1]>=RVS[1] && RVM[2]>=RVS[2]

      // && RRV[0]>RRV[1] && RRV[1]>=RRV[2]

      )

     {

      TrV=0;

      return(TrV);

     }

   if(RVMn[1]<=RVMn[2] && RVM[1]<=RVM[2]

      //    && RVMn[1]<=RVSn[1]

      //    && RVMn[2]<=RVSn[2] && RVM[2]<=RVS[2]

      //  && RRV[0]<RRV[1] && RRV[1]<=RRV[2]

      )

     {

      TrV=1;

      return(TrV);

     }

   TrV=-1;



   return(TrV);

  }

//>=5F ?>4AG5B0  +------------------------------------------------------------------+

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



//>4AG5B RSI ?>10@=>, 2>72@0I05B A83=0; TrS -1 D;5B, 0 225@E 09, 1 2=87 !5;;



int RSI()

  {

   for(int i=0; i<3; i++)

     {

      RS5[i]=iRSI(NULL,0,5,PRICE_CLOSE,i);

      RS5n[i]=iRSI(NULL,Period()/2,5,PRICE_CLOSE,i);

      RS14[i]=iRSI(NULL,Period()/2,14,PRICE_CLOSE,i);

      RS30[i]=iRSI(NULL,Period()/2,30,PRICE_CLOSE,i);

      RRS5_14[i]=RS5[i]-RS14[i];

      RRS5_30[i]=RS5[i]-RS30[i];

     }

   if(RS5n[1]>RS5n[2] && RS5[1]>=RS5[2]

      //    && RS14[0]>RS14[1] && RS14[1]>=RS14[2]

      //   &&  RRS5_14[0]>RRS5_14[1] && RRS5_14[1]>=RRS5_14[2]

      //    && MathAbs(RRS5_30[0])>=MathAbs(RRS5_14[0])

      //    && MathAbs(RRS5_30[1])>=MathAbs(RRS5_14[1])

      //    && MathAbs(RRS5_30[2])>=MathAbs(RRS5_14[2])

      )

     {

      TrS=0;

      return(TrS);

     }

   if(RS5n[1]<RS5n[2] && RS5[1]<=RS5[2]

      //    && RS14[0]<RS14[1] && RS14[1]<=RS14[2]&&

      //     RRS5_14[0]<RRS5_14[1] && RRS5_14[1]<=RRS5_14[2]

      //    &&  MathAbs(RRS5_30[0])>=MathAbs(RRS5_14[0])

      //    && MathAbs( RRS5_30[1])>=MathAbs (RRS5_14[1])

      //   && MathAbs( RRS5_30[2])>=MathAbs (RRS5_14[2])

      )

     {

      TrS=1;

      return(TrS);

     }

   TrS=-1;



   return(TrS);

  }

//>=5F ?>4AG5B0  !+------------------------------------------------------------------+

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

// B:@KB85 >@45@>2

int OpenOr(int Op)

  {



// B:@KB85 >@45@>2

   while(true) // &8:; 70:@KB8O >@4.

     {

      if(Total==0 && OpOr==0) // B:@KBKE >@4. =5B  + :@8B5@89 >B:@. Buy

        {                                       // 

         RefreshRates();                        // 1=>2;5=85 40==KE

         SL=Bid - New_Stop(StopLoss)*Point;     // KG8A;5=85 SL >B:@.

         TP=Bid + New_Stop(TakeProfit)*Point;   // KG8A;5=85 TP >B:@.

         Alert(">?KB:0 >B:@KBL Buy. 6840=85 >B25B0..");

         Ticket=OrderSend(Symb,OP_BUY,Lots,Ask,2,SL,TP,"QstrBuy",Magic,0,Blue);//B:@KB85 Buy

         if(Ticket>0) // >;CG8;>AL :)

           {

            Alert(Symbol()," "$ ",Period(),"B:@KB >@45@ Buy ?> F5=5 ",Ask,"Ticket = ",Ticket);

            Or=0;

            return(Or);                             // KE>4 87 start()

           }

         if(Fun_Error(GetLastError())==1) // 1@01>B:0 >H81>:

            continue;                           // >2B>@=0O ?>?KB:0

         return(Or);                                // KE>4 87 start()

        }

      if(Total==0 && OpOr==1) // B:@KBKE >@4. =5B + :@8B5@89 >B:@. Sell

        {                                       //

         RefreshRates();                        // 1=>2;5=85 40==KE

         SL=Ask + New_Stop(StopLoss)*Point;     // KG8A;5=85 SL >B:@.

         TP=Ask - New_Stop(TakeProfit)*Point;   // KG8A;5=85 TP >B:@.

         Alert(">?KB:0 >B:@KBL Sell. 6840=85 >B25B0..");

         Ticket=OrderSend(Symb,OP_SELL,Lots,Bid,2,SL,TP,"QstrSell",Magic,0,Blue);//B:@KB85 Sel

         if(Ticket>0) // >;CG8;>AL :)

           {

            Alert(Symbol()," "$ ",Period(),"B:@KB >@45@ Sell ?> F5=5 ",Bid,"Ticket = ",Ticket);

            Or=1;

            return(Or);                             // KE>4 87 start()

           }

         if(Fun_Error(GetLastError())==1) // 1@01>B:0 >H81>:

            continue;                           // >2B>@=0O ?>?KB:0

         return(Or);                                // KE>4 87 start()

        }

      break;                                    // KE>4 87 while

     }

//--------------------------------------------------------------- 9 --

   return(Or);                                      // KE>4 87 start()

  }

//-------------------------------------------------------------- 10 --





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

int CloseOr(int Cls)

  {



// 0:@KB85 >@45@>2

   while(true) // &8:; 70:@KB8O >@4.

     {

      if(Or==0 && ClOr==0) // B:@KB >@45@ Buy..

        {                                       //8 5ABL :@8B5@89 70:@

         Alert(">?KB:0 70:@KBL Buy ",Ticket,". 6840=85 >B25B0..");

         RefreshRates();                        // 1=>2;5=85 40==KE

         Ans=OrderClose(Ticket,Lots,Bid,2);      // 0:@KB85 Buy

         if(Ans==true) // >;CG8;>AL :)

           {

            Alert(Symbol()," "$ ",Period(),"0:@KB >@45@ Buy ?> F5=5 = ",Bid,"Ticket = ",Ticket);

            Or=-1;

            break;                              // KE>4 87 F8:;0 70:@

           }

         if(Fun_Error(GetLastError())==1) // 1@01>B:0 >H81>:

            continue;                           // >2B>@=0O ?>?KB:0

         return(Or);                                // KE>4 87 start()

        }



      if(Or==1 && ClOr==1) // B:@KB >@45@ Sell..

        {                                       // 8 5ABL :@8B5@89 70:@

         Alert(">?KB:0 70:@KBL Sell ",Ticket,". 6840=85 >B25B0..");

         RefreshRates();                        // 1=>2;5=85 40==KE

         Ans=OrderClose(Ticket,Lots,Ask,2);      // 0:@KB85 Sell

         if(Ans==true) // >;CG8;>AL :)

           {

            Alert(Symbol()," "$ ",Period(),"0:@KB >@45@ Sell ?> F5=5 ",Ask,"Ticket = ",Ticket);

            Or=-1;

            break;                              // KE>4 87 F8:;0 70:@

           }

         if(Fun_Error(GetLastError())==1) // 1@01>B:0 >H81>:

            continue;                           // >2B>@=0O ?>?KB:0

         return(Or);                                // KE>4 87 start()

        }

      break;                                    // KE>4 87 while

     }



   return(Or);

  }

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



//-------------------------------------------------------------- 10 --

int Fun_Error(int Error) // $-8O >1@01>B >H81>:

  {

   switch(Error)

     {                                          // @5>4>;8<K5 >H81:8            

      case  4: Alert("">@3>2K9 A5@25@ 70=OB. @>1C5< 5IQ @07..");

      Sleep(3000);                           // @>AB>5 @5H5=85

      return(1);                             // KE>4 87 DC=:F88

      case 135:Alert("&5=0 87<5=8;0AL. @>1C5< 5IQ @07..");

      RefreshRates();                        // 1=>28< 40==K5

      return(1);                             // KE>4 87 DC=:F88

      case 136:Alert("5B F5=. 4Q< =>2K9 B8:..");

      while(RefreshRates()==false)           // > =>2>3> B8:0

         Sleep(1);                           // 045@6:0 2 F8:;5

      return(1);                             // KE>4 87 DC=:F88

      case 137:Alert("@>:5@ 70=OB. @>1C5< 5IQ @07..");

      Sleep(3000);                           // @>AB>5 @5H5=85

      return(1);                             // KE>4 87 DC=:F88

      case 146:Alert(">4A8AB5<0 B>@3>2;8 70=OB0. @>1C5< 5IQ..");

      Sleep(500);                            // @>AB>5 @5H5=85

      return(1);                             // KE>4 87 DC=:F88

                                             // @8B8G5A:85 >H81:8

      case  2: Alert("1I0O >H81:0.");

      return(0);                             // KE>4 87 DC=:F88

      case  5: Alert("!B0@0O 25@A8O B5@<8=0;0.");

      Work=false;                            // >;LH5 =5 @01>B0BL

      return(0);                             // KE>4 87 DC=:F88

      case 64: Alert("!G5B 701;>:8@>20=.");

      Work=false;                            // >;LH5 =5 @01>B0BL

      return(0);                             // KE>4 87 DC=:F88

      case 133:Alert("">@3>2;O 70?@5I5=0.");

      return(0);                             // KE>4 87 DC=:F88

      case 134:Alert("54>AB0B>G=> 45=53 4;O A>25@H5=8O >?5@0F88.");

      return(0);                             // KE>4 87 DC=:F88

      default: Alert(">7=8:;0 >H81:0 ",Error); // @C385 20@80=BK   

      return(0);                             // KE>4 87 DC=:F88

     }

  }

//-------------------------------------------------------------- 11 --

//-------------------------------------------------------------- 11 --

int New_Stop(int Parametr) // @>25@:0 AB>?-?@8:.

  {

   int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// 8=8<. 48AB0=F8O

   if(Parametr<Min_Dist) // A;8 <5=LH5 4>?CAB.

     {

      Parametr=Min_Dist;                        // #AB0=>28< 4>?CAB.

      Alert("#25;8G5=0 48AB0=F8O AB>?-?@8:070.");

     }

   return(Parametr);                            // >72@0B 7=0G5=8O

  }

//-------------------------------------------------------------- 12 --

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---