Timer

 
Hello,

I searched for CodeBase and articles. Without success.

I would like a simple code.

Run from - to.

Thanks

 
int НачалоРаботноВреме = 9;
int КрайРаботноВреме = 19;  
MqlDateTime тудей;

TimeToStruct(TimeCurrent(),тудей);
if(тудей.hour<НачалоРаботноВреме || тудей.hour>КрайРаботноВреме) return(false);
 
kypa:

Excuse me in ENG? sorry

 
Stanislav Milka: Excuse me in ENG?

Is it too hard to just change the variable names?

int v1 = 9;
int v2 = 19;  
MqlDateTime v3;

TimeToStruct(TimeCurrent(),v3);
if(v3.hour<v1 || v3.hour>v2) return(false);
 

Hi, when I use your advice, it throws me a mistake.


"{" - function definition unexpected 

Please help :)



//+------------------------------------------------------------------+
//| Čas                                                              |
//+------------------------------------------------------------------+
   {;
   int v1 = 20;
   int v2 = 07;  
   MqlDateTime v3;

   TimeToStruct(TimeCurrent(),v3);
   if(v3.hour<v1 || v3.hour>v2) return(false);  }

//+------------------------------------------------------------------+
//| Obchod                                         |
//+------------------------------------------------------------------+

void OnTick() {

    {;
  OrderSend;
     ;}
  
     {;
  OrderSend;
   ;}
   return;}

The error is on the line  "   {;  "

 

This is Another more elegant way of putting a timer (time permissons) for an expert advisor to trade on certian hours of a day. Simply make an Array of 24 positions like a day has 24 hours. In every position you now have a switch where you allow/disable the trading hours :)

int permissions[24] = {1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; // in this example allow trade from 6 to 21:59
               //hours 0 1 2 3 4 5 6 7 8 91011121314151617181920212223
...
if(permissions[TimeHour(TimeCurrent())]) {
    // trade allowed
}
 
Kenneth Parling:

This is Another more elegant way of putting a timer (time permissons) for an expert advisor to trade on certian hours of a day. Simply make an Array of 24 positions like a day has 24 hours. In every position you now have a switch where you allow/disable the trading hours :)

OK thank you


But how do I use it?



Error again: 'if' - expressions are not allowed on a global scope  16 4

 
 void OnTick()
{
     if( timeCheck(7, 20) )
     {
           /* work */
     }
}

bool timeCheck(const int _start=0, const int _stop=24)
{
     if(_start==_stop) return true;

     MqlDateTime sTime;
     TimeToStruct(TimeCurrent(), sTime);
     
     if(_start<_stop)
     {
          if (sTime.hour<_start)
               return false;
          if (sTime.hour>=_stop)
               return false;
     }
     else
           if(sTime.hour<_start && sTime.hour>=_stop)
               return false;
     return true;
}
Something like that. Did not check.
 
Konstantin Nikitin:
Something like that. Did not check.

Thank you very much for the answer.


in compiler it's written well ...


Unfortunately, however, there was no change in EA trading 24 hours a day.

 
Stanislav Milka:

Thank you very much for the answer.


in compiler it's written well ...


Unfortunately, however, there was no change in EA trading 24 hours a day.

I wrote you a PM 8 days ago.....obveously you didn't read it? I can assist you coding my example of timer into your code so it works properly.
 

Massage icon

Check this Icon to view your private messages

Reason: