Pine Script V5类型不匹配错误及transp警告解决方案咨询
Pine Script v5 编译错误与警告修复方案
错误原因及对应修复
类型不匹配错误(4个)
hline() 仅接受**固定数值(input float)**作为价格参数,但你的upperBound和lowerBound是随K线更新的序列值(series float)——由移动平均和标准差动态计算而来,每根K线都会变化,因此不符合hline()的参数要求。
同时fill()需要传入hline或plot对象,你直接传入序列数值也会导致类型不匹配。
解决方法:改用plot()绘制动态边界线,将plot()的返回对象传递给fill():
plot()支持序列值输入,完全适配动态计算的边界线需求- 保存
plot()的返回值,作为fill()的合法参数
transp 参数弃用警告
transp参数已被Pine Script v5弃用,需使用color.new()函数设置颜色透明度。
修正后的完整代码
//@version=5 // Define the number of bars to be analyzed for finding clusters clusterLength = input(title="Cluster Length", defval=100) // Define the number of standard deviations from the mean to determine the cluster stdDev = input(title="Number of Standard Deviations", defval=2.0) // Calculate the mean and standard deviation for the defined number of bars mean = ta.sma(close, clusterLength) stddev = ta.stdev(close, clusterLength) // Plot dynamic upper/lower bounds and store plot objects upperBoundPlot = plot(mean + stddev * stdDev, color=color.red, linewidth=2, title="Upper Bound") lowerBoundPlot = plot(mean - stddev * stdDev, color=color.blue, linewidth=2, title="Lower Bound") // Fill area between the two plot objects, use color.new for transparency fill(upperBoundPlot, lowerBoundPlot, color=color.new(color.gray, 70))
核心修改点
- 替换
hline()为plot():适配动态序列值的绘制,同时保存返回的plot对象 - 调整
fill()参数:传入plot对象而非原始序列数值 - 替换
transp=70为color.new(color.gray,70):遵循v5语法规范,70代表70%透明度(范围0-100)
内容的提问来源于stack exchange,提问作者Armin
相关产品推荐
相关产品推荐

