OrderModify Error help

 

I am stuck and not sure what I am doing wrong.

My EA is reporting a OrderModify error 1 on almost every tick.

I am trying to get the EA to modify an order when the "entry" variable changes from the OrderOpenPrice(), which was originally opened using "entry".

In the past to check values I have placed a Print (entry); and Print (OrderOpenPrice()); directly after if (entry != OrderOpenPrice()) { and it is still trying to execute my ordermodify statement even when both of these are == to eachother.

What am I doing wrong?

Thank you

Here is the code I have pertaining to this issue.

int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
   {
   OrderSelect(i, SELECT_BY_POS);
   
   if (OrderSymbol()==Symbol()&& OrderType()== OP_SELLSTOP && RiskManagement==true)
      {
      if (entry != OrderOpenPrice())
         {
         OrderModify(OrderTicket(),entry,stoploss,takeprofit,0,0);
         }
      }
   if (OrderSymbol()==Symbol()&& OrderType()== OP_SELLSTOP && RiskManagement==false)
      {
      if (entry != OrderOpenPrice())
         {
         OrderModify(OrderTicket(),entry,entry+(StopLossPips*Point),entry-(TakeProfitPips*Point),0,0);
         }
 
bauerjj10:

I am stuck and not sure what I am doing wrong.

My EA is reporting a OrderModify error 1 on almost every tick.

I am trying to get the EA to modify an order when the "entry" variable changes from the OrderOpenPrice(), which was originally opened using "entry".

In the past to check values I have placed a Print (entry); and Print (OrderOpenPrice()); directly after if (entry != OrderOpenPrice()) { and it is still trying to execute my ordermodify statement even when both of these are == to eachother.

What am I doing wrong?

Thank you

Here is the code I have pertaining to this issue.

In general you better use < and > instead of != when comparing doubles.
 
robofx.org wrote >>
In general you better use < and > instead of != when comparing doubles.


Thanks for the help,

I will try this.

 
bauerjj10:

(...) directly after if (entry != OrderOpenPrice()) { and it is still trying to execute my ordermodify statement even when both of these are == to eachother.

See part 4 in this article -> https://www.mql5.com/en/articles/1561.
 
gordon wrote >>
See part 4 in this article -> https://www.mql5.com/en/articles/1561.


Hi Gordon,

Thank you for this, I was actually wondering if there was a function that would allow me to set the number of digits returned. The NormalizedDouble function seems very usefull.

However I am still getting a ordermodify error 1 but only on my buystop orders, my sellstop orders seem to be working correctly and ordermodify will not be triggered unless my "entry" variable is changed.

here is the code for both my sellstop and buystop. After each tick it seems that the buystop function statement is being triggered, and it is trying to modify the orders "entry" variable when it is exactly the same as the openorderprice().

The Print function you see on my buystop statement is producing the following

10:53:11 2008.11.13 12:00 work181 GBPUSD,H4: 1.5494
10:53:11 2008.11.13 12:00 work181 GBPUSD,H4: 1.5494
10:53:11 2008.11.13 12:00 work181 GBPUSD,H4: OrderModify error 1

int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
   {
   OrderSelect(i, SELECT_BY_POS);
   
   if (OrderSymbol()==Symbol()&& OrderType()== OP_SELLSTOP && RiskManagement==true)
      {
      if (NormalizeDouble(entry,4) != OrderOpenPrice())
         {
         OrderModify(OrderTicket(),entry,stoploss,takeprofit,0,0);
         }
      }
   if (OrderSymbol()==Symbol()&& OrderType()== OP_SELLSTOP && RiskManagement==false)
      {
      if (NormalizeDouble(entry,4) != OrderOpenPrice())
         {
         OrderModify(OrderTicket(),entry,entry+(StopLossPips*Point),entry-(TakeProfitPips*Point),0,0);
         }
      }
   if (OrderSymbol()==Symbol()&& OrderType()== OP_BUYSTOP && RiskManagement==true)
      {
      if (NormalizeDouble (entry1,4) != OrderOpenPrice())
         {
         Print(NormalizeDouble(entry1,4));
         Print(OrderOpenPrice());
         OrderModify(OrderTicket(),entry1,stoploss1,takeprofit1,0,0);
         }
      }
   if (OrderSymbol()==Symbol()&& OrderType()== OP_BUYSTOP && RiskManagement==false)
      {
      if (NormalizeDouble(entry1,4) != OrderOpenPrice())
         {
         OrderModify(OrderTicket(),entry1,entry1-(StopLossPips*Point),entry1+(TakeProfitPips*Point),0,0);
         }
      }
 

Ok, I finally figured out what was wrong before, Now I have a new question.

I am trying to create a function that will not allow MT4 to place a pending trade at the same price as a currently open trade.

for example:
if I have a buy order open at "x" price and my entry rules later say place a buystop at "x" price it will not allow this to happen.

This is what I have right now and it currently is not working.

function:

int buytradeok()
   {
   int trade=0;
//----
   for(int f=0;f<OrdersTotal();f++)
     {
      if(OrderSelect(f,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)
            {
            if (OrderOpenPrice() == entry1)  trade++;
            }
        }
     }
//---- return orders volume
   if(trade>0)return(1);
   else  return(0);
   }

Ordersend:

      if (total < MaxOrders)
            {
                  if (CalculateBuyOrders()==0 && Close[0]<frac_up)                                                                                                                      //only opens buystop order if buystops are equal to 0                                                                   
                     {
                     if (buytradeok() < 1)
                        {
                        if (RiskManagement==true)
                           {
                           ticket=OrderSend(Symbol(),OP_BUYSTOP,LotValue,entry1,MaxSlippage,stoploss1,takeprofit1,NULL,0,0,Blue);
                           if(ticket>0)
                                 {
                                 if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                                 Print("BUYSTOP opened : ",OrderOpenPrice());
                                 }
                           else Print("Error opening BUYSTOP order : ",GetLastError());
                           }
Reason: