Download MetaTrader 5

Trade context busy, three attempts

To add comments, please log in or register
Jusyer
41
Jusyer  

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. 

Carl Schreiber
7092
Carl Schreiber  
do you have a sleep within you loop?
Jusyer
41
Jusyer  
Yes, Sleep (750)
Carl Schreiber
7092
Carl Schreiber  
Due to the fact that you haven't post your code I have to assume the problem is in your code.
whroeder1
15577
whroeder1  
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.
Jusyer
41
Jusyer  
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.
whroeder1
15577
whroeder1  
  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
Jusyer
41
Jusyer  
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); 
            
         }
         ...

 

 

Jusyer
41
Jusyer  
Any ideas?
To add comments, please log in or register