Run EA every few seconds

 
I find that running an EA on every tick would be very "noisy". Is there a way to run an EA every n seconds? Does anyone have the code?

Thanks in advance,

Ed
 

EA code run once for every price change.

add codes beloow to you EA:

datetime lasttime = NULL;
int start()
{
   if (Time[0] == lasttime ) return; 
lasttime = Time[0];
 
yarns90401:
I find that running an EA on every tick would be very "noisy". Is there a way to run an EA every n seconds? Does anyone have the code?

Thanks in advance,

Ed
Use a script with infinite loop.
This script will run your code every seconds, regardless of incoming ticks.

int start()
{
while(!IsStopped())
{
Sleep(1000);

//**your code here**

}
}
 
DxdCn:

EA code run once for every price change.

add codes beloow to you EA:

datetime lasttime = NULL;
int start()
{
   if (Time[0] == lasttime ) return; 
lasttime = Time[0];
This will give an execution once for every bar (at the opening price), not at every few seconds.
 
Zap:
Use a script with infinite loop.
This script will run your code every seconds, regardless of incoming ticks.

int start()
{
while(!IsStopped())
{
Sleep(1000);

//**your code here**

}
}



Better to have the sleep after "the code", and let the start() do the loop
int start() {
 
    // your code
 
    Sleep(1000);
}
 
The following variation to DxdCn's stanza makes the EA return quickly on some ticks, and thus enforce at least the given DELAY (in seconds) before going further.
static datetime lasttime = 0;
static int DELAY = 7;
if ( TimeCurrent() < lasttime + DELAY ) return;
lasttime = TimeCurrent();
 
fireflies:

Better to have the sleep after "the code", and let the start() do the loop
int start() {
 
    // your code
 
    Sleep(1000);
}
The only problem with this is, that a script runs only once, so you need the while loop. This is the only way, how you can make your program depend only on time and not at all on ticks
Well, placing of the Sleep can depend on the construction of the code, but you may be right with default placing at the bottom.
 
Zap:
The only problem with this is, that a script runs only once, so you need the while loop. This is the only way, how you can make your program depend only on time and not at all on ticks
Well, placing of the Sleep can depend on the construction of the code, but you may be right with default placing at the bottom.
Probably you're right. But why do you want to keep a script running forever? Doesn't EA do the job?
 
fireflies:
Zap:
The only problem with this is, that a script runs only once, so you need the while loop. This is the only way, how you can make your program depend only on time and not at all on ticks
Well, placing of the Sleep can depend on the construction of the code, but you may be right with default placing at the bottom.
Probably you're right. But why do you want to keep a script running forever? Doesn't EA do the job?
The idea should be to ignore the code in the start procedure if it just ran in the past n seconds. Does calling the sleep function prevent a subsequent tick move prevent the start procedure from executing?
 
if (MathMod(TimeCurrent( ) , 17) ==0))// better to use a prime number 17,23,31 etc
 {
  YOUR CODE
 }
regards ;)
 
What does this mean? How often will the code run?
Reason: