Pine 编辑器 - 研究错误,"lowest"函数中'length'参数 (0.0) 的值无效。它必须是 >0



我试图创建一个RSI发散指标,但遇到了一些困难。

我在网上搜索了一下,发现我需要添加nz((命令,添加后我仍然会遇到错误。

//@version=5
indicator("My script")
noColor = color.new(color.white, 100)
Bullcondition = false
//Creating the RSI
rsi= ta.rsi(close,14)
plot(ta.rsi(close,14),color=#7E57C2)
hline(50,linestyle=hline.style_dashed, color=color.new(#787B86, 50))
upperband = hline(30,linestyle=hline.style_dashed, color=#787B86, linewidth = 1)
lowerband = hline(70,linestyle=hline.style_dashed, color=#787B86, linewidth = 1)
fill(upperband, lowerband, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")

//---------------------------------------------------
pivot_right = input.int(1,minval=1,title="pivot right")
pivot_left = input.int(10,minval=1,title="pivot left")
min_range = input.int(5,minval=1,title="Min range")
max_range = input.int(60,minval=1,title="Max range")
//function to check range in valid
confirm_range(x) =>
bars =ta.barssince(x == true)
min_range <= bars and bars <= max_range
//--------------bullish divergence--------------
//strong divergence ( price goes down while RSI goes up)
rsi_lowest = ta.lowest(rsi,50)
bars_lowest = nz(ta.barssince( rsi_lowest == rsi),1)
price_atlowest = low[bars_lowest]
lowest_since = ta.lowest(bars_lowest)
pivot_low = na(ta.pivotlow(rsi,bars_lowest,pivot_right)) ? false : true //checking to see that we are at a lowest point in rsi
Bullcondition := rsi_lowest < rsi and price_atlowest < lowest_since and pivot_low // validating everything is in order
plot(pivot_low ? rsi[pivot_right] : na,offset=-pivot_right, linewidth=1, color=(Bullcondition ? color.yellow : noColor)) // Drawing line in between pivots

//pivot_high = na(ta.pivothigh(rsi,pivot_left,pivot_right)) ? false : true //checking to see if we are at pivot high within range defiend

这是我的密码,希望很快能收到你们的来信。非常感谢我能得到的一切帮助!

在此处重新定位以格式化消息

啊,我的坏:(

所以这意味着,每当你的bars_lowest=barssince…==0,最低的函数不接受它——这是正常的,因为它必须大于0。

我知道你正试图捕捉自某种情况发生以来的最低值,对吧?

我可以建议一个肮脏的黑客

var float lowest_since = 0
if bars_lowest > 0
lowest_since := ta.lowest(bars_lowest)

相关内容

最新更新