Afl problem regarding LLV and HHV functions with specific RANGE

Hi, I am having a problem with the function HHV. The problem is that the formula as I have stated it is not responsive to the range that I select. As you can see below, I am stating a range of 10 periods but it always gives back the same result so the RANGE is not written properly.

please any advice as to the error I am making?

SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} , %g (%.1f%%) {{VALUES}}",  C, SelectedValue( ROC( C, 1 ) ) ));
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} , (%.1f%%) {{VALUES}}",   SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

BarrasAtrasMaxMin = 10 ;

Min1 = LastValue ( LLV ( Close , -BarrasAtrasMaxMin ) );
Max1 = LastValue ( HHV ( Close , -BarrasAtrasMaxMin ) );

Plot( Max1,"max", colorLightBlue , styleLine );type or paste code here

imagen

Afl problem regarding LLV and HHV functions with specific RANGE

There isn't AFL problem. Both functions work perfectly fine.


LastValue function returns single element of array so you only get single value at last bar or array
If you want array output you should remove LastValue function.
Recommended reading: Understanding how AFL works

Also you should use positive value as second argument.

SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} , %g (%.1f%%) {{VALUES}}",  C, SelectedValue( ROC( C, 1 ) ) ));
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} , (%.1f%%) {{VALUES}}",   SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

BarrasAtrasMaxMin = 10 ;

Min1 = LLV ( Close , BarrasAtrasMaxMin );
Max1 = HHV ( Close , BarrasAtrasMaxMin );

Plot( Max1,"max", colorLightBlue , styleLine );
Plot( Min1,"min", colorRed , styleLine );

Or if you are after returning single value at selection on chart then rather use SelectedValue() function instead of LastValue()

SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} , %g (%.1f%%) {{VALUES}}",  C, SelectedValue( ROC( C, 1 ) ) ));
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} , (%.1f%%) {{VALUES}}",   SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

BarrasAtrasMaxMin = 10 ;

Min1 = SelectedValue( LLV ( Close , BarrasAtrasMaxMin ) );
Max1 = SelectedValue( HHV ( Close , BarrasAtrasMaxMin ) );

Plot( Max1,"max", colorLightBlue , styleLine );
Plot( Min1,"min", colorRed , styleLine );
4 Likes

thank you again fxshrat, I look blind as to check the AFL Function Reference and not see that there is no MINUS sign. The SelectedValue function I did not know. Thanks.

1 Like