indicator value changes when cursor moves

Created an indicator to show the ranking of the latest close within the past N bars. However the indicator's curve changes as the cursor moves across the chart.

Amibroker version is 5.9.0.

_SECTION_BEGIN("Close Ranking");

// Parameters
period_length = Param("Period length", 26, 5, 50, 1);
number_of_bars = Param("Number of Bars for Ranking", 400, 20, 500, 10);

availableBars = Min(BarIndex()+1, number_of_bars);
closeRanking = PercentRank(Close, selectedvalue(availableBars)) / 100;
Plot(closeRanking, "1DC", colorGreen, styleLine);

_SECTION_END();

In the screenshots, moving the cursor causes the indictor in the bottom pane to change shape.


Any ideas? Does using a later version fix it?

It is to be expected to get different values when you change input parameters (here 'periods' of PercentRank function that depends on selected bar)

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

it turns out PercentRank(array, period) accepts an array type variable for the "period" parameter. So there is no issue.