Download MetaTrader 5
To add comments, please log in or register
Share your programs. That will improve your rating.
Jusyer
41
Jusyer 2014.10.30 10:24 

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
5962
Carl Schreiber 2014.10.30 10:29  
do you have a sleep within you loop?
Jusyer
41
Jusyer 2014.10.30 11:03  
Yes, Sleep (750)
Carl Schreiber
5962
Carl Schreiber 2014.10.30 12:11  
Due to the fact that you haven't post your code I have to assume the problem is in your code.
whroeder1
13644
whroeder1 2014.10.30 12:16  
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 2014.10.30 19:04  
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
13644
whroeder1 2014.10.30 19:36  
  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 2014.10.31 03:18  
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 2014.11.23 10:40  
Any ideas?
/
To add comments, please log in or register