Marking Out of Session Bars

Hi All,

The following script can be used to mark out of session bars on an intraday chart. The following example has been setup using US Equities via IQ Feed. The session times are 9.30am to 4.00pm.

With the following script we can mark all bars outside of the above range as red, making them easy to identify.

//Find the full bar date with intraday decimals
V1 = BARDATE() ;
//Find the daily bar date, without decimals
V2 = ROUND(V1, DECIMALTYPE=0) ;
//Reduce bar date to intraday range only
V3 = V1 - V2;
//Identify Out of Session Range
V4 = (V3 < 0.395555) and (V3 > -0.333);
//Mark Out of Session Range
V4

The script uses the BarDate() function, on intraday charts the values have decimal places (44,049.67 for example). On a daily chart there are no decimals, so by reducing the bar date down to decimal values only we have a range to work with going from a value of -0.5 to +0.5.

Example2

Example of the V3 line outputting the intraday BarDate() range.

Using the output from V3 we can then identify the values outside of the active session and set them up (V4 line of the script).

We can use this script on a bar chart that is set to a custom colour scheme:

Example3

The final results look like this:

Example1

This script can be updated to work on any exchange, all you need to do is identify the range you wish to mark as red, and update the V4 variable to match.