Plot current and prior year high and low on lower time frames


Category:
0
0

Hi Pete, you asked me to post a new question because I was not as clear in my last one. I would like a code that can plot the high and low from the yearly time frame on a chart set to Monthly time frame or lower.

Marked as spam
Posted by (Questions: 2, Answers: 4)
Asked on October 1, 2020 11:47 am
38 views
0
Private answer

Thanks for posting this again. I updated the title of the question to correctly describe this request.

The solution requires that you have at least 360 days of data applied to the chart. This means the lower limit to getting this to work is the 1 hour time frame with 360 days of historical data on the chart.

def highOfYear = high(period = AggregationPeriod.YEAR);
def lowOfYear = low(period = AggregationPeriod.YEAR);
def lastYear = GetLastYear() == GetYear();
plot currentYearHigh = if lastYear then highOfYear else Double.NaN;
plot currentYearLow = if lastYear then lowOfYear else Double.NaN;
rec trackYearHigh = if lastYear <> lastYear[1] then highOfYear[1] else trackYearHigh[1];
rec trackYearLow = if lastYear <> lastYear[1] then lowOfYear[1] else trackYearLow[1];
plot previousYearHigh = if lastYear then trackYearHigh else Double.NaN;
plot previousYearLow = if lastYear then trackYearLow else Double.NaN;

Marked as spam
Posted by (Questions: 37, Answers: 4089)
Answered on October 1, 2020 6:15 pm