In Pine-script, I need to assign the value of the previous bar to the current bar based on a condition of the current bar in a custom indicator.
I have tried various methods of coding this resulting in either an internal server error or compile errors.
Pseudo-code:
If currentbar >= upperthreshold
indicatorvalue = value1
Elseif currentbar <= lowerthreshold
indicatorvalue = value2
Else
indicatorvalue = indicatorvalue[currentbar-1]
The expected result is an indicator plot alternating between the 2 values in the pseudo-code provided, since the value of each bar falling between the thresholds is set to the value of the preceding bar.