EA RSI Martin_AntiMartin v.17.07

Author: Copyright © 2023, R0MAN
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reachedChecks for the total of closed orders
Indicators Used
Relative strength index
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
EA RSI Martin_AntiMartin v.17.07
ÿþ//+------------------------------------------------------------------+

#property copyright "Copyright © 2023, R0MAN"

#property link      "rshiredchenko@mail.ru"

#property strict

#property description "0@80=BK 8A?>;L7>20=8O A  ?> 0@B8=C 8;8 =B80@B8=C"

#property description "!>25B=8: >B:@K205B ?>78F88 AB0@B>2K5 ?> 8=48:0B>@C RSI, ?>A;5 "  C25;8G8205B ;>B ?@8 =B8-0@B8=5 "

#property description "?@8  ?> 0@B8=359;C ?>A;5 ! C25;8G8205B ;>B =0 :>MDD8F85=B"

#property description "2KAB02;O5BAO SL, TP, :>;-2> C25;8G5=89 ;>B, :>MDD8F85=B C25;8F5=89 ;>B0"

#property description "!;54CNI0O A45;:0 =5 >B:@K205BAO, ?>:0 =5 70:@KB0 ?@54K4CI0O"

//

//

//

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



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

//|                                                                  |

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

extern bool   Martin       = false; // " : <0@B8=/0=B8-<0@B8=,  <0@B8= (C25;8G5=85 =0 K_Martin ?@8 ;>AA5)/ ?> 0=B8-<0@B8=C (C25;8G5=85 =0 K_Martin ?@8 ?@>D8B5)

extern ENUM_TIMEFRAMES timeframe_RSI = 15;

extern int    period_RSI   = 14;

extern int    level_buy    = 30;

extern int    level_sell   = 70;



extern double Lot          = 0.1;

extern double K_Martin     = 2.0;

extern int    :>;8G5AB2>   = 3;     // :>;-2> C25;8G5=89 ;>B



extern int    Stoploss     = 200,

              Takeprofit   = 220;



extern int    Magic        = 0;

extern int    DigitsLot    = 2;

extern int    slippage     = 3;

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

string AC;

datetime OpenTime;

double MINLOT,MAXLOT;

double maprice = 0;

static datetime prevtime = 0, prevtime_tral = 0;       // ?> F5=0< >B:@KB8O

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

//----

double lots_step;

//----

int ticket_buy;

int ticket_sell;

