Problem: Regarding iHigh() and Sleep() in scripts

Back to topics list To post a new topic, please log in or register
avatar
2
wissomechano 2015.02.18 22:57
 

Hello everybody,


I am writing a simple script to do action at some given time, it reads the current time and sleep for some minutes till the event time happens.


The problem which I am facing is that after the sleep finishes, when I want to read the current bar details (iHigh) it gives me the detail of the bar when the script initiated not the current bar.

for example, if the event will happen at 00:30, and the script initiated at 00:25 it will sleep for 5 minutes and then do the action. but at that time h1 will be the iHigh of the 25 minute bar not the 30.

how to solve this?

this is my code:

Sleep(sleeper*1000);

h1=iHigh(Symbol(), PERIOD_M1,0);
l1=iLow(Symbol(), PERIOD_M1,0);
avatar
15
lovromirnik 2015.02.18 23:06 #
 

I'm not really sure here since I'm rather new to the forums, but the way I see it you're getting the info about the current bar each program Tick.
But by using Sleep you don't restart the wait for the next Tick before displaying information, you're displaying it right where you left of. Hence the old information.

Drop in a RefreshRates(); and give it a try...

Sleep(sleeper*1000);
RefreshRates();
h1=iHigh(Symbol(), PERIOD_M1,0);
l1=iLow(Symbol(), PERIOD_M1,0);
avatar
2
wissomechano 2015.02.19 01:36 #
 
yes it worked. thank you
Back to topics list  

To add comments, please log in or register