Ordersend error

 

Hello

I have an expert, in some special trades(I don't know the reason), Ordersend can not open the trade. It returns -1, but getlasterror() is 0. I can't understand what is the reason. Could you please help?

this is a part of log file of this expert:

Account balance=100004.00000000
InitialTradeVolumeBeforeMinlot=4.66000000
MinLot=0.10000000
InitialTradeVolumeAfterMinlot=4.66000000
Parameters of Opening Trade are : Trade Type=SELL Symbol=EURUSD current BID price is 1.50147 Instruction_Open_Price=1.50129 SL=1.55497 TP=0.00000 Volume=4.66000000 Leverage=4.66
Allowed slippage for EURUSD is 100 pis
Executing Trade failed with error #0

This expert works well some timesand thsi error some other times. Please help.

Thanks.

 
may your broker make you problems? Why dont you keep trying to send the OrderSend in case you get -1? You may build a counter and send it 3 times after you got error. Of course you may loose some ticks but seems you anyways try to insert a sellstop order.
 
ARFX57:

Hello

I have an expert, in some special trades(I don't know the reason), Ordersend can not open the trade. It returns -1, but getlasterror() is 0. I can't understand what is the reason. Could you please help?

this is a part of log file of this expert:

Account balance=100004.00000000
InitialTradeVolumeBeforeMinlot=4.66000000
MinLot=0.10000000
InitialTradeVolumeAfterMinlot=4.66000000
Parameters of Opening Trade are : Trade Type=SELL Symbol=EURUSD current BID price is 1.50147 Instruction_Open_Price=1.50129 SL=1.55497 TP=0.00000 Volume=4.66000000 Leverage=4.66
Allowed slippage for EURUSD is 100 pis
Executing Trade failed with error #0

This expert works well some timesand thsi error some other times. Please help.

Thanks.

This is either Bid and OpenPrice mismatch (which is definitely a bug for sell order, slippage doesn't matter really) or incorrect error handling, Or both. Or something else.

You're the only person who has a privilege to see your code and find the right answer atm.

 

Hello

thanks for the answers. this is part of the code:

if(SLPG>SlippageControl(Symbol1[j]+ Suffix))
{
Comment2("Could not send Trade_ID=" + TradeID[j] + " due to slippage of " + NormalizeDouble( SLPG, 0) + " Pips.");
}
else
{
int Ticket=-1;
if( CommandType[j] == OP_BUY)
Ticket=OrderSend(Symbol1[j]+ Suffix,CommandType[j],InitialTradeVolume, MarketInfo(Symbol1[j]+ Suffix,MODE_ASK), 50, SL[j], TP[j], "TradeID=" + TradeID[j],TradeID[j]+MaxMagicNumberOfOtherExperts);
else
Ticket=OrderSend(Symbol1[j]+ Suffix,CommandType[j],InitialTradeVolume, MarketInfo(Symbol1[j]+ Suffix,MODE_BID), 50, SL[j], TP[j], "TradeID=" + TradeID[j],TradeID[j]+MaxMagicNumberOfOtherExperts);

if(Ticket<=0)
{
if(GetLastError()==4 | GetLastError()==6 | GetLastError()==132 | GetLastError()==137)
{
Comment2("Trade is not executed due to Server busy or no connection or market closed or broker busy.");
Comment2("Command will be re-executed after 1 minute.");
NumberOfTriesForThisLine[j]--;
Sleep(60000);
}
else
{
Comment2("Executing Trade_ID=" + TradeID[j] + " failed with error #" + GetLastError());
Sleep(1000);
}
}
else
{
Comment2("Trade_ID=" + TradeID[j] + " was executed successfully." );
}

As you see, I'm directly using MarketInfo(). what may be the reason?

Thanks

 

I see your using Sleep() but not RefreshRates()

Print each argument to SendOrder() to full Digits precision.

 
ARFX57:

if(GetLastError()==4 | GetLastError()==6 | GetLastError()==132 | GetLastError()==137)

{
Comment2("Trade is not executed due to Server busy or no connection or market closed or broker busy.");
Comment2("Command will be re-executed after 1 minute.");
NumberOfTriesForThisLine[j]--;
Sleep(60000);
}
else
{
Comment2("Executing Trade_ID=" + TradeID[j] + " failed with error #" + GetLastError());
Sleep(1000);
}


Incorrect error handling it is. GetLastError() zeros LastError value hence all the calls to GetLastError() except the very first one (GetlLastError() == 4) don't make sense.


BTW bitwise OR operator looks cool but may cause unexpected behaviour in condition statement.

Reason: