MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Check MetaTrader Market in order to find your Expert Advisor

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.

 
Trader's Kit: Drag Trade Library

Trader's Kit: Drag Trade Library

The article describes Drag Trade Library that provides functionality for visual trading. The library can easily be integrated into virtually any Expert Advisor. Your Expert Advisor can be transformed from an automat into an automated trading and information system almost effortless on your side by just adding a few lines of code.

avatar
249
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
9421
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