I am trying to calculate value of an indicator using variable lengths as inputs. The length increases with passage of bars until it resets. Pine throws an error saying it cannot determine the length of the referencing series. What am I doing wrong?
indicator(...,max_bars_back=5000)
cidx = bar_index
varLen = cidx-nz(ta.valuewhen(cond==1 and cond[1]==0, bar_index, 0)) + 1
varLen2 = cidx-nz(ta.valuewhen(cond==1 and cond[1]==0, bar_index, 1)) + 1
indiVal = indicator(x,y,varLen)
indiVal2 = indicator(x,y,varLen2)
The above throws an error about max bars back. Even if I try the workaround below, I am still getting the same error:
final_varLen = math.min(varLen,100)
Also, playing with max_bars_back in indicator settings or max_bars_back as a function does not help. I also printed the values of the varLen and varLen2 without any trouble but when I use them as inputs, it falls apart. Any ideas why?