I am trying to make a trailingstop multiple of the ATR, since a buy or sell signal has occured. Naturally I try the barssince(long) function, to determine the amount of bars since the buy signal. Then I use the highest function to find the highest ATR value since my buy signal. My code is:
atr = atr(input(defval=14, title="ATR"))
Multip = input(0.2, minval = 0)
lower = low - atr * Multip
upper = high + atr * Multip
barssincelong = barssince(long)
barssinceshort = barssince(short)
islong = barssincelong < barssinceshort
plotlower= highest(lower, barssincelong)
plotupper= lowest(upper, barssinceshort)
stoplossline = islong ? plotlower : plotupper
plot(stoplossline)
"long" and "short" are defined in the code above that, but that is irrelevant.
For some odd reason, this script gives a Study Error that says:
"Invalid value of the 'length' argument (0) in the 'highest' function. It must be > 0.
Can someone help me with this problem?
The function
barssincereturns the valuenaif no bar with the specified conditions is found. This situation is possible on the very first bars. For the functionshighestandlowestthe argumentlengthgreater than zero must be specified. You need to define in the script how to handle such situations.