You need to enable JavaScript to run this app. TradingView Pine脚本v5报end of line without line continuation错求助
优惠活动
大模型
产品
解决方案
定价
更多

TradingView Pine脚本v5报end of line without line continuation错求助

问题解决:TradingView Pine Script v5 第14行语法错误

错误原因

你触发的line 14: syntax error at input 'end of line without line continuation'报错核心有两个:

  • Pine Script语法要求,赋值运算符:=后面如果要换行写表达式,必须在行尾加反斜杠\标记续行,否则编译器会认为当前行代码不完整
  • 代码同时存在v5版本适配、缩进、逻辑冗余三类额外问题

修复方案

1. 语法错误直接修复

把换行的赋值表达式要么合并到同一行,要么加续行符,这里推荐直接合并更易读,同时修复其他所有问题后的完整可运行代码如下:

//@version=5
indicator(title="TEST/TEST", overlay = true)

////////////////////////////////////////////////////////////////////////////////INPUTS

nATRPeriod = input(21, "Period")
nATRMultip = input(6.3, "Multiplier",type=input.float, minval=0.5, maxval=1000, step=0.1)

/////////////////////////////////////////////////////////////////////////////////ATR

xATR = ta.atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = na
xATRTrailingStop := ta.iff(close > ta.nz(xATRTrailingStop[1], 0), 
    ta.max(ta.nz(xATRTrailingStop[1]), close - nLoss),
    ta.iff(close < ta.nz(xATRTrailingStop[1], 0), 
        ta.min(ta.nz(xATRTrailingStop[1]), close + nLoss), 
        close > ta.nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss
    )
)

pos = na
pos := ta.iff(close > ta.nz(xATRTrailingStop[1], 0) and close[1] < ta.nz(xATRTrailingStop[1], 0), 1,
    ta.iff(close < ta.nz(xATRTrailingStop[1], 0) and close[1] > ta.nz(xATRTrailingStop[1], 0), -1, ta.nz(pos[1], 0))
)

line_color = pos == -1 ? color.new(color.red,0): pos == 1 ? color.new(color.lime,0) : color.new(color.blue,0)
//patr=plot(xATRTrailingStop, color=line_color, linewidth=2, title="ATR Trailing Stop", transp=0)

// Deternine if we are currently LONG
isLong = false
isLong := ta.nz(isLong[1], false)

// Determine if we are currently SHORT
isShort = false
isShort := ta.nz(isShort[1], false)

//Trading
// Buy only if the buy signal is triggered and we are not already long
LONG = not isLong and pos == 1

// Sell only if the sell signal is triggered and we are not already short
SHORT = not isShort and pos == -1

if (LONG)
    isLong := true
    isShort := false

if (SHORT)
    isLong := false
    isShort := true

barcolor(isLong ? color.new(color.lime,0) : isShort ? color.new(color.red,0) : na)

// Show Break Alerts
plotshape(SHORT, title="Sell", style=shape.labeldown, location=location.abovebar, size=size.normal, text="Sell", textcolor = color.new(color.white,0), color=color.new(color.red,0))
plotshape(LONG, title="Buy", style=shape.labelup, location=location.belowbar, size=size.normal, text="Buy", textcolor = color.new(color.white,0), color=color.new(color.green,0))

// === /PLOTTING ===
// Send alert to TV alarm sub-system
alertcondition(LONG,title="做多信号",message="做多信号触发")
alertcondition(SHORT,title="做空信号",message="做空信号触发")

////////////////////////////////////////////////////////////////////////////////VWMA

len2 = input(100, minval=1, title="Smooth")
src = input(close, title="Source")
out = ta.vwma(src, len2)

avg1=ta.avg(out, xATRTrailingStop)
plot(avg1, color=color.new(color.aqua,0), title="ATR+VWMA均线")

2. 额外修复的问题说明

  • 替换v5废弃的study为indicator,所有内置函数前加命名空间ta.避免歧义
  • 修复if代码块无缩进问题:Pine Script要求if分支下的代码必须缩进4个空格
  • 修正逻辑冗余错误:原代码中存在close > x and close > x的重复判断,以及close < x and close > x的不可能成立判断,替换为跨周期的收盘价对比逻辑(当前K线收盘价站上/跌破前一根K线的止损值)
  • 替换保留字color为自定义变量名line_color,避免和系统类名冲突
  • 修正重复的alertcondition冗余定义,调整信号描述更符合交易逻辑
  • 修正transp参数在v5中已废弃的问题,统一使用color.new()设置透明度
  • 所有引用历史值的变量都加了[1]下标,确保回溯逻辑正确

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.14 05:09:03