Retry if IsTradeContxtBusy()

 

Hi all,

I'm using 4 instances on an EA and want to prevent for conflicts.

The code that I though to use is as follow 

         if(......)
         while(IsTradeContextBusy()) Sleep(10);
                       RefreshRates();
         Ticket=OrderSend(Symbol(),OP_BUYSTOP,LotSize,PendingBuyPrice,UseSlippage,BuyStopLoss,BuyTakeProfit,"Buy Stop Order",MagicNumber,0,Green);
         if(Ticket>0)
           {//11
            if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY Stop Order Opened : ",OrderOpenPrice());
           }//11
        else Print("Error opening BUY Stop Order : ",GetLastError());
           }//8

 Is that enough or is that necessary to add a Retry as follow

int Retries;
                    int MaxTries;
                    int Ticket;
                    while(Ticket <=0)
                    {   
         Ticket=OrderSend(Symbol(),OP_BUYSTOP,LotSize,PendingBuyPrice,UseSlippage,BuyStopLoss,BuyTakeProfit,"Buy Stop Order",MagicNumber,0,Green);
         if(Retries <=MaxRetries)Retries++;
         else break;
         }

 Thank you in advance for any clarification provided

Luis 

 
luisneves:

Hi all,

I'm using 4 instances on an EA and want to prevent for conflicts.

The code that I though to use is as follow 

 Is that enough or is that necessary to add a Retry as follow

 Thank you in advance for any clarification provided

Luis 

If you are using a recent Build there shouldn't be any conflicts as there can be upto 8 trade threads . . .  if you need more you can use a Mutex,  or read this: https://www.mql5.com/en/forum/141799