orderdelete with ticketnumber

 

i have the follwing commands to send the order:

buyStopOrder=OrderSend(Symbol(),OP_BUYSTOP,lots,entryw1,100,SLw1,TPw1,NULL,333,0,Blue);

sellStopOrder=OrderSend(Symbol(),OP_SELLSTOP,lots,entryw2,100,SLw2,TPw2,NULL,444,0,Red);

and then the following code. The EA should (for example) delete pending order (with magicnumber 333) when order with magicnumber 444 opens.

Right now i get many error 4108 in journal, saying "unknown ticket 6 for OrderDelete function"

void CheckOrders()
{
   //int total = OrdersTotal();
   //for (int cnt = 0 ; cnt < total ; cnt++)
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

      //OPENED PENDING ORDERS
      if(OrderType()==OP_BUY&& OrderMagicNumber()==333) 
      {
         ready333=0;
         OrderDelete(sellStopOrder);
         if (OrderStopLoss()!=MiddleWhiteLine) OrderModify(OrderTicket(),0,MiddleWhiteLine,TopGoldLine,0,Blue);
      } 
      if(OrderType()==OP_SELL&& OrderMagicNumber()==444) 
      {
         ready444=0;
         OrderDelete(buyStopOrder);
         if (OrderStopLoss()!=MiddleWhiteLine) OrderModify(OrderTicket(),0,MiddleWhiteLine,BottomGoldLine,0,Red);
      }
      
      //PENDING ORDERS
      if(OrderType()==OP_BUYSTOP&& OrderMagicNumber()==333) 
      {
         ready333=0;
         if (OrderOpenPrice()!=TopGreenLine) OrderModify(OrderTicket(),TopGreenLine,0,0,0,Blue);
      }
      if(OrderType()==OP_SELLSTOP&& OrderMagicNumber()==444) 
      {
         ready444=0;
         if (OrderOpenPrice()!=BottomGreenLine) OrderModify(OrderTicket(),BottomGreenLine,0,0,0,Red);
      }
   }
}
 

Why are you looping trough all your orders?

if you have stored the ticketnumber in the variables sellStopOrder and buyStopOrder there is no need for the loop, but i assume you have made a mistake in the OrderOpen() code..

and btw, no matter what happens to your orders, ready333 and ready444 will always be 0.

//z

 
zzuegg:

Why are you looping trough all your orders?

if you have stored the ticketnumber in the variables sellStopOrder and buyStopOrder there is no need for the loop, but i assume you have made a mistake in the OrderOpen() code..

and btw, no matter what happens to your orders, ready333 and ready444 will always be 0.

//z


i have different orders, each with their own magicnumber) so i have to check them all. Also in the main code, the ready333 and ready444 are both set to 1 each time, so only when the order alrady exists, it wont take the order again.

I don't use OrderOpen() but OrderSend(), but do you see a mistake it it? If so, whats wrong?

And yes, the SellStopOrder and BuyStopOrder should have the right ticket number, but when i watch the results in backtest, i see orders are deleted, but somehow it also gives many 4108 errors in Journal?

 
ido370:

i have the follwing commands to send the order:

buyStopOrder=OrderSend(Symbol(),OP_BUYSTOP,lots,entryw1,100,SLw1,TPw1,NULL,333,0,Blue);

sellStopOrder=OrderSend(Symbol(),OP_SELLSTOP,lots,entryw2,100,SLw2,TPw2,NULL,444,0,Red);

and then the following code. The EA should (for example) delete pending order (with magicnumber 333) when order with magicnumber 444 opens.

Right now i get many error 4108 in journal, saying "unknown ticket 6 for OrderDelete function"

You are trying to delete open orders. OrderDelete() only works on pending orders. For example you say if the order type is OP_BUY then delete it.

An OP_BUY from the open orders pool is a long position not a pending position. It can't be deleted, it has to be closed using the OrderClose() function.


You should of course be checking your sellStopOrder and buyStop order variables to make sure they hold valid tickets (not -1).

 
dabbler:

You are trying to delete open orders. OrderDelete() only works on pending orders. For example you say if the order type is OP_BUY then delete it.

An OP_BUY from the open orders pool is a long position not a pending position. It can't be deleted, it has to be closed using the OrderClose() function.


You should of course be checking your sellStopOrder and buyStop order variables to make sure they hold valid tickets (not -1).


I think you misread, if the order type is OP_BUY, THEN delete the pending order (OP_SELLSTOP) with ticketnumber sellStopOrder.

other way around, if order type is OP_SELL, then delete pending order OP_BUYSTOP

 
anyone else got ideas, of whats wrong in the code? It's like an OCO, one pending order opens, other pending should be deleted. Who can help?