DeleteOrder problem

 

Hi!

I have a problem with DeleteOrder function. My EA places series of 18 pending orders and assigns order ticket numbers to the array. Program should delete them later on when it decides that they are in a wrong place, and put new ones in a valid place. The problem is that new orders are placed but previous ones are not deleted.

I have coded the following function:

for(int w = 0 ; w < 18 ; w++)

{

if(OrderSelect(sell_order[w,ys-1], SELECT_BY_TICKET) == true)

{ Alert ("w= ",w," ys= ",ys," I have found sell order number: ", sell_order[w,ys-1]);

bool deleted = OrderDelete(sell_order[w,ys-1]);

Alert("OrderDelete returns value: ",deleted, " last error: ", GetLastError());

}

}

Disclaimer: ys is the int variable which is increased by one each time after series of orders are placed.

When I'm testing alerts show the following:

Alert: w= 0 ys= 1 I have found order number:1
delete #1 sell limit (...) ok
OrderDelete returns value: 1 last error: 0

(...)

Alert: w= 16 ys= 1 I have found order number:17
delete #17 sell limit (...) ok

OrderDelete returns value: 1 last error: 0

BUT!

All orders are still there...

I have another question. Why the last found order is number 17 while the last placed order is number 18...?

Does anybody know why is that? I will really appreciate any help.

P.

 

  1. All orders are still there...
    What does the Journal say. Are you exiting Start()? If not, the chart doesn't get refreshed until ObjectsRedraw()
  2. Why the last found order is number 17 while the last placed order is number 18...?
    Post the code for populating sell_order[][] No mind readers here.
  3. Personally I would not use the "remember ticket number" way. If the terminal is restarted/pc reboots/power glitches the EA must be able to recover. That means persistent storage (files). The order loop is easier
        for(int pos = OrdersTotal() - 1; pos >= 0; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber() == magic.number              // my magic number
        &&  OrderSymbol()      == Symbol() ){               // and period and symbol
            if (OrderType()>OP_SELL){  OrderDelete(OrderTicket());}
    
    Also note, your code does not handle the case where an pending order has triggered.