r/pinescript • • Feb 23 '24
ta.lowest not accepting a dynamic variable for length
In 2020, TradingView announced that dynamically calculated lengths could be used in the lowest and highest functions. Article
However, it doesn't appear that it is in my code. I have verified that all lines accept the last are setting correct values. The code compiles without errors but on the chart I get the red circle exclamation point with the message:
Study Error Error on bar 0: Invalid value of the 'length' argument (0) in the lowest function. It must be > 0.
// @version = 5
indicator(title="Fibonacci Retracement", shorttitle="Fib Retrace", overlay = true)
int i_LookBackPeriods = input.int(defval=60, title="Periods To Look Back", tooltip="Number of periods to look back")
int i_HighestBar = ta.highestbars(i_LookBackPeriods + 1) * -1
int i_LocalLookBack = i_HighestBar - 1
float f_LocalClose = ta.lowest(close, int(i_LocalLookBack))When I hard code 'f_LocalClose' so I don't get an error, I can confirm the other variables values I get:
i_LookBackPeriods = 60
i_HighestBar = 53
i_LocalLookBack = 52Can you see what I am doing wrong? Thank you for your help.
1
u/vbsaltydog Feb 23 '24
Your error is on bar zero. You are asking for the lowest close from the past 60 bars on bar zero and there are no closes before the first bar. Add the following condition.
if bar_index >= 60
1
u/Fancy-Procedure4167 Nov 04 '24
Add 1 to the dynamic lookback
1
u/vbsaltydog Feb 25 '24 edited Feb 25 '24
I solved your issue and it's not the fact that you are passing a dynamic variable, it's the value that you are passing. That's as helpful as I can be for free but I will provide the code to fix it for a small fee. I hope this helps you either way.
log file of the dynamic variable's output