int lots_digits;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   MINLOT = MarketInfo(Symbol(),MODE_MINLOT);

   MAXLOT = MarketInfo(Symbol(),MODE_MAXLOT);

   Comment("Start ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));



   AC = StringConcatenate(" ", AccountCurrency());



   int Y=15;

   DrawLABEL("">@3>2;O",1,5,Y,Red,"">@3>2;O ");

   Y += 20;

   DrawLABEL("Balance",1,5,Y,clrGreen,StringConcatenate("Balance ",DoubleToStr(AccountBalance(),2),AC));

   Y += 15;

   DrawLABEL("Equity",1,5,Y,clrGreen,StringConcatenate("Equity ",DoubleToStr(AccountEquity(),2),AC));

   Y += 15;

   DrawLABEL("FreeMargin",1,5,Y,clrGreen,StringConcatenate("FreeMargin ",DoubleToStr(AccountFreeMargin(),2),AC));

   Y += 30;



   DrawLABEL("Take",1,5,Y,Lime,"Profit ");

   Y += 20;



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

   ticket_buy=-1;

   ticket_sell=-1;

//----

   lots_step=MarketInfo(Symbol(),MODE_LOTSTEP);

//----

   if(lots_step==0.01)

      lots_digits=2;

//----

   if(lots_step==0.1)

      lots_digits=1;

//----

   if(lots_step==1.0)

      lots_digits=0;

//---

   Print("Symbol=",Symbol());

   Print(" BID = ",NormalizeDouble(Bid,Digits), " ASK = ", NormalizeDouble(Ask,Digits));

   Print(" MINLOT  = ", MarketInfo(Symbol(),MODE_MINLOT), " lots_step = ", lots_step," MAXLOT  = ", MarketInfo(Symbol(),MODE_MAXLOT));

   Print(" STOPLEVEL = ", MarketInfo(Symbol(),MODE_STOPLEVEL)," !?@54  = ", MarketInfo(Symbol(),MODE_SPREAD));

   Print(" DIGITS  = ", MarketInfo(Symbol(),MODE_DIGITS), " POINT  = ", MarketInfo(Symbol(),MODE_POINT));

   Print(" LOTSIZE  = ", MarketInfo(Symbol(),MODE_LOTSIZE), " TICKVALUE = ", MarketInfo(Symbol(),MODE_TICKVALUE),

         " TICKSIZE  = ", MarketInfo(Symbol(),MODE_TICKSIZE));



   Print("8=8<0;L=0O 4=52=0O F5=0=",MarketInfo(Symbol(),MODE_LOW));

   Print("0:A8<0;L=0O 4=52=0O F5=0=",MarketInfo(Symbol(),MODE_HIGH));

   Print("@5<O ?>ABC?;5=8O ?>A;54=59 :>B8@>2:8=",(MarketInfo(Symbol(),MODE_TIME)));

   Print(">A;54=OO ?>ABC?82H0O F5=0 ?@54;>65=8O=",MarketInfo(Symbol(),MODE_BID));

   Print(">A;54=OO ?>ABC?82H0O F5=0 ?@>4068=",MarketInfo(Symbol(),MODE_ASK));

   Print(" 07<5@ ?C=:B0 2 20;NB5 :>B8@>2:8=",MarketInfo(Symbol(),MODE_POINT));

   Print(">;8G5AB2> F8D@ ?>A;5 70?OB>9 2 F5=5 8=AB@C<5=B0=",MarketInfo(Symbol(),MODE_DIGITS));

   Print("!?@M4 2 ?C=:B0E=",MarketInfo(Symbol(),MODE_SPREAD));

   Print("8=8<0;L=> 4>?CAB8<K9 C@>25=L AB>?-;>AA0/B59:-?@>D8B0 2 ?C=:B0E=",MarketInfo(Symbol(),MODE_STOPLEVEL));

   Print(" 07<5@ :>=B@0:B0 2 107>2>9 20;NB5 8=AB@C<5=B0=",MarketInfo(Symbol(),MODE_LOTSIZE));

   Print(" 07<5@ <8=8<0;L=>3> 87<5=5=8O F5=K 8=AB@C<5=B0 2 20;NB5 45?>78B0=",MarketInfo(Symbol(),MODE_TICKVALUE));

   Print("8=8<0;L=K9 H03 87<5=5=8O F5=K 8=AB@C<5=B0 2 ?C=:B0E=",MarketInfo(Symbol(),MODE_TICKSIZE));

   Print(" 07<5@ A2>?0 4;O >@45@>2 =0 ?>:C?:C=",MarketInfo(Symbol(),MODE_SWAPLONG));

   Print(" 07<5@ A2>?0 4;O >@45@>2 =0 ?@>406C=",MarketInfo(Symbol(),MODE_SWAPSHORT));

   Print("0;5=40@=0O 40B0 =0G0;0 B>@3>2 (DLNG5@AK)=",MarketInfo(Symbol(),MODE_STARTING));

   Print("0;5=40@=0O 40B0 >:>=G0=8O B>@3>2 (DLNG5@AK)=",MarketInfo(Symbol(),MODE_EXPIRATION));

   Print(" 07@5H5=85 B>@3>2 ?> C:070==><C 8=AB@C<5=BC=",MarketInfo(Symbol(),MODE_TRADEALLOWED));

   Print("8=8<0;L=K9 @07<5@ ;>B0=",MarketInfo(Symbol(),MODE_MINLOT));

   Print("(03 87<5=5=8O @07<5@0 ;>B0=",MarketInfo(Symbol(),MODE_LOTSTEP));

   Print("0:A8<0;L=K9 @07<5@ ;>B0=",MarketInfo(Symbol(),MODE_MAXLOT));

   Print("5B>4 2KG8A;5=8O A2>?>2=",MarketInfo(Symbol(),MODE_SWAPTYPE));

   Print("!?>A>1 @0AG5B0 ?@81K;8=",MarketInfo(Symbol(),MODE_PROFITCALCMODE));

   Print("!?>A>1 @0AG5B0 70;>3>2KE A@54AB2=",MarketInfo(Symbol(),MODE_MARGINCALCMODE));

   Print("0G0;L=K5 70;>3>2K5 B@51>20=8O 4;O 1 ;>B0=",MarketInfo(Symbol(),MODE_MARGININIT));

   Print(" 07<5@ 70;>3>2KE A@54AB2 4;O ?>445@6:8 >B:@KBKE >@45@>2 2 @0AG5B5 =0 1 ;>B=",MarketInfo(Symbol(),MODE_MARGINMAINTENANCE));

   Print("0@60, 278<05<0O A ?5@5:@KBKE >@45@>2 2 @0AG5B5 =0 1 ;>B=",MarketInfo(Symbol(),MODE_MARGINHEDGED));

   Print(" 07<5@ A2>1>4=KE A@54AB2, =5>1E>48<KE 4;O >B:@KB8O 1 ;>B0 =0 ?>:C?:C=",MarketInfo(Symbol(),MODE_MARGINREQUIRED));

   Print("#@>25=L 70<>@>7:8 >@45@>2 2 ?C=:B0E=",MarketInfo(Symbol(),MODE_FREEZELEVEL));



//---------------------     %"+"   &     # "      ---------------------------------------------------

   for(int pos=OrdersTotal()-1; pos>=0; pos--)

      if(OrderSelect(pos,SELECT_BY_POS)==true)

         if(OrderMagicNumber()==Magic)

            if(OrderSymbol()==Symbol())

              {

               if(OrderType()==OP_BUY)

                 {

                  ticket_buy=OrderTicket();

                  break;

                 }

               //----

               if(OrderType()==OP_SELL)

                 {

                  ticket_sell=OrderTicket();

                  break;

                 }

              }

//----

   return(INIT_SUCCEEDED);

  }





//void OnTick()

int start()

  {

   int i;

   if(iTime(Symbol(),0,0) == prevtime)

      return(0);            //645< =>2>3> 10@0 =0 B5:CI5< B09<D@59<5

   prevtime = iTime(Symbol(),0,0);





   if(!IsTradeAllowed())

     {

      DrawLABEL("">@3>2;O",0,0,0,Red,"">@3>2;O 70?@5I5=0");

      return(0);

     }

   else

      DrawLABEL("">@3>2;O",0,0,0,Lime,"">@3>2;O @07@5H5=0");



//---



   double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);

//---

   double OSL,OTP,OOP,SL,TP,Profit=0;

   int b=0,s=0,tip;

   double Lots=0,RSI1=0,RSI0=0;



// @0AG5B 7=0G5=89 8=48:0B>@>2

   RSI0= iRSI(NULL,timeframe_RSI,period_RSI,PRICE_CLOSE,0);

   RSI1= iRSI(NULL,timeframe_RSI,period_RSI,PRICE_CLOSE,2);



//  Print(" BID = ",NormalizeDouble(Bid,Digits), " ASK = ", NormalizeDouble(Ask,Digits));



// -----------------------------   <>48D8:0F8O ! 8 "      ------------------------------------



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

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

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

           {

            tip = OrderType();

            OSL = NormalizeDouble(OrderStopLoss(),Digits);

            OTP = NormalizeDouble(OrderTakeProfit(),Digits);

            OOP = NormalizeDouble(OrderOpenPrice(),Digits);

            SL=OSL;

            TP=OTP;

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

            if(tip==OP_BUY)

              {

               b++;

               if(OSL==0 && Stoploss!=0)

                 {

                  if((Bid-NormalizeDouble(OOP - (Stoploss + MarketInfo(Symbol(),MODE_SPREAD))* Point,Digits)) / Point >= STOPLEVEL)

                     SL = NormalizeDouble(OOP - (Stoploss + MarketInfo(Symbol(),MODE_SPREAD)) * Point,Digits);

                  else

                     SL = NormalizeDouble(OOP - STOPLEVEL*Point,Digits);



                 }

               if(OTP==0 && Takeprofit!=0)

                 {

                  if((NormalizeDouble(OOP + Takeprofit* Point,Digits) - Ask) / Point >= STOPLEVEL)

                     TP = NormalizeDouble(OOP + Takeprofit * Point,Digits);

                  else

                     TP = NormalizeDouble(OOP + STOPLEVEL*Point,Digits);

                 }



               if(SL != OSL || TP != OTP)

                 {

                  Print(" SL = ",NormalizeDouble(SL,Digits), " TP = ", NormalizeDouble(TP,Digits));

                  if(!OrderModify(OrderTicket(),OOP,SL,TP,0,clrAliceBlue))

                     Print("Error OrderModify ",GetLastError());

                 }

              }

            if(tip==OP_SELL)

              {

               s++;

               if(OSL==0 && Stoploss!=0)

                 {

                  if((NormalizeDouble(OOP + Stoploss * Point,Digits) - Ask) / Point >= STOPLEVEL)

                     SL = NormalizeDouble(OOP + Stoploss*Point,Digits);

                  else

                     SL = NormalizeDouble(OOP + STOPLEVEL*Point,Digits);

                  //SL = NormalizeDouble(OOP + (STOPLEVEL + Stoploss) * Point,Digits);

                 }



               if(OTP==0 && Takeprofit!=0)

                 {

                  if((Bid-NormalizeDouble(OOP - Takeprofit*Point,Digits)) / Point >= STOPLEVEL)

                     TP = NormalizeDouble(OOP - Takeprofit*Point,Digits);

                  else

                     TP = NormalizeDouble(OOP - STOPLEVEL*Point,Digits);

                  //TP = NormalizeDouble(OOP - (Takeprofit + STOPLEVEL)*Point,Digits);



                 }

               if(SL != OSL || TP != OTP)

                 {

                  Print(" SL = ",NormalizeDouble(SL,Digits), " TP = ", NormalizeDouble(TP,Digits));

                  if(!OrderModify(OrderTicket(),OOP,SL,TP,0,clrLightPink))

                     Print("Error OrderModify ",GetLastError());

                 }

              }

           }

        }

     }



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



//--------------------------      0745; 8=D>@<0F8>==KE A>>1I5=89        ---------------------------------------------------------



   double AB = AccountBalance();

//---

   DrawLABEL("Balance",1,5,0,clrGreen,StringConcatenate("Balance ",DoubleToStr(AB,2),AC));

   DrawLABEL("Equity",1,5,0,clrGreen,StringConcatenate("Equity ",DoubleToStr(AccountEquity(),2),AC));

   DrawLABEL("FreeMargin",1,5,0,clrGreen,StringConcatenate("FreeMargin ",DoubleToStr(AccountFreeMargin(),2),AC));

   DrawLABEL("Take",1,5,0,Color(Profit>0,Lime,Red),StringConcatenate("Profit ",DoubleToStr(Profit,2),AC));

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





   if(b+s > 0)  // :>340 5ABL ?>78F8O, 2KE>4 2 =0G0;>

     {

      return(0); //   ' & ,(  



     }







//----- @8 =B8-0@B8=5, 2E>40 =0 C25;8G5==KE >1J5<0E 2 ?@>4>;65=85 B5=45=F88, 5A;8 2 ?@>D8B 8 <5=LH5 ":>;8G5AB20", B> 2E>4 =0 C25;8G5==KE >1J5<0E

//---------------  2 =0?@02;5=88 ?@54K4CI59 ?@>D8B=>9 A45;:8

   if(!Martin)  // ?@8 0=B8-<0@B8=5 - ?> B@5=4C C25;8G8205< ;>B ?>A;5 "  ?@54K4CI59 A45;:8

      if(b+s==0)  // :>340 =5B ?>78F88

         if(Fresh_closed_at_a_profits())   // 5A;8 ?@54K4CI0O 70:@KB0 2 ?@>D8B. A;8 - 2 !! - B> AB0@BC5< ?>  ! =0G >1J5<><

           {

            Lots=LOT_Antimartin();

            if(Lots>MAXLOT)

               Lots = MAXLOT;

            if(Lots<MINLOT)

               Lots = MINLOT;



            // 2 109

            if(TYPE_OF_PREVIOUS_TRANSACTION() == 0)

               if(SendOrder(OP_BUY,Lots,NormalizeDouble(Ask,Digits),NormalizeDouble(Bid - Stoploss * Point,Digits),NormalizeDouble(Ask + Takeprofit * Point,Digits)))

                 {

                  Print(" OP_BUY 2 =0?@02;5=88 ?@54K4CI59 ?@>D8B=>9 A45;:8 ");

                  OpenTime=iTime(NULL,timeframe_RSI,1);

                  b++;

                 }



            // 2 A5;;

            if(TYPE_OF_PREVIOUS_TRANSACTION() == 1)

               if(SendOrder(OP_SELL,Lots,NormalizeDouble(Bid,Digits),NormalizeDouble(Ask + Stoploss * Point,Digits),NormalizeDouble(Bid - Takeprofit * Point,Digits)))

                 {

                  Print(" OP_SELL 2 =0?@02;5=88 ?@54K4CI59 ?@>D8B=>9 A45;:8 ");

                  OpenTime=iTime(NULL,timeframe_RSI,1);

                  s++;

                 }

           }

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





