How to plot Range High/Low for the previous N days?

Hello everyone,

I am new to AFL and have been exploring it a bit..I'm trying to plot range high and low of the previous 4 days, but the problem is my code returns me the the results considering the current bar. I need to exclude the current bar from my range high/low and plot the lines exactly as they are now for the past N days. As per my current level of knowledge I have used HHV/LLV function. Any help would be much appreciated.. :slight_smile:

Here's my code - `/*
Objective:

  1. add chart settings
  2. add price
  3. consider range high and low of previous 4 days (excluding current bar)
  4. add lines to the highest and lowest points.
    */
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
		_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
			Plot( C, "Close", ParamColor("Color", colorDefault), styleThick | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("RHRL");
	Plot(HHV(High,4), "RH", colorRed, styleLine);
	Plot(LLV(Low,4), "RL", colorGreen, styleLine);
_SECTION_END();

And here's a screenshot -
Screenshot%20(3)

As manual says... HHV and LLV include "current" bar:

Calculates the highest value in the ARRAY over the preceding periods ( periods includes the current day).

So to exclude current day one may use Ref() function:

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
		_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
			Plot( C, "Close", ParamColor("Color", colorDefault), styleThick | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("RHRL");
	Plot(Ref(HHV(High,4), -1), "RH (excl. 'current' bar)", colorRed, styleLine);
	Plot(Ref(LLV(Low,4), -1), "RL (excl. 'current' bar)", colorGreen, styleLine);
_SECTION_END();

2 Likes

Thanks a ton @fxshrat. Appreciate it ! :smiley: