Download MetaTrader 5
To add comments, please log in or register
They are already making profit using the Market. You can join them!
gangsta1
1117
gangsta1 2015.10.05 17:23 

I am running multiple terminals on a VPS (with EA's) and every so often I am getting the "OrderSend() error - trade timeout" message.

It also happens when the EA is trying to modify open orders right after they have been placed - e.g. to place the take profit.

Is there anything I can code so that it will keep trying until the order is sent or modified?

whroeder1
13610
whroeder1 2015.10.05 17:46  

Yes, you code it to RefreshRates and try again.

Note that a trade timeout on OrderSend means that the order may or may not have been opened.

This is why I recommend just logging the error and returning. On the next tick, an OrderSelect loop tells you which.

gangsta1
1117
gangsta1 2015.10.05 18:26  

My EA uses "once per bar" to execute the code, perhaps this is causing a problem also? Maybe if it was on every tick it would keep trying to modify the order. I will look for a refresh rates snippet of code to try and work with. Again, I hop refresh rates will work with once per bar.


Where on my code should I place "Refresh Rates"?

void SellOrderLots()
{
    if (MarketInfo(Symbol(), MODE_SPREAD)/PipValue <= MaxSpread)
{
 //RefreshRates(); Place here??
    double SL = Bid + StopLoss*PipValue*Point;
    if (StopLoss == 0) SL = 0;
    double TP = Bid - TakeProfit*PipValue*Point;
    if (TakeProfit == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, MaxSlippage, 0, 0, ExpertName, MagicNumber2, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, MaxSlippage, SL, TP, ExpertName, MagicNumber2, 0, Red);
    if (ticket > -1)
    {
        if (true)
        {
 //RefreshRates(); And Place here??
            if(OrderSelect(ticket, SELECT_BY_TICKET))
            if (OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red) == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}
}
/
To add comments, please log in or register