limits_martin2_1

Author: Dmitriy Epshteyn
Orders Execution
Checks for the total of closed ordersChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
3 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/CAD Oct 2024 - Jan 2025
0.00 %
Total Trades 3
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -2.17
Gross Profit 0.00
Gross Loss -6.52
Total Net Profit -6.52
-100%
-50%
0%
50%
100%
limits_martin2_1
ÿþ//+------------------------------------------------------------------+

//|                                                Limits_Martin.mq4 |

//|                                                 Dmitriy Epshteyn |

//|                                                  setkafx@mail.ru |

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

#property copyright "Dmitriy Epshteyn"

#property link      "setkafx@mail.ru"

#property version   "1.02"

#property strict



extern bool        Buy = true;

extern bool        Sell = true;

extern int         Limits0_or_Stops1=0;

// 5A;8 0 - B>@3C5< ;8<8B=K<8 >@45@0<8, 5A;8 1 - B>@3C5< AB>?>2K<8

extern bool        Last_Price_Limit_Use=false;

//?>A;5 C40;5=8O A>25B=8:>< ;8<8B=>9 >B;>6:8 ?@8 ?>O2;5=88 @K=>G=>3> >@45@0, A;54CNI89 ;8<8B=K9 >@45@ B0:>3> 65 B8?0 2KAB028BAO ?> B>9 65 F5=5

// (;CGH5 >AB028BL false)

extern bool        Last_Price_Stops_Use=false;

//?>A;5 C40;5=8O A>25B=8:>< >B;>6:8 ?@8 ?>O2;5=88 @K=>G=>3> >@45@0, A;54CNI89 >B;>65==K9 AB>? >@45@ B0:>3> 65 B8?0 2KAB028BAO ?> B>9 65 F5=5

extern int         Step=200;

//@0AAB>O=85, =0 :>B>@>< 2KAB02;ONBAO 8 BO=CBLAO >@45@0 70 F5=>9

extern int         Step_Interval=10;

// H03 2 ?C=:B0E, G5@57 :>B>@K9 >B;>65==K5 >@45@0 ?>4BO3820NBAO : @K=>G=>9 F5=5

extern int         SL=30;

//AB>? ;>AA

extern int         TP=60;

//B59: ?@>D8B



extern bool  Martin=true;

//2:;NG8BL <0@B8= 

extern int         Limit=10;

//>3@0=8G5=85 :>;8G5AB20 C<=>65=89 ;>B0

extern double      Lots=0.01;

//;>B

extern bool        MegaLot=true;

// ?@8 >B:@KB88 A;54CNI53> >@45@0 2 A;CG05, 5A;8 ?>A;54=89 >@45@ (A5@8O C1KB>G=KE >@45@>2) 70:@K;AO C1KB:><, 

// ;>B 1C45B @0AAG8BK20BLAO B0:8< >1@07><,

// GB>1K ?5@5:@KBL ?@54K4CI85 C1KB:8 8 70@01>B0BL AC<<C 2 20;NB5 45?>78B0 = :>;-2> ?C=:B>2 ?> B59: ?@>D8BC, 70:@KBK5  AB0@B>2K< ;>B>< 

extern string A2="_______________Trailing Stop___________";

extern bool Trailing_Use=true;

// 2:;NG8BL B@59;8=3 AB>? >@45@>2 (@01>B05B, 5A;8 ?>A;54=89 >@45@ 70:@K;AO ?@>D8B>< ;81> 2 =>;L)

extern int Profit_Level_Trailing=100;

// C@>25=L ?@>D8B0 2 ?C=:B0E, ?@8 4>AB865=88 >@45@0 :>B>@K< =0G8=05B @01>B0BL B@59;8=3 AB>? 

extern int TrailingStop=50;

//  0AAB>O=85 TrailingStop ?C=:B>2, =0 :>B>@>< AB>? ;>AA >@45@0 1C45B BO=CBLAO 70 F5=>9

extern int TrailingStep=50;

// (03 2 ?C=:B0E, G5@57 :>B>@K9 1C45B ?5@5<5I0BLAO  AB>? ;>AA >@45@0 

extern string A3="_______________Breakeven______________";

extern bool Breakeven_Use=true;

// 2:;NG8BL 157C1KB>: 

extern int Profit_Level=30;

// @45@ 2KE>48B 2 ?;NA =0 C:070==>5 :>;8G5AB2> ?C=:B>2 (4;O 157C1KB:0)

extern int SL_Plus=10;

// KAB02;O5BAO 157C1KB>: >@45@0+SL_Plus 2 ?C=:B0E

extern int         Slip=5;

// @>A:0;L7K20=85

extern int         Magic=100;

//8=48284C0;L=K9 =><5@ M:A?5@B0



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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---



//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---



  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

   ENUM_TIMEFRAMES TF=PERIOD_CURRENT;



   int orders=0;

   int accTotal1=OrdersHistoryTotal();

   for(int h_1=accTotal1-1;h_1>=0;h_1--)

      if(OrderSelect(h_1,SELECT_BY_POS,MODE_HISTORY))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

               if(OrderType()==OP_BUY || OrderType()==OP_SELL)

                 {

                  if(OrderCloseTime()>=iTime(NULL,TF,0)) {orders++; }

                  if(OrderCloseTime()<iTime(NULL,TF,0)) {break;}

                 }

//--------------8AB>@8O  >@45@>2--------------

   int loss=0; // :>;-2> >@45@>2, 70:@KBKE 2 ?>4@O4 A C1KB:><

   double loss_profit=0;

   for(int h_2=accTotal1-1;h_2>=0;h_2--)

      if(OrderSelect(h_2,SELECT_BY_POS,MODE_HISTORY))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

              {

               if(OrderProfit()<0) {loss++;loss_profit+=OrderProfit()+OrderSwap()+OrderCommission(); }

               if(OrderProfit()>0) {break;}

              }

   int    OP_TYPE=-1;

   double h_Lot=0; // ;>B ?>A;54=53> >@45@0

   double last_profit=0; // ?@>D8B ?>A;54=53> 70:@KB>3> >@45@0

   for(int h_3=accTotal1-1;h_3>=0;h_3--)

      if(OrderSelect(h_3,SELECT_BY_POS,MODE_HISTORY))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

              {

               if(OrderType()==OP_BUY || OrderType()==OP_SELL) {h_Lot=OrderLots(); last_profit=OrderProfit()+OrderSwap()+OrderCommission();OP_TYPE=OrderType(); break;}

              }

   double last_limit_price=0; // F5=0 >B:@KB8O ?>A;54=53> C40;5==>3> ;8<8B=>3> >@45@0

   int OP_TYPE_LIMIT=-1; // B8? ?>A;54=53> C40;5==>3> ;8<8B=>3> >@45@0

   for(int h_4=accTotal1-1;h_4>=0;h_4--)

      if(OrderSelect(h_4,SELECT_BY_POS,MODE_HISTORY))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

              {

               if(OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT) {last_limit_price=OrderOpenPrice(); OP_TYPE_LIMIT=OrderType(); break;}

              }

   double last_stop_price=0; // F5=0 >B:@KB8O ?>A;54=53> C40;5==>3> ;8<8B=>3> >@45@0

   int OP_TYPE_STOPS=-1; // B8? ?>A;54=53> C40;5==>3> ;8<8B=>3> >@45@0

   for(int h_5=accTotal1-1;h_5>=0;h_5--)

      if(OrderSelect(h_5,SELECT_BY_POS,MODE_HISTORY))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

              {

               if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP) {last_stop_price=OrderOpenPrice(); OP_TYPE_STOPS=OrderType(); break;}

              }



//-------------------;>B------------------

   double sl = NormalizeDouble(SL*Point,Digits);

   double tp = NormalizeDouble(TP*Point,Digits);





   double lots_step=MarketInfo(Symbol(),MODE_LOTSTEP);

   int lots_digits = 0;

   if(lots_step==0.01) {lots_digits=2;}

   if(lots_step==0.1)  {lots_digits=1;}

   if(lots_step==1.0)  {lots_digits=0;}



   double Lot=0;

   if((last_profit>=0) || (loss>=Limit)) {Lot=Lots;}

   if(MegaLot==true && last_profit<0 && tp/Point*h_Lot *MarketInfo(Symbol(),MODE_TICKVALUE)<=MathAbs(loss_profit) && loss<Limit) {Lot=NormalizeDouble(((MathAbs(loss_profit)+TP*Lots*MarketInfo(Symbol(),MODE_TICKVALUE))/tp*Point/MarketInfo(Symbol(),MODE_TICKVALUE)),2); }

   if(MegaLot==false && last_profit<0 && tp/Point*h_Lot *MarketInfo(Symbol(),MODE_TICKVALUE)<=MathAbs(loss_profit) && loss<Limit) {Lot=NormalizeDouble(((MathAbs(loss_profit))/tp*Point/MarketInfo(Symbol(),MODE_TICKVALUE)),2); }



   if(last_profit<0 && tp/Point*h_Lot *MarketInfo(Symbol(),MODE_TICKVALUE)>MathAbs(loss_profit) && loss<Limit) {Lot=h_Lot; }



   double lots_test=Lot;

   lots_test=NormalizeDouble(MathCeil((lots_test)/lots_step)*lots_step,lots_digits);

   if(lots_test<Lot) {Lot=Lots;}



   if(Martin==false) {Lot=Lots;}

   if(Lot<MarketInfo(Symbol(),MODE_MINLOT)) {Lot=MarketInfo(Symbol(),MODE_MINLOT);}

   if(Lot>MarketInfo(Symbol(),MODE_MAXLOT)) {Lot=MarketInfo(Symbol(),MODE_MAXLOT);}



   bool open_buy=true,open_sell=true;

   if(AccountFreeMarginCheck(Symbol(),OP_BUY,Lot)<=0) {Lot=Lots;}

   if(AccountFreeMarginCheck(Symbol(),OP_SELL,Lot)<=0) {Lot=Lots;}



   if(AccountFreeMarginCheck(Symbol(),OP_BUY,Lot)<=0) {open_buy=false;}

   if(AccountFreeMarginCheck(Symbol(),OP_SELL,Lot)<=0) {open_sell=false;}



   if(open_buy==false || open_sell==false) {Comment("Not enough money to open a lot buy=",DoubleToStr(Lot,2)," or lot sell=",DoubleToStr(Lot,2));}

//--------------



   double step=NormalizeDouble(Step*Point,Digits);

   double step_interval=NormalizeDouble(Step_Interval*Point,Digits);

   double stops=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;



   double TS=NormalizeDouble(TrailingStop*Point,Digits);

   double shag=NormalizeDouble(TrailingStep*Point,Digits);

   double sl_Plus=NormalizeDouble(SL_Plus*Point,Digits);

   double profit_level=NormalizeDouble(Profit_Level*Point,Digits);

   double profit_level_tr=NormalizeDouble(Profit_Level_Trailing*Point,Digits);



if (sl<stops) {sl=stops;}

if (tp<stops) {tp=stops;}

