problem calcul with orderopentime

 

Yo,

I want to take order one by one. I mean when one order is open, he can't open an other while the other is still open.

And i don't want that he can close an order until a few time has spent between the order open time and one hour (by exemple)


So i wrote a code and It seems It works only for the first order. Tehn, he close order while wait the cooldown...

Where i'm wrong ?

Here's my code :

   if(OrdersTotal()>=1) 
   {
      for(int b=1; b>=OrdersTotal(); b++)
      {  
         if(OrderSelect(b-1, SELECT_BY_POS)==true)
         {
            if (TimeCurrent() >= (OrderOpenTime()+4500000))
            {
etc...
 
Bad_Bond: It works only for the first order. Tehn, he close order while wait the cooldown...
  1. for(int b=1; b>=OrdersTotal(); b++)

  2. Your OrderSelect loop means the EA is incompatible with every other, including itself on other charts and manual trading. https://www.mql5.com/en/forum/145507
  3. if(OrderSelect(b-1, SELECT_BY_POS)==true)
    You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Reading the code out loud becomes "if order is selected is true" You would never say the "is true" part. Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled.
  4. if (TimeCurrent() >= (OrderOpenTime()+4500000))
    When the order closes your for loop does nothing, so there is no "cooldown." You must remember that before the order closes.
    static datetime cooldown=0;
    if(TimeCurrent() < cooldown) return;
    for(int b=OrdersTotal() - 1; b>=0; --b)
      if(OrderSelect(b, SELECT_BY_POS)
      && and my magic number
      && and my pair        
        ){
         #define DAYS52 4500000         // What you wrote
         #define HOUR1 (PERIOD_H1 * 60) // What you meant "one hour (by exemple)"
         if (cooldown < OrderOpenTime()+DAYS52) cooldown = OrderOpenTime()+DAYS52;
    }
 

thanks a lot

I don't understand why there is no more cooldown...

and why, one year ago, my ea didn't make this error...

Reason: