MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
How to Use MQL5 Constructions? Check the Documentation!

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.

 
The top 20 universities globally for getting a job in finance

The top 20 universities globally for getting a job in finance

The QS World University rankings are out. In the British press, there’s excitement over the fact that four of the all-round top six universities are based in the UK. However, if you want to work in banking and finance it won’t necessarily help if you go to a university that excels at modern history or English literature: you really need to study at a university a reputation for excellence in economics. In particular, you want to go to a university where employers really rate the economics course. Fortunately QS splits out its rankings both by subject area and by employer reputation. Below we have listed the top twenty university courses globally for economics and econometrics, ranked according to employer reputation. There are some surprises. With the exception of Harvard, the U.S. Ivy League is not so hot. And where is the Stockholm School of Economics?

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
9637
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