if (step<stops) {step = stops;}



   int b=0,s=0,n=0,blimit=0,slimit=0,bs=0,ss=0,total=OrdersTotal();

   for(int i1=total-1; i1>=0; i1--)

      if(OrderSelect(i1,SELECT_BY_POS))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

              {

               if(OrderType()==OP_BUY)

                 {

                  b++;n++;



                  if(SL>0 && TP>0 && OrderStopLoss()==0 && Bid>NormalizeDouble(OrderOpenPrice()-sl+stops,Digits) && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-sl,Digits)

                     && OrderTakeProfit()==0 && Ask<NormalizeDouble(OrderOpenPrice()+tp-stops,Digits) && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl,Digits),NormalizeDouble(OrderOpenPrice()+tp,Digits),0,0);if(!mod) Print("Error modification block 1=",GetLastError());}



                  if(SL>0 && OrderStopLoss()==0 && Bid>NormalizeDouble(OrderOpenPrice()-sl+stops,Digits) && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-sl,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 2=",GetLastError());}

                  if(SL>0 && OrderStopLoss()==0 && Bid<NormalizeDouble(OrderOpenPrice()-sl+stops,Digits) && OrderStopLoss()!=NormalizeDouble(Bid-stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-stops,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 3=",GetLastError());}



                  if(TP>0 && OrderTakeProfit()==0 && Ask<NormalizeDouble(OrderOpenPrice()+tp-stops,Digits) && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+tp,Digits),0,0);if(!mod) Print("Error modification block 4=",GetLastError());}



                  if(TP>0 && OrderTakeProfit()==0 && Ask>NormalizeDouble(OrderOpenPrice()+tp-stops,Digits) && OrderTakeProfit()!=NormalizeDouble(Ask+stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Ask+stops,Digits),0,0);if(!mod) Print("Error modification block 5=",GetLastError());}

                  //---

                  if(last_profit>=0 && Trailing_Use==true && Bid>NormalizeDouble(Ask-TS+stops,Digits) && Ask-OrderStopLoss()>=TS && Bid-OrderOpenPrice()>=profit_level_tr && 

                     (Ask-TS)-OrderStopLoss()>=shag && OrderStopLoss()!=NormalizeDouble(Ask-TS,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask-TS,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 6=",GetLastError());}

                  if(last_profit>=0 && Breakeven_Use==true && Bid>=NormalizeDouble(OrderOpenPrice()+profit_level,Digits) && Bid>NormalizeDouble(OrderOpenPrice()+sl_Plus+stops,Digits)

                     && NormalizeDouble(OrderOpenPrice()+sl_Plus,Digits)>OrderStopLoss()

                     && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+sl_Plus,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl_Plus,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 7=",GetLastError());}



                 }

               if(OrderType()==OP_SELL)

                 {

                  s++;n++;

                  if(SL>0 && TP>0 && OrderStopLoss()==0 && Ask<NormalizeDouble(OrderOpenPrice()+sl-stops,Digits) && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+sl,Digits)

                     && OrderTakeProfit()==0 && Bid>NormalizeDouble(OrderOpenPrice()-tp+stops,Digits) && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl,Digits),NormalizeDouble(OrderOpenPrice()-tp,Digits),0,0);if(!mod) Print("Error modification block 6=",GetLastError());}



                  if(SL>0 && OrderStopLoss()==0 && Ask<NormalizeDouble(OrderOpenPrice()+sl-stops,Digits) && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+sl,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 7=",GetLastError());}

                  if(SL>0 && OrderStopLoss()==0 && Ask>NormalizeDouble(OrderOpenPrice()+sl-stops,Digits) && OrderStopLoss()!=NormalizeDouble(Ask+stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+stops,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 8=",GetLastError());}

                  if(TP>0 && OrderTakeProfit()==0 && Bid>NormalizeDouble(OrderOpenPrice()-tp+stops,Digits) && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-tp,Digits),0,0);if(!mod) Print("Error modification block 9=",GetLastError());}

                  if(TP>0 && OrderTakeProfit()==0 && Bid<NormalizeDouble(OrderOpenPrice()-tp+stops,Digits) && OrderTakeProfit()!=NormalizeDouble(Bid-stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Bid-stops,Digits),0,0);if(!mod) Print("Error modification block 10=",GetLastError());}

                  //----

                  if(last_profit>=0 && Trailing_Use==true && OrderStopLoss()>0 && Bid<NormalizeDouble(Bid+TS-stops,Digits) && OrderStopLoss()-Bid>=TS && OrderOpenPrice()-Ask>=profit_level_tr && 

                     OrderStopLoss()-(Bid+TS)>=shag && OrderStopLoss()!=NormalizeDouble(Bid+TS,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid+TS,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 13=",GetLastError());}



                  if(last_profit>=0 && Trailing_Use==true && OrderStopLoss()==0 && Bid<NormalizeDouble(Bid+TS-stops,Digits) && OrderOpenPrice()-Ask>=profit_level_tr && OrderStopLoss()!=NormalizeDouble(Bid+TS,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid+TS,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 14=",GetLastError());}



                  if(last_profit>=0 && Breakeven_Use==true && OrderStopLoss()>0 && Ask<=NormalizeDouble(OrderOpenPrice()-profit_level,Digits) && Ask<NormalizeDouble(OrderOpenPrice()-sl_Plus-stops,Digits)

                     && NormalizeDouble(OrderOpenPrice()-sl_Plus,Digits)<OrderStopLoss()

                     && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-sl_Plus,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl_Plus,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 15=",GetLastError());}

                  if(last_profit>=0 && Breakeven_Use==true && OrderStopLoss()==0 && Ask<=NormalizeDouble(OrderOpenPrice()-profit_level,Digits) && Ask<NormalizeDouble(OrderOpenPrice()-sl_Plus-stops,Digits)

                     && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-sl_Plus,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl_Plus,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 16=",GetLastError());}



                 }

               if(OrderType()==OP_BUYLIMIT)

                 {

                  blimit++;



                  if(SL>0 && TP>0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),NormalizeDouble(Bid-step-sl,Digits),NormalizeDouble(Bid-step+tp,Digits),0,0);if(!mod) Print("Error modification block 11=",GetLastError());}

                  if(SL>0 && TP==0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),NormalizeDouble(Bid-step-sl,Digits),0,0,0);if(!mod) Print("Error modification block 12=",GetLastError());}

                  if(SL==0 && TP>0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),0,NormalizeDouble(Bid-step+tp,Digits),0,0);if(!mod) Print("Error modification block 13=",GetLastError());}

                  if(SL==0 && TP==0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),0,0,0,0);if(!mod) Print("Error modification=",GetLastError());}



                  if(SL>0 && sl>stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-sl,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 14=",GetLastError());}

                  if(SL>0 && sl<=stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-stops,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 15=",GetLastError());}



                  if(TP>0 && tp>stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+tp,Digits),0,0);if(!mod) Print("Error modification block 16=",GetLastError());}

                  if(TP>0 && tp<=stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+stops,Digits),0,0);if(!mod) Print("Error modification block 17=",GetLastError());}

                 }

               if(OrderType()==OP_SELLLIMIT)

                 {

                  slimit++;

                  if(SL>0 && TP>0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),NormalizeDouble(Ask+step+sl,Digits),NormalizeDouble(Ask+step-tp,Digits),0,0);if(!mod) Print("Error modification 18",GetLastError());}

                  if(SL>0 && TP==0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),NormalizeDouble(Ask+step+sl,Digits),0,0,0);if(!mod) Print("Error modification block 19=",GetLastError());}

                  if(SL==0 && TP>0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),0,NormalizeDouble(Ask+step-tp,Digits),0,0);if(!mod) Print("Error modification block 20=",GetLastError());}

                  if(SL==0 && TP==0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),0,0,0,0);if(!mod) Print("Error modification block 27=",GetLastError());}



                  if(SL>0 && sl>stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+sl,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 21=",GetLastError());}

                  if(SL>0 && sl<=stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+stops,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 22=",GetLastError());}



                  if(TP>0 && tp>stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-tp,Digits),0,0);if(!mod) Print("Error modification block 23=",GetLastError());}

                  if(TP>0 && tp<=stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-stops,Digits),0,0);if(!mod) Print("Error modification block 24=",GetLastError());}

                 }

               if(OrderType()==OP_BUYSTOP)

                 {

                  bs++;



                  if(SL>0 && TP>0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),NormalizeDouble(Ask+step-sl,Digits),NormalizeDouble(Ask+step+tp,Digits),0,0);if(!mod) Print("Error modification block 11=",GetLastError());}

                  if(SL>0 && TP==0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),NormalizeDouble(Ask+step-sl,Digits),0,0,0);if(!mod) Print("Error modification block 12=",GetLastError());}

                  if(SL==0 && TP>0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),0,NormalizeDouble(Ask+step+tp,Digits),0,0);if(!mod) Print("Error modification block 13=",GetLastError());}

                  if(SL==0 && TP==0 && OrderOpenPrice()-Ask>step && OrderOpenPrice()-(Ask+step)>step_interval && OrderOpenPrice()!=NormalizeDouble(Ask+step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Ask+step,Digits),0,0,0,0);if(!mod) Print("Error modification=",GetLastError());}



                  if(SL>0 && sl>stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-sl,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 14=",GetLastError());}

                  if(SL>0 && sl<=stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-stops,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 15=",GetLastError());}



                  if(TP>0 && tp>stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+tp,Digits),0,0);if(!mod) Print("Error modification block 16=",GetLastError());}

                  if(TP>0 && tp<=stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+stops,Digits),0,0);if(!mod) Print("Error modification block 17=",GetLastError());}

                 }

               if(OrderType()==OP_SELLSTOP)

                 {

                  ss++;

                  if(SL>0 && TP>0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),NormalizeDouble(Bid-step+sl,Digits),NormalizeDouble(Bid-step-tp,Digits),0,0);if(!mod) Print("Error modification 18",GetLastError());}

                  if(SL>0 && TP==0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),NormalizeDouble(Bid-step+sl,Digits),0,0,0);if(!mod) Print("Error modification block 19=",GetLastError());}

                  if(SL==0 && TP>0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),0,NormalizeDouble(Bid-step-tp,Digits),0,0);if(!mod) Print("Error modification block 20=",GetLastError());}

                  if(SL==0 && TP==0 && Bid-OrderOpenPrice()>step && (Bid-step)-OrderOpenPrice()>step_interval && OrderOpenPrice()!=NormalizeDouble(Bid-step,Digits))

                    {bool mod=OrderModify(OrderTicket(),NormalizeDouble(Bid-step,Digits),0,0,0,0);if(!mod) Print("Error modification block 27=",GetLastError());}



                  if(SL>0 && sl>stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+sl,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 21=",GetLastError());}

                  if(SL>0 && sl<=stops && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+stops,Digits),OrderTakeProfit(),0,0);if(!mod) Print("Error modification block 22=",GetLastError());}



                  if(TP>0 && tp>stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-tp,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-tp,Digits),0,0);if(!mod) Print("Error modification block 23=",GetLastError());}

                  if(TP>0 && tp<=stops && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-stops,Digits))

                    {bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-stops,Digits),0,0);if(!mod) Print("Error modification block 24=",GetLastError());}

                 }



              }



   double buylimit_open=0,selllimit_open=0;

   int sig_slimit=0,sig_blimit=0;

   if(n==0&&blimit==0&&step>stops&&Last_Price_Limit_Use==false) {buylimit_open=NormalizeDouble(Bid-step,Digits);sig_blimit=1; }

   if(n==0&&slimit==0&&step>stops&&Last_Price_Limit_Use==false) {selllimit_open=NormalizeDouble(Ask+step,Digits);sig_slimit=1;}

   if(n==0&&blimit==0&&step<=stops&&Last_Price_Limit_Use==false) {buylimit_open=NormalizeDouble(Bid-stops,Digits);sig_blimit=1; }

   if(n==0&&slimit==0&&step<=stops&&Last_Price_Limit_Use==false) {selllimit_open=NormalizeDouble(Ask+stops,Digits);sig_slimit=1;}





   if(n==0 && blimit==0 && OP_TYPE_LIMIT==OP_BUYLIMIT && Bid>=last_limit_price+stops && Last_Price_Limit_Use==true) {buylimit_open=NormalizeDouble(last_limit_price,Digits);sig_blimit=1; }

   if(n==0 && blimit==0 && OP_TYPE_LIMIT!=OP_BUYLIMIT && Bid>=Bid-step+stops && Last_Price_Limit_Use==true) {buylimit_open=NormalizeDouble(Bid-step,Digits);sig_blimit=1; }

   if(n==0&&blimit==0&&OP_TYPE_LIMIT==OP_BUYLIMIT&&Bid<=last_limit_price+stops&&Last_Price_Limit_Use==true) {buylimit_open=NormalizeDouble(Bid-stops,Digits);sig_blimit=1; }

   if(n==0 && blimit==0 && OP_TYPE_LIMIT!=OP_BUYLIMIT && Bid<=Bid-step+stops && Last_Price_Limit_Use==true) {buylimit_open=NormalizeDouble(Bid-stops,Digits);sig_blimit=1; }



   if(n==0 && slimit==0 && OP_TYPE_LIMIT==OP_SELLLIMIT && Ask<=last_limit_price-stops && Last_Price_Limit_Use==true) {selllimit_open=NormalizeDouble(last_limit_price,Digits);sig_slimit=1; }

   if(n==0 && slimit==0 && OP_TYPE_LIMIT!=OP_SELLLIMIT && Ask<=Ask+step-stops && Last_Price_Limit_Use==true) {selllimit_open=NormalizeDouble(Ask+step,Digits);sig_slimit=1; }

   if(n==0&&slimit==0&&OP_TYPE_LIMIT==OP_SELLLIMIT&&Ask>=last_limit_price-stops&&Last_Price_Limit_Use==true) {selllimit_open=NormalizeDouble(Ask+stops,Digits);sig_slimit=1; }

   if(n==0 && slimit==0 && OP_TYPE_LIMIT!=OP_SELLLIMIT && Ask>=Ask+step-stops && Last_Price_Limit_Use==true) {selllimit_open=NormalizeDouble(Ask+stops,Digits);sig_slimit=1; }



   if(Sell==true&&sig_slimit==1 && open_sell==true && Limits0_or_Stops1==0) {int open=OrderSend(Symbol(),OP_SELLLIMIT,Lot,selllimit_open,Slip,0,0,NULL,Magic,0,Red);if(open>0) {return;} if(open<0) {Print("OrderSend failed #",GetLastError());return;}}

   if(Buy==true&&sig_blimit==1 && open_buy==true && Limits0_or_Stops1==0) {int open=OrderSend(Symbol(),OP_BUYLIMIT,Lot,buylimit_open,Slip,0,0,NULL,Magic,0,Blue);if(open>0) {return;} if(open<0) {Print("OrderSend failed #",GetLastError());return;}}



   double buystop_open=0,sellstop_open=0;

   int sig_bstop=0,sig_sstop=0;

   if(n==0&&bs==0&&step>stops&&Last_Price_Stops_Use==false) {buystop_open=NormalizeDouble(Ask+step,Digits);sig_bstop=1; }

   if(n==0&&ss==0&&step>stops&&Last_Price_Stops_Use==false) {sellstop_open=NormalizeDouble(Bid-step,Digits);sig_sstop=1;}

   if(n==0&&bs==0&&step<=stops&&Last_Price_Stops_Use==false) {buystop_open=NormalizeDouble(Ask+stops,Digits);sig_bstop=1; }

   if(n==0&&ss==0&&step<=stops&&Last_Price_Stops_Use==false) {sellstop_open=NormalizeDouble(Bid-stops,Digits);sig_sstop=1;}





   if(n==0 && bs==0 && OP_TYPE_STOPS==OP_BUYSTOP && Ask<=last_stop_price-stops && Last_Price_Stops_Use==true) {buystop_open=NormalizeDouble(last_stop_price,Digits);sig_bstop=1; }

   if(n==0 && bs==0 && OP_TYPE_STOPS!=OP_BUYSTOP && Ask<=Ask+step-stops && Last_Price_Stops_Use==true) {buystop_open=NormalizeDouble(Ask+step,Digits);sig_bstop=1; }

   if(n==0 && bs==0 && OP_TYPE_STOPS==OP_BUYSTOP && Ask>=last_stop_price+stops && Last_Price_Stops_Use==true) {buystop_open=NormalizeDouble(Ask+stops,Digits);sig_bstop=1; }

   if(n==0 && bs==0 && OP_TYPE_STOPS!=OP_BUYSTOP && Ask>=Ask+step-stops && Last_Price_Stops_Use==true) {buystop_open=NormalizeDouble(Ask+stops,Digits);sig_bstop=1; }



   if(n==0 && ss==0 && OP_TYPE_STOPS==OP_SELLSTOP && Bid>=last_stop_price+stops && Last_Price_Stops_Use==true) {sellstop_open=NormalizeDouble(last_stop_price,Digits);sig_sstop=1; }

   if(n==0 && ss==0 && OP_TYPE_STOPS!=OP_SELLSTOP && Bid>=Bid-step+stops && Last_Price_Stops_Use==true) {sellstop_open=NormalizeDouble(Bid-step,Digits);sig_sstop=1; }

   if(n==0 && ss==0 && OP_TYPE_STOPS==OP_SELLSTOP && Bid<=last_stop_price+stops && Last_Price_Stops_Use==true) {sellstop_open=NormalizeDouble(Bid-stops,Digits);sig_sstop=1; }

   if(n==0 && ss==0 && OP_TYPE_STOPS!=OP_SELLSTOP && Bid<=Bid-step+stops && Last_Price_Stops_Use==true) {sellstop_open=NormalizeDouble(Bid-stops,Digits);sig_sstop=1; }



   if(Sell==true&&sig_sstop==1 && open_sell==true && Limits0_or_Stops1==1) {int open=OrderSend(Symbol(),OP_SELLSTOP,Lot,sellstop_open,Slip,0,0,NULL,Magic,0,Red);if(open>0) {return;} if(open<0) {Print("OrderSend failed #",GetLastError());return;}}

   if(Buy==true&&sig_bstop==1 && open_buy==true && Limits0_or_Stops1==1) {int open=OrderSend(Symbol(),OP_BUYSTOP,Lot,buystop_open,Slip,0,0,NULL,Magic,0,Blue);if(open>0) {return;} if(open<0) {Print("OrderSend failed #",GetLastError());return;}}



   for(int lim_del=total-1; lim_del>=0; lim_del--)

      if(OrderSelect(lim_del,SELECT_BY_POS))

         if(OrderSymbol()==Symbol())

            if(OrderMagicNumber()==Magic)

               if(OrderType()>1)

                 {

                  if(n>0) {int cl=OrderDelete(OrderTicket());} // C40;O5< >B;>6:C ?@8 ?>O2;5=88 @K=>G=>3> >@45@0

                 }



  }

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

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 ---