pausing the algo for X days

 

Hi everyone,

I'm looking for a way to automatically stop\pause my algo for X days in certain cases. Any idea\snippet for that?

Thanks

 
What code have you tried so far?
 
adibi83:

Hi everyone,

I'm looking for a way to automatically stop\pause my algo for X days in certain cases. Any idea\snippet for that?

Why not just return(0); immediately from start when you don't want it to do anything ?
 
I tried it with a "while" loop and used the DayOfYear() function to take X days off.... but I got into infinite loop because the DayOfYear() did not make any update... I think it's because it as stuck on the same tick... will try the "return(0)"... TX
 

I would create a global variable when the EA should start the "pausing" period, the value would be the datetime of next run:

GlobalVariableSet("nextrun", TimeLocal()+86400*3)  // 3 days, 1 day=86400 second

Then at the beginning of the start() I would check for example:

if (TimeLocal()<GlobalVariableGet("nextrun")) { return(0); }

TimeLocal may be any kind of time you calculate with.

This is a simplified example with no error handling, etc.

Reason: