You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PineScript编译错误求助:第9行'TrueRange'语法错误

PineScript 编译错误排查与修复(Line 9: Syntax error at input 'TrueRange')

报错信息

9:18:39 AM — Compilation error. Line 9: Syntax error at input 'TrueRange'

原代码

indicator("sigbars")
study("Significant Bar gku", shorttitle="Significant Bar", overlay=false) 
length=input(14, "length")
ThreshStrong = input(2, "Strong Significant Bar")
ThreshWeak = input(1.4, "Weak Significant Bar")
TrueRange = at.tr
ATR = atr(length)
strongSB = tr > ATR*ThreshStrong
weakSB = tr > ATR*ThreshWeak
cold1=white
cold2=#b2ebf2
color = strongSB ? cold1 : weakSB ? cold2 : na
band1 = hline(ThreshStrong, "Upper Band", color=#C0C0C0)
band0 = hline(ThreshWeak, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")
plot(tr, "true range", blue)
plot(ATR, "ATR", black)
plot(tr/ATR,"TR/ATR", red, style = histogram)
//plot(ma,"ma(TR/ATR)", green)
barcolor(color)

plot(close)

问题排查与修复

  • 重复声明脚本入口:PineScript中脚本只能用indicator()或study()其中一个声明入口,study()是旧版函数,建议统一使用indicator(),删除多余的study()行。
  • 错误的真实波幅赋值:at.tr是无效写法,PineScript内置变量tr直接表示当前K线的真实波幅,无需额外定义TrueRange,直接删除TrueRange = at.tr这行即可解决语法错误。
  • 可选优化:脚本设置overlay=false(副图显示),最后一行plot(close)会在副图单独绘制收盘价,若不需要可删除该行。

修复后的完整代码

indicator("Significant Bar gku", shorttitle="Significant Bar", overlay=false) 
length=input(14, "length")
ThreshStrong = input(2, "Strong Significant Bar")
ThreshWeak = input(1.4, "Weak Significant Bar")
ATR = atr(length)
strongSB = tr > ATR*ThreshStrong
weakSB = tr > ATR*ThreshWeak
cold1=white
cold2=#b2ebf2
color = strongSB ? cold1 : weakSB ? cold2 : na
band1 = hline(ThreshStrong, "Upper Band", color=#C0C0C0)
band0 = hline(ThreshWeak, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")
plot(tr, "true range", blue)
plot(ATR, "ATR", black)
plot(tr/ATR,"TR/ATR", red, style = histogram)
//plot(ma,"ma(TR/ATR)", green)
barcolor(color)

// 若不需要副图显示收盘价,可删除下面一行
plot(close)

内容的提问来源于stack exchange,提问作者Sam Wich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 22:21:39