Dear MQL5 users.
I am currently experiencing some multiple order execution problem with my EA but only for a specific broker.
My EA works perfectly in strategy tester. It also works with other brokers in live trading mode too.
With a specific broker, my EA sometime often 10 orders of the same size at the same time.
It seems that the problem is caused by the communication between brokers and terminal.
Below is my current code and the current code checks 10 time if order is executed.
If the EA receive retcode==10009 or retcode==10008 immediately after order was sent, then the loop will stop and only 1 order will be opened. This is an ideal case and a good working scenario.
However it can opens 10 orders of the same size if the terminal does not receive retcode==10009 or retcode==10008 immediately after order was sent. I heard that some other people also experiencing the same issues.
How can I stop this multiple order entry problem.
Any suggestion will be really appreciated.
Kind regards.
Which code did you receive when it opens 10 orders ?
Which code did you receive when it opens 10 orders ?
Hello
I received the retcode==10008 for each of the order. It repeated it for 10 times. Kind regards.
for(int i=0;i<10;i++) { volume=NormalizeDouble(volume, lotDigit); if(volume<=0.0) break; if(Type==POSITION_TYPE_SELL) { request.type=ORDER_TYPE_SELL; request.price=SymbolInfoDouble(mSymbol,SYMBOL_BID); if(TP!=0) takeprofit = request.price-TP*mPoint; if(SL!=0) stoploss = request.price+SL*mPoint; } if(Type==POSITION_TYPE_BUY) { request.type=ORDER_TYPE_BUY; request.price=SymbolInfoDouble(mSymbol,SYMBOL_ASK); if(TP!=0) takeprofit = request.price+TP*mPoint; if(SL!=0) stoploss = request.price-SL*mPoint; } request.action = TRADE_ACTION_DEAL; request.symbol = mSymbol; request.volume = MathMin(volume,SymbolInfoDouble(mSymbol,SYMBOL_VOLUME_MAX)); request.sl = stoploss; request.tp = takeprofit; request.deviation=SymbolInfoInteger(mSymbol,SYMBOL_SPREAD); request.type_filling=ORDER_FILLING_FOK; request.comment=DoubleToString(Money,2)+"$"; if(!OrderCheck(request,check)) { if(check.margin_level<100) volume-=SymbolInfoDouble(mSymbol,SYMBOL_VOLUME_STEP); Print("OrderCheck Code: ",check.retcode); continue; } if(!OrderSend(request,result) || result.deal==0 ) { Print("OrderSend Code: ",result.retcode); if(result.retcode==TRADE_RETCODE_TRADE_DISABLED) break; if(result.retcode==TRADE_RETCODE_MARKET_CLOSED) break; if(result.retcode==TRADE_RETCODE_NO_MONEY) break; if(result.retcode==TRADE_RETCODE_TOO_MANY_REQUESTS) Sleep(5000); if(result.retcode==TRADE_RETCODE_FROZEN) break; if(result.retcode==TRADE_RETCODE_CONNECTION) Sleep(15000); if(result.retcode==TRADE_RETCODE_LIMIT_VOLUME) break; } else if(result.retcode==10009 || result.retcode==10008) { Print("OrderSend Code: ",result.retcode); volume-=result.volume; //If order was successful then reduce volume to 0.0, then the loop will be terminated. if(Type == POSITION_TYPE_BUY) {mBuyPositionCnt = mBuyPositionCnt + 1.0; cntLotCalculation = cntLotCalculation + 1;} if(Type == POSITION_TYPE_SELL) {mSellPositionCnt = mSellPositionCnt + 1.0; cntLotCalculation = cntLotCalculation + 1;} break; } Sleep(1000); }
Hello
I received the retcode==10008 for each of the order. It repeated it for 10 times. Kind regards.
It doesn't repeat it in the same loop then, as you have a break here :
else if(result.retcode==10009 || result.retcode==10008) { Print("OrderSend Code: ",result.retcode); volume-=result.volume; //If order was successful then reduce volume to 0.0, then the loop will be terminated. if(Type == POSITION_TYPE_BUY) {mBuyPositionCnt = mBuyPositionCnt + 1.0; cntLotCalculation = cntLotCalculation + 1;} if(Type == POSITION_TYPE_SELL) {mSellPositionCnt = mSellPositionCnt + 1.0; cntLotCalculation = cntLotCalculation + 1;} break; }
Can you post your experts logs to confirm ?
Before this loop you should have a PositionSelect(Symbol()) ?
It doesn't repeat it in the same loop then, as you have a break here :
Can you post your experts logs to confirm ?
Before this loop you should have a PositionSelect(Symbol()) ?
Yes of course. Here is the experts logs.
QS 0 00:00:12.786 EA_v (EURJPY,H1) OrderSend Code: 10008
Also your guess is right. I used PositionSelect(Symbol()) before this code to check the volume of current position.
Kind regards.
Yes of course. Here is the experts logs.
QS 0 00:00:12.786 EA_v (EURJPY,H1) OrderSend Code: 10008
Also your guess is right. I used PositionSelect(Symbol()) before this code to check the volume of current position.
Kind regards.
Ok, so it's well the same problem we are talking in some topics. PositionSelect() is updated from local database of the terminal, and the ticks come too rapidly for this to be updated. Sleep() isn't a reliable method, you have to find a workaround to be sure your position is open before sending a new order.
Forum on trading, automated trading systems and testing trading strategies
doshur, 2013.12.21 03:21
I remember someone who had the same problem and use xxxx.
I could not find that thread, if anyone can help me out that would be a big thanks...
Ok, so it's well the same problem we are talking in some topics. PositionSelect() is updated from local database of the terminal, and the ticks come too rapidly for this to be updated. Sleep() isn't a reliable method, you have to find a workaround to be sure your position is open before sending a new order.
I see. Thanks so much. If PositionSelect() does not work, how about limiting order using PositionsTotal() ? Is PositionsTotal() updated from Broker's database?
I see. Thanks so much. If PositionSelect() does not work, how about limiting order using PositionsTotal() ? Is PositionsTotal() updated from Broker's database?
I don't think so, but you can try it and let us know.
Hi
Has anyone found a working solution to this problem?
It's frustrating to have multiple orders executed when you have proper checks in place.
It doesn't make sense to have PositionSelect updated from a local database when all trade executions happen on a remote broker server.
I believe this should be addressed in future build releases.
Please post your solution.
Thank you,
Forum on trading, automated trading systems and testing trading strategies
Multiple Order Entry Problem for live account with a specific broker
BlindMist, 2014.05.15 02:00
Hi
Has anyone found a working solution to this problem?
It's frustrating to have multiple orders executed when you have proper checks in place.
It doesn't make sense to have PositionSelect updated from a local database when all trade executions happen on a remote broker server.
I believe this should be addressed in future build releases.
Please post your solution.
Thank you,
Hi BlindMist, it does make sense to check your local database to verify if your account is synchronized with the broker server.
Please take a look at the suggested post to address this problem.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear MQL5 users.
I am currently experiencing some multiple order execution problem with my EA but only for a specific broker.
My EA works perfectly in strategy tester. It also works with other brokers in live trading mode too.
With a specific broker, my EA sometime often 10 orders of the same size at the same time.
It seems that the problem is caused by the communication between brokers and terminal.
Below is my current code and the current code checks 10 time if order is executed.
If the EA receive retcode==10009 or retcode==10008 immediately after order was sent, then the loop will stop and only 1 order will be opened. This is an ideal case and a good working scenario.
However it can opens 10 orders of the same size if the terminal does not receive retcode==10009 or retcode==10008 immediately after order was sent. I heard that some other people also experiencing the same issues.
How can I stop this multiple order entry problem.
Any suggestion will be really appreciated.
Kind regards.
for(int i=0;i<10;i++)
{
volume=NormalizeDouble(volume, lotDigit);
if(volume<=0.0) break;
if(Type==POSITION_TYPE_SELL)
{
request.type=ORDER_TYPE_SELL;
request.price=SymbolInfoDouble(mSymbol,SYMBOL_BID);
if(TP!=0) takeprofit = request.price-TP*mPoint;
if(SL!=0) stoploss = request.price+SL*mPoint;
}
if(Type==POSITION_TYPE_BUY)
{
request.type=ORDER_TYPE_BUY;
request.price=SymbolInfoDouble(mSymbol,SYMBOL_ASK);
if(TP!=0) takeprofit = request.price+TP*mPoint;
if(SL!=0) stoploss = request.price-SL*mPoint;
}
request.action = TRADE_ACTION_DEAL;
request.symbol = mSymbol;
request.volume = MathMin(volume,SymbolInfoDouble(mSymbol,SYMBOL_VOLUME_MAX));
request.sl = stoploss;
request.tp = takeprofit;
request.deviation=SymbolInfoInteger(mSymbol,SYMBOL_SPREAD);
request.type_filling=ORDER_FILLING_FOK;
request.comment=DoubleToString(Money,2)+"$";
if(!OrderCheck(request,check))
{
if(check.margin_level<100) volume-=SymbolInfoDouble(mSymbol,SYMBOL_VOLUME_STEP);
Print("OrderCheck Code: ",check.retcode);
continue;
}
if(!OrderSend(request,result) || result.deal==0 )
{
Print("OrderSend Code: ",result.retcode);
if(result.retcode==TRADE_RETCODE_TRADE_DISABLED) break;
if(result.retcode==TRADE_RETCODE_MARKET_CLOSED) break;
if(result.retcode==TRADE_RETCODE_NO_MONEY) break;
if(result.retcode==TRADE_RETCODE_TOO_MANY_REQUESTS) Sleep(5000);
if(result.retcode==TRADE_RETCODE_FROZEN) break;
if(result.retcode==TRADE_RETCODE_CONNECTION) Sleep(15000);
if(result.retcode==TRADE_RETCODE_LIMIT_VOLUME) break;
}
else if(result.retcode==10009 || result.retcode==10008)
{
Print("OrderSend Code: ",result.retcode);
volume-=result.volume; //If order was successful then reduce volume to 0.0, then the loop will be terminated.
if(Type == POSITION_TYPE_BUY) {mBuyPositionCnt = mBuyPositionCnt + 1.0; cntLotCalculation = cntLotCalculation + 1;}
if(Type == POSITION_TYPE_SELL) {mSellPositionCnt = mSellPositionCnt + 1.0; cntLotCalculation = cntLotCalculation + 1;}
break;
}
Sleep(1000);
}