invalid ticket for order modify

 

I searched through google for how to set stoploss and takeprofit on an ecn broker.

I tried all the examples what could be wrong with my code?

I actually initialized my active open orders ticket number to my variables so that it would work but to no avail on MBtrading


 bull.trade = true;
   Bear.Ticket1 = 431220;
   Bear.Ticket2 = 431221;
    if((bear.trade == true)&&(bear.order.modified == false))
    {
      Print("bear.trade "+bear.trade);
     Print("bear.order.modified "+bear.order.modified);
     Print("bear.modify1 "+bear.modify1);
       OrderSelect(Bear.Ticket1,SELECT_BY_TICKET);
       bear.TP1 = NormalizeDouble((OrderOpenPrice() - atr24),Digits);
        bear.TP2 = NormalizeDouble((OrderOpenPrice() - atr24),Digits);
        
        bear.SL1 = NormalizeDouble((OrderOpenPrice() + atr24),Digits);
        bear.SL2 = NormalizeDouble((OrderOpenPrice() + atr24),Digits);
        Print("Bear.SL1 "+bear.SL1);
         Print("Bear.SL2 "+bear.SL2);
      if(bear.modify1 == false)
      {
       bear.modify1 = OrderModify(Bear.Ticket1,OrderOpenPrice(),bear.SL1,bear.TP1,0,Red);
       }
       
       OrderSelect(Bear.Ticket2,SELECT_BY_TICKET,MODE_TRADES);
       if(bull.modify2 == false)
      {
       bear.modify2 = OrderModify(Bear.Ticket2,OrderOpenPrice(),bear.SL2, bear.TP2,0,Red);
       }
       
       if( (bear.modify1 == true)&&(bear.modify2 == true) )
       {
         bear.order.modified =true;
       }
    }
 

I found this at OrderModify description:

Notes: Open price and expiration time can be changed only for pending orders.
If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated.

For debugging, try to write error codes after OrderSelect / OrderModify functions like this:

if (!OrderSelect(Bear.Ticket1, SELECT_BY_TICKET)) {
    Print("OrderSelect failed with error code: " + GetLastError());
}
 

You can try two scripts as example from here: http://www.forexfactory.com/showthread.php?p=3569282, it places TP and SL on ECN.

 
erzo:

I found this at OrderModify description:

Notes: Open price and expiration time can be changed only for pending orders.
If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated.

For debugging, try to write error codes after OrderSelect / OrderModify functions like this:

figured it out. wrong boolean
 
jeemba2012:

I searched through google for how to set stoploss and takeprofit on an ecn broker.

I tried all the examples what could be wrong with my code?

I actually initialized my active open orders ticket number to my variables so that it would work but to no avail on MBtrading



Every trade you do has its own specific OrderTicket() number. That number is given by your broker to the order

You trie to modify it with wrong OrderTicket() number Before you gonna modify you have to select the right trade

Bear.Ticket1 is not your OrderTicket() if it fails OrderModify( ... ) with error invalid ticket for order modify

 
  1. Always test return codes including OrderSelect.
  2. On the creation of an order, you can just select and modify
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){                                                     OptParameters();
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(..., 0,0,...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
           Alert("OrderModify failed: ", GetLastError());
         */
    

  3. On a new tick, you must find the open order ticket number as the ticket might already be closed.
        for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
        &&  OrderMagicNumber()  == Magic.Number                 // my magic number
        &&  OrderSymbol()       == chart.symbol                 // and my pair.
        ){
            // OrderTicket() is valid here

Reason: