This study is a very simple example of how to use the time functions in thinkScript. This will plot the close during market hours only (8:30am CT – 3:00pm CT) and it will plot 0 if outside of the time range. Please note that the closing bar is not the bar at () rather, it is the last bar before that time. Thus, as you can see, the logic in evaluating the end function (which is the function that tells us when the market closes) excludes zero as the bar at 1600 isn’t included in the market hours. However, the begin function includes zero (greater than or equal to expression) as the market open does include the bar ().
Please recall that the time functions in thinkScript only will work if you use 24-hour time format and it is stated in Eastern Time.
Note, for simplicity and layout purposes, this study has been coded as a lower study...
!!! FOR EDUCATIONAL PURPOSES ONLY !!!! PLEASE READ DISCLAIMER POST!
input begin_time = 930;
input end_time = 1600;
def begin = secondstilltime(begin_time);
def end = secondstilltime(end_time);
plot data = if(begin<=0 and end>0,close,0);