Inconsistent behaviour of OrderSend

 

Hi,


I have the following code:


   int ticketBuy=OrderSend(pair,OP_BUYSTOP,lot,longEntryPrice,100,longStopLossPrice,0,"BUY",0,0,Green);
   if (ticketBuy == -1) {
      ticketBuy=OrderSend(pair,OP_BUYSTOP,lot,longEntryPrice,100,longStopLossPrice,0,"BUY",0,0,Green);
   }
   int ticketSell=OrderSend(pair,OP_SELLSTOP,lot,shortEntryPrice,100,shortStopLossPrice,0,"SELL",ticketBuy,0,Red);
   if (ticketSell == -1) {
      ticketSell=OrderSend(pair,OP_SELLSTOP,lot,shortEntryPrice,100,shortStopLossPrice,0,"SELL",ticketBuy,0,Red);
   }

   Print("Buy ticket: ", ticketBuy, ", Sell ticket: ", ticketSell);


Sometimes it works, sometimes it does not, with a valid ticketBuy value, but -1 for ticketSell.


Anyone has encountered this before?


Thanks in advance,

Alipapa

 

Not sure why you're doubling up on each stop order. But make sure of a few things:

- you're stop order price is not too close to the market price or you will have an invalid price

- Look at your journal tab, it might show an error and help u pinpoint

- u sure you want the magic number to be ticketBuy?

- for a buy stop, the entry price has to be higher then the current market price (Ask), opossite for sell stop