BreakEven Order Modify Error 1

 

Sir,

I learned this MQL5 Programming but I want to practice this MQL4 Programming because What is the result difference b/w MT4 & MT5 in my Real account .

 

I am getting error "Order Modify Error 1" too many times....

Please use this OctaFX Broker MT4 Terminal ....because you are using another broker if you don't getting any error...

//+------------------------------------------------------------------+
//|     Breakeven Gain & Breakeven                                   |
//+------------------------------------------------------------------+
void BreakEven(string Symbol_param, int Magic_1, int slippage_1, double Input_BreakevenGain, double Input_Breakeven)
  {
  for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      ulong Position_Ticket = OrderTicket();

      string Check_Symbol = OrderSymbol();
      long Pos_Magic = OrderMagicNumber();

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && Check_Symbol == Symbol_param && Pos_Magic == Magic_1)
        {
         //double Price_Current = Bid;
         double Price_Open = NormalizeDouble(OrderOpenPrice(),Digits());

         double Position_SL = NormalizeDouble(OrderStopLoss(),Digits());
         double Position_TP = NormalizeDouble(OrderTakeProfit(),Digits());

         double Stoplevel = MarketInfo(Symbol_param,MODE_STOPLEVEL) * point;
         double Spread = MarketInfo(Symbol_param,MODE_SPREAD) * point;

         double BreakevenGain_SL = MathMax(Stoplevel+Spread,Input_BreakevenGain*point);
         double Breakeven_SL = Input_Breakeven * point;
         
        //Print("End ======================= End");       

         if(OrderType() == OP_BUY)
           {
            if((Bid - OrderOpenPrice()) > BreakevenGain_SL) 
              {
               if(Position_SL < Price_Open || Position_SL == 0 )
                 {
                 if(!OrderModify(Position_Ticket,Price_Open, NormalizeDouble(Price_Open + Breakeven_SL,Digits),Position_TP,0,clrNONE))
                    {
                     //Print("Buy Order Price = ", Price_Open, ", BreakEven Failed ",GetLastError());
                     return;
                    }

                 }
              }
           }
         else
            if(OrderType() == OP_SELL)
              {
               if((OrderOpenPrice()-Ask) > BreakevenGain_SL)
                 {
                  if(Position_SL > Price_Open || Position_SL == 0)
                    {
                     if(!OrderModify(Position_Ticket,Price_Open,NormalizeDouble(Price_Open - Breakeven_SL,Digits),Position_TP,0,clrNONE))
                       {
                        //Print("Sell Order Price = ", Price_Open, ", BreakEven Failed ",GetLastError());
                        return;
                       }
                    }
                 }

              }
        }
     }

  }


//Digits

//Point
double point = 0;

   int digits = 1;

   if(Digits() == 3 || Digits() == 5)
     {
      digits = 10;
      point = Point() * digits;
     }
   else
      if(Digits() <= 2 || Digits() == 4)
        {
         point = Point() * 1;
        }


I saw the many Comment in MQL4 Forum (Link below  👇

Link :- https://www.mql5.com/en/forum/145258 or many link

But I don't really understand...   Please solve this code or write your code...


Thanks 

The == operand.
The == operand.
  • 2013.06.07
  • www.mql5.com
Hi, can anyone help? This seems a simple task but it does not work...
Files:
 

Probably OrderModify call without sl/tp change cause the error.

         if(OrderType() == OP_BUY)
           {
            if((Bid - OrderOpenPrice()) > BreakevenGain_SL) 
              {
               if(Position_SL < Price_Open || Position_SL == 0 )
                 {
                	 double new_sl=NormalizeDouble(Price_Open + Breakeven_SL,Digits);
	                 if(new_sl!=Position_SL)
			 {
        	                 if(!OrderModify(Position_Ticket,Price_Open, new_sl,Position_TP,0,clrNONE))
                	            {
                        	     //Print("Buy Order Price = ", Price_Open, ", BreakEven Failed ",GetLastError());
                                	return;
	                            }
			  }
                 }
              }
           }
 
Yashar Seyyedin #:

Probably OrderModify call without sl/tp change cause the error.

Sir,

I tried it but I changed this code  if I am getting error "Order Modify Error 1" too many times..

Code :-

//+------------------------------------------------------------------+
//|     Breakeven Gain & Breakeven                                   |
//+------------------------------------------------------------------+
void BreakEven(string Symbol_param, int Magic_1, int slippage_1, double Input_BreakevenGain, double Input_Breakeven)
  {
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      ulong Position_Ticket = OrderTicket();

      string Check_Symbol = OrderSymbol();
      long Pos_Magic = OrderMagicNumber();

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && Check_Symbol == Symbol_param && Pos_Magic == Magic_1)
        {
 
        //double Price_Current = Bid;
         double Price_Open = NormalizeDouble(OrderOpenPrice(),Digits);

         double Position_SL = NormalizeDouble(OrderStopLoss(),Digits);
         double Position_TP = NormalizeDouble(OrderTakeProfit(),Digits);

         double Stoplevel = MarketInfo(Symbol_param,MODE_STOPLEVEL) * point;
         double Spread = MarketInfo(Symbol_param,MODE_SPREAD) * point;

         double BreakevenGain_SL = MathMax(Stoplevel+Spread,Input_BreakevenGain*point);
         double Breakeven_SL = Input_Breakeven * point;

         //Print("End ======================= End");

         if(OrderType() == OP_BUY)
           {
            if((Bid - OrderOpenPrice()) > BreakevenGain_SL)
              {
               if(Position_SL < Price_Open || Position_SL == 0)
                 {
                  double new_sl=NormalizeDouble(Price_Open + Breakeven_SL,Digits);

                  if(new_sl != Position_SL)
                    {
                     if(!OrderModify(Position_Ticket,Price_Open,new_sl,Position_TP,0,clrNONE))
                       {
                        //Print("Buy Order Price = ", Price_Open, ", BreakEven Failed ",GetLastError());
                        return;
                       }
                    }

                 }
              }
           }
         else
            if(OrderType() == OP_SELL)
              {
               if((OrderOpenPrice()-Ask) > BreakevenGain_SL)
                 {
                  if(Position_SL > Price_Open || Position_SL == 0)
                    {
                     double new_sl_1 = NormalizeDouble(Price_Open - Breakeven_SL,Digits);

                     if(new_sl_1 != Position_SL)
                       {
                        if(!OrderModify(Position_Ticket,Price_Open,new_sl_1,Position_TP,0,clrNONE))
                          {
                           //Print("Sell Order Price = ", Price_Open, ", BreakEven Failed ",GetLastError());
                           return;
                          }
                       }
                    }
                 }

              }
        }
     }

  }
Files:
 

Vikram J U #:

I would put the RefreshRates() before the loop starts, and OrderSelect line directily underneath the loop initiation.

Also OrderTakeProfit() and OrderStopLoss() are already Normalised, therefore it could add to your error 1.

And your new_sl_1 != Position_SL is your issue. This sort of comparision needs to be avoided at all costs, as it is a computer binary issue that means that that statement is not the same in computer lingo, and it might result in true when to you and me it should be false.

And your OrderModify lines need to have at least 1 OrderXXX() whether it be OrderTicket() or OrderLots() or OrderStopLoss() or OrderTakeProfit(). This could be another reason for your error 1.

 
Vikram J U #:

Sir,

I tried it but I changed this code  if I am getting error "Order Modify Error 1" too many times..

Code :-

i would also change the "return" for break too.

And you shoud Normalise the 2X Breakeven variables. This might cause the != to result in wrong true/false.

see if those changes make any difference.
 
Vikram J U #:
void BreakEven(string Symbol_param, int Magic_1, int slippage_1, double Input_BreakevenGain, double Input_Breakeven)
  {
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      ulong Position_Ticket = OrderTicket();

      string Check_Symbol = OrderSymbol();
      long Pos_Magic = OrderMagicNumber();

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && Check_Symbol == Symbol_param && Pos_Magic == Magic_1)
        {

You should do what I highlighted after the OrderSelect and not before.

Most likely this is the cause of error 1

 
Revo Trades #:
And your new_sl_1 != Position_SL is your issue.

In this case, there are no problems due to the accuracy of the double type, since both prices involved in the comparison are normalized.

However, I would rather compare the difference between the current and new stop loss value with the Point value, for example.

 
Vladislav Boyko #:

In this case, there are no problems due to the accuracy of the double type, since both prices involved in the comparison are normalized.

However, I would rather compare the difference between the current and new stop loss value with the Point value, for example.

agreed. I suggested that it should be avoided.

 
  1.       ulong Position_Ticket = OrderTicket();
    
          string Check_Symbol = OrderSymbol();
          long Pos_Magic = OrderMagicNumber();
    
          if(OrderSelect(…

    MT4: You can not use any Trade Functions until you first select an order.

  2.                      if(new_sl_1 != Position_SL)
    

    You must move the SL at least one ticksize.

    Doubles are rarely equal (doubles are usually not equal). Understand the links in:
              The == operand. - MQL4 programming forum #2 (2013)

 
Vladislav Boyko #:

You should do what I highlighted after the OrderSelect and not before.

Most likely this is the cause of error 1

 and

William Roeder #:
  1. MT4: You can not use any Trade Functions until you first select an order.

  2. You must move the SL at least one ticksize.

    Doubles are rarely equal (doubles are usually not equal). Understand the links in:
              The == operand. - MQL4 programming forum #2 (2013)


Sir,

 It is working to modifying this stoploss but There is no more error in this journal tab ..

Please see this code :-

 if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         string Check_Symbol = OrderSymbol();
         long Pos_Magic = OrderMagicNumber();

         if(Check_Symbol == Symbol_param && Pos_Magic == Magic_1)
           {
            double Position_SL = OrderStopLoss();
            double Position_TP = OrderTakeProfit();

            double Price_Open = OrderOpenPrice();
            ulong Position_Ticket = OrderTicket();


Thank you helping for me ....😃😁