// ?@8 <0@B8=5 - ?5@52>@>B=>< - 2:;NG05<, :>340 ?@54K4CI0O 70:@KB0 2 ;>AA

   if(Martin)   // ?@8 <0@B8=5 - ?5@52>@>B=>< C25;8G8205< ;>B ?>A;5 ! ?@54K4CI59 A45;:8

      if(b+s==0)  // :>340 =5B ?>78F88

         if(!Fresh_closed_at_a_profits())   // 5A;8 ?@54K4CI0O 70:@KB0 2 !!. A;8 - 2 ?@>D8B - B> AB0@BC5< ?>  ! =0G >1J5<><

           {

            Lots=LOT_Martin();

            if(Lots>MAXLOT)

               Lots = MAXLOT;

            if(Lots<MINLOT)

               Lots = MINLOT;



            // 2 109

            if(TYPE_OF_PREVIOUS_TRANSACTION() == 1)

               if(SendOrder(OP_BUY,Lots,NormalizeDouble(Ask,Digits),NormalizeDouble(Bid - Stoploss * Point,Digits),NormalizeDouble(Ask + Takeprofit * Point,Digits)))

                 {

                  Print(" OP_BUY 2 ?5@52>@>B >B ?@54K4CI59 ;>AA>2>9 ! A45;:8 (?> =0?@02;5=8N B5=45=F88 225@E) ");

                  OpenTime=iTime(NULL,timeframe_RSI,1);

                  b++;

                 }



            // 2 A5;;

            if(TYPE_OF_PREVIOUS_TRANSACTION() == 0)

               if(SendOrder(OP_SELL,Lots,NormalizeDouble(Bid,Digits),NormalizeDouble(Ask + Stoploss * Point,Digits),NormalizeDouble(Bid - Takeprofit * Point,Digits)))

                 {

                  Print(" OP_SELL 2 ?5@52>@>B >B ?@54K4CI59 ;>AA>2>9 109 A45;:8 (?> =0?@02;5=8N B5=45=F88 2=87) ");

                  OpenTime=iTime(NULL,timeframe_RSI,1);

                  s++;

                 }

           }

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









   if(b+s==0)  // :>340 =5B ?>78F88

     {

      //---  !" " ?>  ! ---------------

      if(RSI0 >= level_buy && RSI1 <= level_buy)

        {

         Lots=Lot;

         if(Lots>MAXLOT)

            Lots = MAXLOT;

         if(Lots<MINLOT)

            Lots = MINLOT;

         Print(" !" " 2 109: RSI0 = ", RSI0, " RSI1 = ", RSI1);

         if(SendOrder(OP_BUY,Lots,NormalizeDouble(Ask,Digits),NormalizeDouble(Bid - Stoploss * Point,Digits),NormalizeDouble(Ask + Takeprofit * Point,Digits)))

            //if(SendOrder(OP_BUY,Lots,NormalizeDouble(Ask,Digits)))

            OpenTime=iTime(NULL,timeframe_RSI,1);

        }



      //---



      if(RSI0 <= level_sell && RSI1 >= level_sell)

        {

         Lots=Lot;

         if(Lots>MAXLOT)

            Lots = MAXLOT;

         if(Lots<MINLOT)

            Lots = MINLOT;

         Print(" !" " 2 A5;;: RSI0 = ", RSI0, " RSI1 = ", RSI1);

         if(SendOrder(OP_SELL,Lots,NormalizeDouble(Bid,Digits),NormalizeDouble(Ask + Stoploss * Point,Digits),NormalizeDouble(Bid - Takeprofit * Point,Digits)))

            OpenTime=iTime(NULL,timeframe_RSI,1);

        }

     } // :>= :  if (b+s==0) // :>340 =5B ?>78F88





   return(0);

  }

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

