OrderModify error? I cant see why?

 

I have shown below 2 different codes that each do the same task of moving my stop to breakeven after price has gained profit of 200pts (at 0.1 lots).

While the first code works like I want without any problems, I cant see why the second code although appears to work correctly in the MT4 journal it always says OrderModify error 1?

Code 1

  
   // BreakEven Stop   
   for(int order = 0; order <= OrdersTotal() - 1; order++)
   {
      bool select = OrderSelect(order,SELECT_BY_POS);
      bool setBreakEvenStop = false;
      
      double breakEvenStop = 0;   
      double currentProfit = 0;

      double orderStopLoss = OrderStopLoss();   
      double minProfit = pointsBE * _Point;
      
      // Check buy order for stop placement         
      if(OrderType() == OP_BUY)
      {
         breakEvenStop = OrderOpenPrice() + (profit * _Point); 
         breakEvenStop = NormalizeDouble(breakEvenStop,_Digits);
            
         orderStopLoss = NormalizeDouble(orderStopLoss,_Digits); 
                        
         currentProfit = Bid - OrderOpenPrice();
         currentProfit = NormalizeDouble(currentProfit,_Digits);
 
         if(breakEvenStop > orderStopLoss && currentProfit >= minProfit)
         {
            setBreakEvenStop = true;
         }                                
      } 
         
      // Check sell order for stop placement 
      if(OrderType() == OP_SELL)
      {
         breakEvenStop = OrderOpenPrice() - (profit * _Point); 
         breakEvenStop = NormalizeDouble(breakEvenStop,_Digits);
             
         orderStopLoss = NormalizeDouble(orderStopLoss,_Digits); 
                 
         currentProfit = OrderOpenPrice() - Ask;
         currentProfit = NormalizeDouble(currentProfit,_Digits);  

         if(breakEvenStop < orderStopLoss && currentProfit >= minProfit)
         {
            setBreakEvenStop = true;
         }         
      }
         
      if(setBreakEvenStop == true)
      {
         select = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
      }                 
   }

 

Code 2

   // BreakEven Stop   
   for(int order = 0; order <= OrdersTotal() - 1; order++)
   {
      bool select = OrderSelect(order,SELECT_BY_POS);
               
      if(OrderMagicNumber() == MagicNumber && select == true)
      {          
         // Check buy order for stop placement         
         if(OrderType() == OP_BUY)
         {
            if(Bid >= (OrderOpenPrice()+pointsBE*_Point))
            { 
               select = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(profit*_Point), OrderTakeProfit(),0);
            }                                    
         } 
         
         // Check sell order for stop placement 
         if(OrderType() == OP_SELL)
         {     
            if(Ask <= (OrderOpenPrice()-pointsBE*_Point))
            {
               select = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-(profit*_Point), OrderTakeProfit(),0);
            }                                     
         }               
      }
   }  
 
select = OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+(profit*_Point), OrderTakeProfit(),0);

Where do you check if the new SL is above the current?

You
Server
Change the SL to X
It is at X!
Change the SL to XIt is at X!
Change the SL to XYou are insane
 
renzbub:

I have shown below 2 different codes that each do the same task of moving my stop to breakeven after price has gained profit of 200pts (at 0.1 lots).

While the first code works like I want without any problems, I cant see why the second code although appears to work correctly in the MT4 journal it always says OrderModify error 1?

Code 1

 

Code 2

 

 

 

 

  

Error 1 means you are trying to set a new stoploss with the same value as the old one. Check your new value against the old.

Reason: