Sleep and RefreshRates

Back to topics list To post a new topic, please log in or register
avatar
57
eempc 2014.02.08 13:55
 

I've noticed some codes Sleep at the start of a code then Refreshes to update values before continuing with the rest.

Is it not better to Sleep at the end of the code? Then RefreshRates is not required?

edit: should probably specify purpose: to make sure the code only runs once per second for example Sleep(1000)

avatar
Moderator
3206
angevoyageur 2014.02.08 15:17 #
 
eempc:

I've noticed some codes Sleep at the start of a code then Refreshes to update values before continuing with the rest.

Is it not better to Sleep at the end of the code? Then RefreshRates is not required?

edit: should probably specify purpose: to make sure the code only runs once per second for example Sleep(1000)

f you want your code to run every second you can now use the OnTimer() event handler. But you have to use RefreshRates().

avatar
1109
Ovo 2014.02.08 15:29 #
 
angevoyageur:
f you want your code to run every second you can now use the OnTimer() event handler. But you have to use RefreshRates().


Is there any available information that OnTimer event has out of date rates and therefore RefreshRates() is mandatory? Just curious, because I would not expect it at all.
avatar
Moderator
3206
angevoyageur 2014.02.08 20:13 #
 
Ovo:

Is there any available information that OnTimer event has out of date rates and therefore RefreshRates() is mandatory? Just curious, because I would not expect it at all.
You are right, I didn't check. It's only a supposition. We will see when Market will be opened.
avatar
123
maj1es2tic 2015.09.07 16:12 #
 

This is absolutely true and confirmed for OFFLINE charts at least, as of MT4 Build 840. I've been trying to get an EA to run on an offline chart for a few hours now. Every time OnTimer() kicks off (50ms intervals), Time[0] and iTime() and Close[0] are always always from the last bar as of the time the EA was added to the chart, no matter how many bars have been created since the last OnTimer() event had ran. I decided to add RefreshRates() to force it, and it immediately started working as expected. 

I had been using an isNewBar() function that works fine in Strategy Testers, but never on an offline chart directly.  RefreshRates() was the culprit. Heres my newest revision for isNewBar() if anyone is interested.

 

Now, I just call isNewBar(Time[0]) ... But you can call it with iTime() as well, in case you're looking at another chart for some reason.

/*********************************************************
* Bar Functions
**********************************************************/
bool isNewBar(datetime now) {
   static datetime _currentTime;
   if (_currentTime != now) {
      _currentTime = now;
      return (true);
   }   
   return (false);
}
angevoyageur
:

You are right, I didn't check. It's only a supposition. We will see when Market will be opened.
Back to topics list  

To add comments, please log in or register