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.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
This script will run your code every seconds, regardless of incoming ticks.
int start()
{
while(!IsStopped())
{
Sleep(1000);
//**your code here**
}
}
DxdCn:
This will give an execution once for every bar (at the opening price), not at every
few seconds.
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];
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**
}
}
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
Well, placing of the Sleep can depend on the construction of the code, but you may be right with default placing at the bottom.
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:
Probably you're right. But why do you want to keep a script running forever? Doesn't
EA do the job?
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.
Well, placing of the Sleep can depend on the construction of the code, but you may be right with default placing at the bottom.
fireflies:
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?
Zap:
Probably you're right. But why do you want to keep a script running forever? Doesn't
EA do the job?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.
Well, placing of the Sleep can depend on the construction of the code, but you may be right with default placing at the bottom.
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?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thanks in advance,
Ed