Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

pine script - How can I fix the Study Error: "Invalid value of the 'length' argument (0) in the 'highest' function. It must be > 0. When making a trailing stop?

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?

question from:https://stackoverflow.com/questions/65870422/how-can-i-fix-the-study-error-invalid-value-of-the-length-argument-0-in-th

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The function barssince returns the value na if no bar with the specified conditions is found. This situation is possible on the very first bars. For the functions highest and lowest the argument length greater than zero must be specified. You need to define in the script how to handle such situations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...