MQL4 order count in closed for stop loss

 
hello everyone, I need a function that counts how many orders are closed in stop loss (total), then how many consecutive orders are closed in stop loss.
someone can help me
 

You can write a function that loops over the closed orders and analyze the order comment if it contains [sl] then the order was closed by a stoploss, then you analyze the ordertype (if needed) and if it is the same as the previous sl closed order then you increment the consecutive sl counter until either the ordertype changes, or the order was closed manually, or by take profit so when there is no [sl] in the order comment.

When you exit the loop you will have the number of consecutive orders that were closed by sl.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 
topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
 

hello I'm tring this function, but it generates a continue counter

int RicercaSL()
  {
   int TotaleStorico = OrdersHistoryTotal();
   if(TotaleStorico > 0)
     {
      for(int i = 0; i < TotaleStorico ; i++)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
           {
            if(OrderMagicNumber() == MagicNumber && OrderProfit()<0)  //
              {

               if(OrderType()==OP_BUY)
                  stl=stl+1;

               if(OrderType()==OP_SELL)
                  stl=stl+1;

               Print("Closed price:",OrderClosePrice()," Price StopLoss",OrderStopLoss(), " Closed in SL");
              }
           }
        }
     }
   Print("Orders total", TotaleStorico, "  Orders in SL:",stl);
   return(stl);
  }


someone cal help me?

 
Gianni.D:

Please edit your post and

use the code button (Alt+S) when pasting code