I have this function that takes top and bottom values (Candle Index) as inputs and returns the candle index which has highest high between those two candles
// Function to find highest bar index within a specified window
f_find_highest_bar_index(bot, top) =>
var float hi = 10e-10
var float lo = 10e10
var int highestBarIndex = na
bool window = bar_index >= bot and bar_index <= int(top)
if (window)
if (high > hi)
hi := high
highestBarIndex := bar_index
if (low < lo)
lo := low
// Return the highest bar index
highestBarIndex
Code works fine and returns 6670 currectly if i pass constant for top value (see image 1)
top = 6671
But as soon as i pass variable retracementBarIndex in top variable, it returns wrong value 6672, while it should also return 6670. See second image
Cannot quire understand why is this happening?
2
It can’t be discerned based on the information provided. There’s no demonstration of how retracementBarIndex
is determined.
That’s where your issue probably is.