Trade context busy, three attempts

 

Hi.

I'm using IsTradeAllowed () in a while loop (while (IsTradeAllowed () == false)) but only makes three attempts, after exit the loop. I would like not to go out of the loop until the order is placed. Can anyone help? 

Thanks. 

 
do you have a sleep within you loop?
 
Yes, Sleep (750)
 
Due to the fact that you haven't post your code I have to assume the problem is in your code.
 
Jusyer: while loop (while (IsTradeAllowed () == false)) but only makes three attempts, after exit the loop.
I can think of only two ways this could happen:
  1. You coded it to exit after three attempts.
  2. You coded an indicator. Indicators can not sleep. Indicators can not trade. They MUST return to the GUI.
 
while (IsTradeAllowed()==false)
         {
            RefreshRates();
            ticket=OrderSend(Symbol(),OP_SELL,auxImporte,Bid,3,0,0,"BO exp:60",magic); 
            Sleep(750);
         }
It's EA, no indicator.
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Your code says: if trading is not allowed, try to open an order. Makes no sense. If trading is not allowed, you should be sleeping. Then once it is allowed, you need to check if the trade still makes sense.
  3. You need RefreshRates() after sleeping.
  4. Check your return codes (OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
 
Sorry for my short explanation, but my English is not very good. 
The EA works correctly in 8 pairs, the problem exists when an order sent several pairs at once. When the order (1) can not be sent, then the EA enters this loop, then try again to launch the order (2), if it can send the order, the EA out of the loop, if it can not, try again, but this time if it can not send the order (3), the EA out of the loop. 

Therefore, do not understand why the third time EA exits the loop.

         ...
         ticket=OrderSend(Symbol(),OP_SELL,auxImporte,Bid,3,0,0,"BO exp:60",magic);
         while (IsTradeAllowed()==false)
         {
            Sleep(750);
            RefreshRates();
            ticket=OrderSend(Symbol(),OP_SELL,auxImporte,Bid,3,0,0,"BO exp:60",magic); 
            
         }
         ...

 

 

 
Any ideas?
Reason: