start() function running too many times?

 
Greetings,

I have just begun writing my first EA, but I need some help from the gurus and veterans of MQL4. I have experience writing code in C++ so I'm pretty comfortable writing in MQL4. But for some reason I can't figure this one out.

I'm writing a simple program to update the stoploss of my trades. The EA is attached to a chart using the H1 timefram. Now from my understanding I believe the start() function should run every time a new quote is received by the chart. So start() would run at the beginning of every hour right? Or am I missing something?

Anyways, the problem is that start() is actually running every few minutes not once in an hour. So when start() runs multiple times in the same hour it tries to update the order with the same data, resulting in error code 1 because the data only changes hourly.

I know the start() function is running multiple time because I have put in Print statements in the function for debugging. It's not being caused by a loop running more times than expected. I can provide the code if anyone wants to look at it.

Please help me shed some light on this problem. Thanks in advance.
 
start() is called on every incoming TICKS, that is every price changes, which happen usually a couple thousand times per hour.
If you want your EA to run once per hour, check for Hour() change.
 
Zap:
start() is called on every incoming TICKS, that is every price changes, which happen usually a couple thousand times per hour.
If you want your EA to run once per hour, check for Hour() change.
Thanks Zap. That clears it up for me.
 
superalf:
Zap:
start() is called on every incoming TICKS, that is every price changes, which happen usually a couple thousand times per hour.
If you want your EA to run once per hour, check for Hour() change.
Thanks Zap. That clears it up for me.


If your EA is attached to H1 chart and want to do calculation once in one hour use following code:

//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;

Reason: