ERROR 4108

 

Hey everybody

Using ea i need to delete a pending order sellstop type. i use simple technique : first ordeselect

and then oderdelete, nost of the imes i recieve error 4108 invalid ticket though it the orderselcet

locates the order.

my question : who can explain that mishap and how can i overcome this deviation from simple logic

THNKS ANY WAY

 
You'd need to post the section of code so we can investigate. CB
 

Usually, this is due to people selecting using a ticket number but still using SELECT_BY_POS instead of SELECT_BY_TICKET.

.

Jon

 

Hello I was wondering if you could help me with a couple of questions...

1. What is the logic difference between...

for (int index = OrdersTotal() - 1; index >= 0; index--)

and

for (int index = 0; index < OrdersTotal(); index ++)

2. I am using the following to get the last opened order entry price for calculation purposes.

for (int index = 0; index < OrdersTotal(); index ++) {
OrderSelect(index, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol && OrderMagicNumber() == MNumber) EntryPrice = OrderOpenPrice();
}

This works fine but if I have five opened orders, (looking at the order history as ascending),

I need to get the first opened order entry price, (number Five, the oldest in the index), and then

I need to be able to get the entry price for the second and third order. And then I can use the code above for the last one (first one in the index).

Thanks in advance guys!

 
Stanc30:

Hello I was wondering if you could help me with a couple of questions...

1. What is the logic difference between...

for (int index = OrdersTotal() - 1; index >= 0; index--)

loop thru all open orders from the end to the begining

and

for (int index = 0; index < OrdersTotal(); index ++)

loop thru all open orders from the begining to the end

2. I am using the following to get the last opened order entry price for calculation purposes.

for (int index = 0; index < OrdersTotal(); index ++) {
OrderSelect(index, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol && OrderMagicNumber() == MNumber) EntryPrice = OrderOpenPrice();
}

This works fine but if I have five opened orders, (looking at the order history as ascending),

for checking the history, u have use OrdersHistoryTotal()

I need to get the first opened order entry price, (number Five, the oldest in the index), and then

I need to be able to get the entry price for the second and third order. And then I can use the code above for the last one (first one in the index).

checking time, OrderOpenTime() would be the easiest

Thanks in advance guys!

 
  1. You must count down when closing or deleting, or in the presence of other chart orders.
  2. Always test return codes
  3. I need to get the first opened order entry price
    i need to delete a pending order sellstop type
    int         ticket          = 0;                    #define INF 0x7FFFFFFF
    datetime    firstOrderDT    = INF;
    for(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 my pair
    &&  OrderOpenTime()     <  firstOrderDT){              
        ticket = OrderTicket();
    }
    if (ticket != 0 && OrderSelect(ticket, SELECT_BY_TICKET)){
        if (OrderType <= OP_SELL){ // Buy or Sell
           if (!OrderClose(ticket, OrderSize(), OrderClosePrice(), Slippage.Pips*pips2points)
               Alert("OrderClose(ticket=", ticket, ", ...) [1] failed: ", GetLastError());
        }
        else{ // Pending
           if (!OrderDelete(ticket) Alert("OrderDelete(ticket=", ticket, ") [1] failed: ", GetLastError());
        }
    }
Reason: