Download MetaTrader 5
To add comments, please log in or register
Let your idle PCs do something useful. Join MQL5 Cloud Network!
DeanDeV
330
DeanDeV 2015.05.29 04:28 

Hi guys,

My OrderDelete() is attempting to delete incorrect orders, thus giving me errors. Below is the code:

void DeleteOrders()
 {
  for(int g=OrdersTotal()-1; g>=0; g--) 
   {
    if(!OrderSelect(g,SELECT_BY_POS,MODE_TRADES)) continue;  
     if(OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicNumber || OrderMagicNumber()==MagicNumber1 || OrderMagicNumber()==MagicNumber2)                
       && (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP))  //Also tried (OrderType()>2)  
    RefreshRates();
     if(!OrderDelete(OrderTicket()))
      Print("Deleting stop orders"," Ordertype:",OrderType());      
   }
 }

 It is trying to delete buy and sell orders. ie. OrderType()<3; however it needs to delete OrderType()>2. 

Please help! 

Keith Watford
Moderator
7887
Keith Watford 2015.05.29 06:37  

Your code tries to delete every order

RefreshRates is the only code dependant on the if conditions

Put in some curly braces

void DeleteOrders()
  {
   for(int g=OrdersTotal()-1; g>=0; g--)
     {
      if(!OrderSelect(g,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderSymbol()==Symbol() &&(OrderMagicNumber()==MagicNumber || OrderMagicNumber()==MagicNumber1 || OrderMagicNumber()==MagicNumber2)
         && (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)) //Also tried (OrderType()>2)
        {
         RefreshRates();
         if(!OrderDelete(OrderTicket()))
            Print("Deleting stop orders"," Ordertype:",OrderType());
        }
     }
  }

 Why do you need the RefreshRates anyway?

DeanDeV
330
DeanDeV 2015.05.29 07:13  
GumRai:

Your code tries to delete every order

RefreshRates is the only code dependant on the if conditions

Put in some curly braces

 Why do you need the RefreshRates anyway?

Thank you GumRai. RefreshRates() removed. It doesn't seem to be giving the error as many times now, but it still pops up. This is what I get printed. It deletes the order and then gives errors:

 

2015.05.29 09:06:44.633 2015.01.05 13:23 OrderDelete error 4108
2015.05.29 09:06:44.633 2015.01.05 13:23 unknown ticket 22 for OrderDelete function
2015.05.29 09:06:44.633 2015.01.05 13:23 OrderDelete error 4108
2015.05.29 09:06:44.633 2015.01.05 13:23 unknown ticket 22 for OrderDelete function
2015.05.29 09:06:44.633 2015.01.05 13:23 OrderDelete error 4108
2015.05.29 09:06:44.633 2015.01.05 13:23 unknown ticket 22 for OrderDelete function
2015.05.29 09:06:44.633 2015.01.05 13:23 Deleting BUY_STOP Ordertype:1
2015.05.29 09:06:44.633 2015.01.05 13:23 delete #22 buy stop 0.50 EURUSD at 1.19429 sl: 1.19129 tp: 1.19814 ok

 It had not entered the buy stop, why is it trying to delete a sell and returning OrderType():1? Also, may I ask for an understanding as to why the curly brackets addition?

Keith Watford
Moderator
7887
Keith Watford 2015.05.29 09:12  
DeanDeV:

Also, may I ask for an understanding as to why the curly brackets addition?

Because in your original code, there were no conditions for the order delete. It would try to delete every order.

The log items that you have posted do not come from the code that you have posted.

Please post the actual code that you have used. 

DeanDeV
330
DeanDeV 2015.05.29 09:58  
GumRai:

Because in your original code, there were no conditions for the order delete. It would try to delete every order.

The log items that you have posted do not come from the code that you have posted.

Please post the actual code that you have used. 

Aha! Rookie error indeed. Thank you! That is referring to another OrderDelete() in my code. Managed to fix the error. If you have a moment, is it possible to help me on this thread: https://forum.mql4.com/67798

 Thanks! 

/
To add comments, please log in or register