timing

 

Hi I I have this EA and I was wondering how to make it wait 1 minute after it gives me an alert before it does its job again. 

 currently it is echoing the alert nonstop until it meets its goal. what code do I use ?  

 

You can use the OnMillisecondTimer() function, or use the datetime open of the M1 timeframe then it will alert on every new 1 minute candle if the condition is still true.




 
Reco Daley:

Hi I I have this EA and I was wondering how to make it wait 1 minute after it gives me an alert before it does its job again. 

 currently it is echoing the alert nonstop until it meets its goal. what code do I use ?  

Just set a flag (and a delay) and check it before alerting again. It's basic coding!

If however you are not a coder then place a Job request in the Freelance section and hire someone to do it for you!

 
Reco Daley:

Hi I I have this EA and I was wondering how to make it wait 1 minute after it gives me an alert before it does its job again. 

 currently it is echoing the alert nonstop until it meets its goal. what code do I use ?  

I would define a (global or static) datetime variable nxtAlert and set it to:

   if (... && TimeCurrent() > nextAlert ) {
       Alert(...)
       nextAlert = TimeCurrent() + 60;
       ...
   }
No Sleep => no blocking of anything else.
 
Sleep(60*1000);

RefreshRates();
 
Fstrifoerr8:
Sleep(60*1000);

RefreshRates();

I don't think "Sleep" is ideal here as one wants an EA to continue responding to ticks and carry out other tasks. The OP just does not want the "Alert" to continue being triggered during that time.

Hence, why he should just use a flag (Boolean Variable), to know when the Alert has first been triggered and thus let some time go by before resting the flag again.

Carl's suggestion is much more applicable to this case!

 

The simplest and correct answer was provided, you don't need to use sleep or a boolean :

Forum on trading, automated trading systems and testing trading strategies

timing

Carl Schreiber, 2016.11.04 20:25

I would define a (global or static) datetime variable nxtAlert and set it to:

   if (... && TimeCurrent() > nextAlert ) {
       Alert(...)
       nextAlert = TimeCurrent() + 60;
       ...
   }
No Sleep => no blocking of anything else.

 
Fernando Carreiro:

I don't think "Sleep" is ideal here as one wants an EA to continue responding to ticks and carry out other tasks. The OP just does not want the "Alert" to continue being triggered during that time.

Hence, why he should just use a flag (Boolean Variable), to know when the Alert has first been triggered and thus let some time go by before resting the flag again.

Carl's suggestion is much more applicable to this case!

Maybe. But if we see all code, maybe Sleep() can be used too.
 
Fstrifoerr8:
Maybe. But if we see all code, maybe Sleep() can be used too.
No it can't. Please read the question again.
 
Fernando Carreiro:
Do we have another troll here?

Thanks to you all the 

Sleep(60*1000);

RefreshRates();

 Seemed to have done the job.

 
Reco Daley:

Thanks to you all the 

Sleep(60*1000);

RefreshRates();

 Seemed to have done the job.

Did you even read the posts and reasons why that solution is not ideal?
Reason: