Download MetaTrader 5
To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
Mio
9
Mio 2016.02.18 10:16 

I placed a BUYSTOP and a SELLSTOP; but after selecting the order, OrderType() return 0 or 1 instead of 4 or 6 (no other order type  placed)

 result=OrderSend(symbol,OP_BUYSTOP,lot,NormalizeDouble(Ask+2*boxSize,Digits),slippage,0,0,"",MAGICMA,0,CLR_NONE);

   for(int TradeNumber=(OrdersTotal()-1); TradeNumber>=0; TradeNumber--)
     {
      bool selected=OrderSelect(TradeNumber,SELECT_BY_POS,MODE_TRADES);

      if(Bid<slBuy && OrderType()==OP_BUY &&  OrderSymbol()==Symbol())
        {
         result=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Green);
         //HERE CLOSE THE BUYSTOP ORDER!!!!! WHY????
        }

      if(Ask>slSell && OrdeType()==OP_SELL &&  OrderSymbol()==Symbol())
        {
         result=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Green);
         //HERE CLOSE THE SELLSTOP ORDER!!!!! WHY????
        }
     }
Keith Watford
Moderator
7875
Keith Watford 2016.02.18 11:55  

Maybe because the pending orders had been triggered and were no longer stop orders.

Pending orders have to be deleted, not closed, so your code should not delete a pending order.

Mio
9
Mio 2016.02.18 12:34  
No, no pending orders triggered. Return wrong value immeditely, when orders are already pending. I don't want delete pending orders.
Keith Watford
Moderator
7875
Keith Watford 2016.02.18 12:51  
Use Ctrl+f and search for OrderDelete in your code as the order is probably being deleted elsewhere.
whroeder1
13597
whroeder1 2016.02.18 13:19  
  1. Print your variable values used in your if statements.
  2. Check your return codes (OrderSend and OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
/
To add comments, please log in or register