MQL4 - automated forex trading   /  

Forum

Run EA every few seconds

Back to topics list  | 1 2 To post a new topic, please log in or register

avatar
18
old_man 2007.07.19 02:31 
yarns90401 wrote:
What does this mean? How often will the code run?

depends on the second parameter of the mathmod function\  timecurrent returns the total number of seconds since 1970 , so by finding the reminder of the division of the current time by the number of seconds you want the code to be activated at , your problem will be solved , try it , the 17 means that the code will be executed every 17 seconds

avatar
18
old_man 2007.07.19 02:44 

OR

int count =0; //defined globaly
 
 
int start()
{
if (count==5) // 5 is the number of ticks u want to skip 
{ 
 count =0;
 YOUR CODE
}
else
count++;
}
hope this is easier :)

avatar
231
fireflies 2007.07.19 11:35 
yarns90401 wrote:
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?
No more than one call to start() at a time. If there is another tick coming in while current start() is still in process, the newer tick is ignored. So Sleep()-ing will ignore all those ticks.

avatar
231
fireflies 2007.07.19 11:38 
old_man wrote:
if (MathMod(TimeCurrent( ) , 17) ==0))// better to use a prime number 17,23,31 etc
 {
  YOUR CODE
 }
Nice but may not work all the time. Suppose last tick as at t=16, and because it's a slow day, the next one instead of at t=17, it comes at t=18. You'll miss one whole cycle, and may be more.

avatar
18
old_man 2007.07.19 15:54 
fireflies wrote:
old_man wrote:
if (MathMod(TimeCurrent( ) , 17) ==0))// better to use a prime number 17,23,31 etc
 {
  YOUR CODE
 }
Nice but may not work all the time. Suppose last tick as at t=16, and because it's a slow day, the next one instead of at t=17, it comes at t=18. You'll miss one whole cycle, and may be more.

you are right, i realized that after i had posted it.  however tthe second solution is better . note that it skip ticks not seconds

avatar
125
Zap 2007.07.19 19:28 
fireflies wrote:

Probably you're right. But why do you want to keep a script running forever? Doesn't EA do the job?
The script doesn't have to run forever, just until stopped (just like an EA) , an the question was: "Is there a way to run an EA every n seconds?" My code does exactly this. Why would one need this? I don't know, maybe I misunderstood something.
Back to topics list   | 1 2  

To add comments, please log in or register