Multiple OrderSend simultaneously

 

Hi!


I'd like to make multiple ordersend simultaneously (one tick).

Here is my code:

      ticket1=OrderSend(tradepair,OP_SELL,mylot,Bid,1,Bid+sl_limit*Point,Bid-tp_limit*Point,"",1,0,Coral);
      ticket2=OrderSend(tradepair,OP_SELL,mylot,Bid,1,Bid+sl_limit*Point,Bid-tp_limit*Point,"",1,0,Coral);
      ticket3=OrderSend(tradepair,OP_SELL,mylot,Bid,1,Bid+sl_limit*Point,Bid-tp_limit*Point,"",1,0,Coral);
      ticket4=OrderSend(tradepair,OP_SELL,mylot,Bid,1,Bid+sl_limit*Point,Bid-tp_limit*Point,"",1,0,Coral);
      ....
      ticketn=OrderSend(tradepair,OP_SELL,mylot,Bid,1,Bid+sl_limit*Point,Bid-tp_limit*Point,"",1,0,Coral);

I get only one trade. Why?

How can I do it well?

Thanks

 
 

GG

Do something like this - just an idea..

In summary, you need to handle certain possible errors and get the latest prices.

Worst thing about yours is that if n orders goes off one tick, the Bid will have moved on at the brokers server when you will still be sending the Bid from that earlier tick..

So always do a RefreshRates() before calling this and sending the latest Bid/Ask

int OpenAtMarket (string strPair, int iOrderType, double dLots, double dPrice, int iSlippage, double dSL, double dTP, string strOrderComment, int iMagicNumber, datetime dtExpiry, color cColour, int iNR, int iMTS)
{
int iMaxNumRetries, iNumRetries=iNR;

// is server or context busy - try n times to submit the order
iNumRetries=iNR;

while(iNumRetries>0)
{
int iTicket = OrderSend(strPair, iOrderType, dLots, dPrice, iSlippage, dSL, dTP, strOrderComment, iMagicNumber, dtExpiry, cColour);

iNumRetries--;

if(iTicket == -1 )
{
int iError = GetLastError();

// retry if error is "busy", otherwise give up
if( iError==4 || iError==146 || iError==137 || iError==6 || iError==128) //ERR_SERVER_BUSY, ERR_TRADE_CONTEXT_BUSY, ERR_BROKER_BUSY, ERR_NO_CONNECTION, ERR_TRADE_TIMEOUT
Sleep(iMTS);
else
{
iNumRetries = 0;
Print("OpenAtMarket: OrderSend Error ", GetLastError() );
}
}
else
iNumRetries = 0;
}

return(iTicket);
}