MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Buy Latest Technical Indicators in MetaTrader Market

Ordersend error

Back to topics list To post a new topic, please log in or register
avatar
2
ARFX57 2009.10.24 23:43
 

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.

 
All about Automated Trading Championship: Reporting the Championship 2007

All about Automated Trading Championship: Reporting the Championship 2007

The present article contains Weekly Reports of the ATC 2007. These materials are like snapshots, they are interesting-to-read not only during the Championship, but years later as well.

avatar
250
fx1.net 2009.10.25 10:00 #
 
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.
 
avatar
364
Irtron 2009.10.25 15:06 #
 
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.

 
avatar
2
ARFX57 2009.10.25 17:54 #
 

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

avatar
9522
WHRoeder 2009.10.25 18:34 #
 

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

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

 
avatar
364
Irtron 2009.10.25 19:55 #
 
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.

 
Back to topics list  

To add comments, please log in or register