December 28, 2007
Real-Time Bar-Period Timing
In real-time trading one often needs to know when a new period starts and how much time there is left before the period ends. The code below provides this information. Be sure to synchronize your system’s clock.
<p>function GetSecondNum() <p>{ <p>Time = Now(4); <p>Seconds = int(Time%100); <p>Minutes = int(Time/100%100); <p>Hours = int(Time/10000%100); <p>SecondNum= int(Hours*60*60+Minutes*60+Seconds); <p>return SecondNum; <p>} <p> <p>RequestTimedRefresh(1); <p>TimeFrame = Interval(); <p>SecNumber = GetSecondNum(); <p>Newperiod = SecNumber%TimeFrame == 0; <p>SecsLeft = SecNumber-int(SecNumber/TimeFrame)*TimeFrame; <p>SecsToGo = TimeFrame - SecsLeft; <p>if( NewPeriod ) <p>{ <p>Say("New period"); <p>Plot(1,"",colorYellow,styleArea|styleOwnScale,0,1); <p>} <p>Title = "\n"+ <p>"time: "+Now(2)+"\n"+ <p>"Interval: "+NumToStr(TimeFrame,1.0)+"\n"+ <p>"Second Number: "+NumToStr(SecNumber,1.0,False)+"\n"+ <p>"Seconds Left: "+NumToStr(SecsLeft,1.0,False)+"\n"+ <p>"Seconds To Go: "+NumToStr(SecsToGo,1.0,False); <p>
For testing and code verification timing is displayed in the chart title:
Filed by Herman at 12:42 pm under Real-Time AFL Programming
Comments Off on Real-Time Bar-Period Timing