HHV and LLV between specific Dates

Hi Folks,
I am trying to explore the results with HHV and LLV values between two specific dates. For example, I want to know what was the highest high and lowest low for a list of stocks between Oct-07 and Oct-14. The following code just gives me the last 7 days HHV and LLV which is incorrect. Could you please help me out with this? Thanks a ton.

StartDate = ParamDate( "StartDate", "2024-10-07",0 );
EndDate = ParamDate( "EndDate", "2024-10-14",0 );
TotalDays = EndDate - StartDate;

HighBtw = HHV(High,TotalDays);
LowBtw = LLV(Low,TotalDays);

Filter = 1;
AddColumn(HighBtw,"HighBtw",1.2);
AddColumn(LowBtw,"LowBtw",1.2);
_SECTION_END();

Hello RaMb0, HHV and LLV function are not the proper functions for your task in my opinion. According to the manual they "they calculates the highest (lowest) value in the array over the preceding periods". If you would investigate the highest and the lowest values between any two dates, you could call highest() and lowest() functions instead.

For example you could try in this way:

dt = DateTime();
startDate = StrToDateTime("2024-10-07");
endDate = StrToDateTime("2024-10-14");

hVals = IIf(dt >= startDate AND dt <= endDate, H, Null);
lVals = IIf(dt >= startDate AND dt <= endDate, L, Null);
oVals = IIf(dt >= startDate AND dt <= endDate, O, Null);	// calculated only for plotting the bars
cVals = IIf(dt >= startDate AND dt <= endDate, C, Null);	// calculated only for plotting the bars

HighBtw = Highest(hVals);
LowBtw = Lowest(lVals);

PlotOHLC(oVals,hVals,lVals,cVals,"",colorBlack,styleBar);
SetChartOptions(0, chartShowDates);
Title = "highest is " + NumToStr(HighBtw, 1.3) + "\nlowest is " + NumToStr(lowBtw, 1.3);

Hi 2DD,

Thanks for the logic. It makes sense. To start, I tried the code to explore the result. High is working but low shows blank. Let me explore why and will get back to you.

dt = DateTime();
startDate = StrToDateTime("2024-10-07");
endDate = StrToDateTime("2024-10-14");

hVals = IIf(dt >= startDate AND dt <= endDate, H, Null);
lVals = IIf(dt >= startDate AND dt <= endDate, L, Null);
//oVals = IIf(dt >= startDate AND dt <= endDate, O, Null);	// calculated only for plotting the bars
//cVals = IIf(dt >= startDate AND dt <= endDate, C, Null);	// calculated only for plotting the bars

HighBtw = Highest(hVals);
LowBtw = Lowest(lVals);

Filter = 1;
AddColumn(HighBtw,"HighBtw",1.2);
AddColumn(LowBtw,"LowBtw",1.2);
AddColumn(Close,"Close",1.2);

Hi RaMb0, it looks like the issue might related to the values of startDate and endDate. Could you verify if the days you're investigating are correct? Unfortunately the days are not visible in your screenshot, but it's possible that you are analyzing prices beyond 2024-10-14.