Download MetaTrader 5

Multiple Order Entry Problem for live account with a specific broker

To add comments, please log in or register
Young Ho Seo
22111
Young Ho Seo  

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);
   }
  

 

Alain Verleyen
Moderator
33366
Alain Verleyen  
FinanceEngineer:

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 ?

Forum on trading, automated trading systems and testing trading strategies


Please use the SRC button when you post code. Thank you.




Young Ho Seo
22111
Young Ho Seo  
angevoyageur:

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);
   }
   

 
Alain Verleyen
Moderator
33366
Alain Verleyen  
FinanceEngineer:

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()) ?

Young Ho Seo
22111
Young Ho Seo  
angevoyageur:

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.

 

PF 0 00:00:02.348 EA_v (EURJPY,H1) OrderSend Code: 10008
CE 0 00:00:03.520 EA_v (EURJPY,H1) OrderSend Code: 10008
DI 0 00:00:04.692 EA_v (EURJPY,H1) OrderSend Code: 10008
FL 0 00:00:05.864 EA_v (EURJPY,H1) OrderSend Code: 10008
HS 0 00:00:07.020 EA_v (EURJPY,H1) OrderSend Code: 10008
PF 0 00:00:08.177 EA_v (EURJPY,H1) OrderSend Code: 10008
QJ 0 00:00:09.348 EA_v (EURJPY,H1) OrderSend Code: 10008
KI 0 00:00:10.489 EA_v (EURJPY,H1) OrderSend Code: 10008
HL 0 00:00:11.630 EA_v (EURJPY,H1) OrderSend Code: 10008

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.

 

 

Alain Verleyen
Moderator
33366
Alain Verleyen  
FinanceEngineer:

Yes of course. Here is the experts logs.

 

PF 0 00:00:02.348 EA_v (EURJPY,H1) OrderSend Code: 10008
CE 0 00:00:03.520 EA_v (EURJPY,H1) OrderSend Code: 10008
DI 0 00:00:04.692 EA_v (EURJPY,H1) OrderSend Code: 10008
FL 0 00:00:05.864 EA_v (EURJPY,H1) OrderSend Code: 10008
HS 0 00:00:07.020 EA_v (EURJPY,H1) OrderSend Code: 10008
PF 0 00:00:08.177 EA_v (EURJPY,H1) OrderSend Code: 10008
QJ 0 00:00:09.348 EA_v (EURJPY,H1) OrderSend Code: 10008
KI 0 00:00:10.489 EA_v (EURJPY,H1) OrderSend Code: 10008
HL 0 00:00:11.630 EA_v (EURJPY,H1) OrderSend Code: 10008

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

My EA does a double entry

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


Young Ho Seo
22111
Young Ho Seo  
angevoyageur:

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?

Alain Verleyen
Moderator
33366
Alain Verleyen  
FinanceEngineer:

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.
Young Ho Seo
22111
Young Ho Seo  
angevoyageur:
I don't think so, but you can try it and let us know.
Sure I will do. Regards.
Sergei Krupich
6415
Sergei Krupich  

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,

Rodrigo Malacarne
Moderator
10392
Rodrigo Malacarne  
BlindMist:

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. 

To add comments, please log in or register