Plot previous HLC without extended hours on


Category:
0
0

Hi Pete,

Could you please help me out with the code below as I’d like to have it plot correctly for normal market hours as well? At the moment it only shows it correctly if extended hours is enabled.

Thanks

Attachments:
RESOLVED
Marked as spam
Posted by (Questions: 4, Answers: 2)
Asked on August 2, 2020 4:27 pm
143 views
0
Private answer

The solution entirely depends on what data you want to plot.

If all you are trying to do is to plot the High, Low and Close from the previous day but not include the extended trading session there is a much simpler way to do that:

def okToPlot = GetDay() == GetLastDay();
plot prevDayHigh = if okToPlot then high(period = AggregationPeriod.DAY)[1] else Double.NaN;
plot prevDayLow = if okToPlot then low(period = AggregationPeriod.DAY)[1] else Double.NaN;
plot prevDayClose = if okToPlot then close(period = AggregationPeriod.DAY)[1] else Double.NaN;

However if you are trying to include extended hours high and low while excluding the extended hours session from your chart it is 100% completely impossible to do.

Just an FYI to the newbies trying to learn how to write code. Don't try to learn from the code provided by the author of this post. That code is hideous. Looks like it was written by an engineer. Brute force all the way. 20 lines of code to accomplish the same task that can be completed in 3. Scary stuff.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 2, 2020 5:49 pm
0
Thank you for the much simpler version of the code. How get I get it to plot only the last HLC? The one you shared above plot them for every day on the chart time frame.
( at August 3, 2020 6:03 am)
0
I have updated the code in my answer to restrict the plots to only the current session.
( at August 3, 2020 8:30 am)