How to Store StopLoss for trades and call if I change to 0

 

Hi,


I want to store stoploss in StopLoss manually also if I change.

I need to get only first StopLoss, and then change in variable only first time. If StopLoss has been changed in the future, in my variable this not change.


My code:

double point_value = 0;
  for (int Counter = 0; Counter <= OrdersTotal() - 1; Counter++)
    {
        if (OrderSelect(Counter, SELECT_BY_POS))
        {
            if (OrderSymbol() == _Symbol && (OrderType() == OP_BUY || OrderType() == OP_SELL))
            { 
            
                int point_compat = 1;
                point_value = _Point * MarketInfo(_Symbol, MODE_TICKVALUE) / MarketInfo(_Symbol, MODE_TICKSIZE);
                
                 if (Digits == 3 || Digits == 5) point_compat = 10;
                 
                 
             double StopLoss;    
             
             
               StopLoss = OrderStopLoss();
             
             DiffPips = MathAbs((NormalizeDouble(((OrderOpenPrice() - OrderStopLoss()) / MarketInfo(Symbol(), MODE_POINT)), MarketInfo(Symbol(), MODE_DIGITS))) / point_compat * 10);              
            
            Print(StopLoss);
            
            
            }
            
            }
            
            } 
 
chris.dotan:

Hi,


I want to store stoploss in StopLoss manually also if I change.

I need to get only first StopLoss, and then change in variable only first time. If StopLoss has been changed in the future, in my variable this not change.


My code:

Something simple like this may work, adjust as needed - NOT TESTED 

   double point_value =  0;
   double StopLoss    = -1;


   for(int Counter = 0; Counter <= OrdersTotal() - 1; Counter++)
     {
      if(OrderSelect(Counter, SELECT_BY_POS))
        {
         if(OrderSymbol() == _Symbol && (OrderType() == OP_BUY || OrderType() == OP_SELL))
           {

            int point_compat = 1;
            point_value = _Point * MarketInfo(_Symbol, MODE_TICKVALUE) / MarketInfo(_Symbol, MODE_TICKSIZE);

            if(Digits == 3 || Digits == 5)
               point_compat = 10;



            StopLoss = (StopLoss < 0)? OrderStopLoss() : StopLoss;

            DiffPips = MathAbs((NormalizeDouble(((OrderOpenPrice() - OrderStopLoss()) / MarketInfo(Symbol(), MODE_POINT)), MarketInfo(Symbol(), MODE_DIGITS))) / point_compat * 10);

            Print(StopLoss);


           }

        }

     }
 
chris.dotan:

Hi,


I want to store stoploss in StopLoss manually also if I change.

I need to get only first StopLoss, and then change in variable only first time. If StopLoss has been changed in the future, in my variable this not change.


My code:

I don't really understand what you want, my interpretation is that you want to get the stoploss and compare it once with your new stoploss or something.

If you only want to get your stoploss then you only need to get the OrderStopLoss().

for (int Counter = OrdersTotal; Counter >= 0; Counter--) //better do decrement because of how MT4 read OrdersTotal() 
    {
        if (OrderSelect(Counter, SELECT_BY_POS))
        {
            if (OrderSymbol() == _Symbol && (OrderType() == OP_BUY || OrderType() == OP_SELL))
            { 
                if(OrderStopLoss() != your new stoploss)
                {
                    //do something here
                }
            }