bool SendOrder(int tip, double lots, double price, double sl=0, double tp=0)

  {

   if(tip<2)

     {

      if(AccountFreeMarginCheck(Symbol(),tip,lots)<0)

        {

         Alert("54>AB0B>G=> A@54AB2");

         return(false);

        }

     }

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

     {

      if(tip == OP_BUY)

         if(OrderSend(Symbol(),tip, lots,price,slippage,sl,tp," 073>= ?> 0=B8<0@B8=C",Magic,0,clrBlue)!=-1)

            return(true);

      if(tip == OP_SELL)

         if(OrderSend(Symbol(),tip, lots,price,slippage,sl,tp," 073>= ?> 0=B8<0@B8=C",Magic,0,clrRed)!=-1)

            return(true);



      Alert(" ?>?KB:0 ",i," H81:0 >B:@KB8O >@45@0 ",Strtip(tip)," <<",(GetLastError()),">>  lot=",lots,"  pr=",price," sl=",sl," tp=",tp);

      Sleep(500);

      RefreshRates();

      if(IsStopped())

         return(false);

     }

   return(false);

  }

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

string Strtip(int tip)

  {

   switch(tip)

     {

      case OP_BUY:

         return("BUY");

      case OP_SELL:

         return("SELL");

      case OP_BUYSTOP:

         return("BUYSTOP");

      case OP_SELLSTOP:

         return("SELLSTOP");

      case OP_BUYLIMIT:

         return("BUYLIMIT");

      case OP_SELLLIMIT:

         return("SELLLIMIT");

     }

   return("error");

  }

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

void OnDeinit(const int reason)

  {

   if(!IsTesting())

     {

      ObjectsDeleteAll(0);

     }

  }

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

void DrawLABEL(string name, int CORNER, int X, int Y, color clr, string Name)

  {

   if(ObjectFind(name)==-1)

     {

      ObjectCreate(name, OBJ_LABEL, 0, 0, 0);

      ObjectSet(name, OBJPROP_CORNER, CORNER);

      ObjectSet(name, OBJPROP_XDISTANCE, X);

      ObjectSet(name, OBJPROP_YDISTANCE, Y);

     }

   ObjectSetText(name,Name,10,"Arial",clr);

  }

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



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

color Color(bool P,color a,color b)

  {

   if(P)

      return(a);

   else

      return(b);

  }



//------------------------      !'" * '  "   "- " (?@8 70:@KB>9 A25659 2 ?@>D8B ;>B C25;8G8205<)   ------------------------------------------

double LOT_Antimartin()

  {

   int n=0;

   int j;

   double OL = Lot;  //NormalizeDouble(AccountBalance()*LotPercent/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED),DigitsLot);

   if(OL>MAXLOT)

      OL = MAXLOT;

   if(OL<MINLOT)

      OL = MINLOT;



   for(j = OrdersHistoryTotal()-1; j >= 0; j--)

     {

      if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

        {

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

           {

            if(OrderProfit()>=0)

              {

               n++;

               Print(" >;-2> ?>4@O4 ?;NA>2,  n = ",n);

              }

            else

               break;



           }



        }

     }



   if(n <= :>;8G5AB2>)  // B@5E-:>;5==K9 @073>= (<56 ;>AA0<8), C25;8G5=85 ;>B0 ?@>872>48< =5 1>;55 ":>;8G5AB2>" @07 ?>A;5 ?@>D8B0

      for(j = OrdersHistoryTotal()-1; j >= 0; j--)

        {

         if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

           {

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

              {

               if(OrderProfit()>=0)

                 {

                  OL=NormalizeDouble(OrderLots()*K_Martin,DigitsLot);

                 }

               break;

              }

           }

        }



   return(OL);

  }

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



//------------------------      !'" * '  "    " (?@8 C1KB:5 C25;8G8205< ;>B)   ------------------------------------------

double LOT_Martin()

  {

   int n=0;

   int j;

   double OL = Lot;  //NormalizeDouble(AccountBalance()*LotPercent/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED),DigitsLot);

   if(OL>MAXLOT)

      OL = MAXLOT;

   if(OL<MINLOT)

      OL = MINLOT;



   for(j = OrdersHistoryTotal()-1; j >= 0; j--)

     {

      if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

        {

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

           {

            if(OrderProfit() < 0)

              {

               n++;

               Print(" >;-2> ?>4@O4 <8=CA>2KE A45;>:,  n = ",n);

              }

            else

               break;



           }



        }

     }



   if(n <= :>;8G5AB2>)  // :>;-2> C25;8G5=89 ;>B - =5 1>;55 ":>;8G5AB2>" @07 ?>A;5 A5@88 ;>AA>2

      for(j = OrdersHistoryTotal()-1; j >= 0; j--)

        {

         if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

           {

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

              {

               if(OrderProfit() < 0)

                 {

                  OL=NormalizeDouble(OrderLots()*K_Martin,DigitsLot);

                 }

               break;

              }

           }

        }



   return(OL);

  }

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





//---------------------    !/  +"/   $"/!!     ---------------------------------------------

bool Fresh_closed_at_a_profits() // 5A;8 2 ?@>D8B: 1, 5A;8 2 ;>AA: 0

  {

   int n=0;

   int j;



   for(j = OrdersHistoryTotal()-1; j >= 0; j--)

     {

      if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

        {

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

           {

            if(OrderProfit()>=0)

              {

               n++;

               Print(" !2560O 70:@KB0O 2 ?@>D8B = ", OrderProfit());

               return(true);

              }

            else

              {

               Print(" !2560O 70:@KB0 2 !! = ", OrderProfit());

               break;

              }

           }

        }

     }

   return(false);

  }

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



//-----     '!"  /  +"+%  .!     -----------------

int Number_of_fresh_profits_in_a_row()

  {

   int n=0;

   int j;



   for(j = OrdersHistoryTotal()-1; j >= 0; j--)

     {

      if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

        {

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

           {

            if(OrderProfit()>=0)

              {

               n++;

               Print(" >;-2> ?>4@O4 70:@KBKE ?>78F89 2 ?@>D8B,  n = ",n);

              }

            else

               break;

           }



        }

     }

   return(n);

  }

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



//---------------------     )"   (")  +#)  +" !:   !  ---------------------------------------------

int TYPE_OF_PREVIOUS_TRANSACTION()

  {

   int n=0;

   int j;



   for(j = OrdersHistoryTotal()-1; j >= 0; j--)

     {

      if(OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))

        {

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

           {

            if(OrderType() == OP_BUY)

              {

               Print(" !2560O 70:@KB0O OP_BUY, ?@>D8B/;>AA = ", OrderProfit());

               return(OP_BUY);

              }



            if(OrderType() == OP_SELL)

              {

               Print(" !2560O 70:@KB0O OP_SELL, ?@>D8B/;>AA = ", OrderProfit());

               return(OP_SELL);

              }



           }

        }

     }

   return(-1);

  }

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

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