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

TradingView Pine Script报错:行末无续行符语法错误

Pine Script v5 语法错误:end of line without line continuation

问题详情

报错信息:

Error at 5:10 Syntax error at input 'end of line without line continuation'

我的代码:

//@version=5

indicator ("Trigger Lines Trend Definition", overlay=true)

import ta

// Indicator inputs
band_length = input.int(title="Band Length", defval=10)
band_mult = input.float(title="Band Multiplier", defval=1.5)

// Calculate the band
basis = ta.sma(close, band_length)
dev = band_mult * ta.stdev(close, band_length)
upper_band = basis + dev
lower_band = basis - dev

// Define body
body = abs (close - open)

// Determine trend direction
up_trend = close > upper_band and ta.median(close - open, band_length) > (upper_band - basis) and close > high[1] and body >= body[1]
down_trend = close < lower_band and ta.median(open - close, band_length) > (basis - lower_band) and close < low[1] and body >= body[1]

// Plot the ribbon
fill(upper_band, lower_band, color=up_trend ? color.green : down_trend ? color.red : color.gray)

// Add horizontal lines to visualize the band
plot(upper_band, color=color.blue)
plot(lower_band, color=color.blue)

// Plot signals
signalColor = up_trend ? color.green : down_trend ? color.red : color.black
plotshape(series=up_trend, style=shape.triangleup, location=location.belowbar, color=signalColor, size=size.small, title="Up Trend")
plotshape(series=down_trend, style=shape.triangledown, location=location.abovebar, color=signalColor, size=size.small, title="Down Trend")

// Create alerts
alertcondition(up_trend, title="Up Trend", message="New uptrend detected")
alertcondition(down_trend, title="Down Trend", message="New downtrend detected")

已尝试调整缩进、增减代码行等方法,问题仍未解决。

解决方案

错误根源

Pine Script v5 不允许函数名称与左括号之间存在空格,你的代码中有两处违反了这个语法规则:

  • indicator ("Trigger Lines Trend Definition", overlay=true):indicator 与左括号间有空格
  • body = abs (close - open):abs 与左括号间有空格

解释器会将带空格的函数名识别为独立变量,导致语法解析失败,抛出报错。

修正后的代码

//@version=5

indicator("Trigger Lines Trend Definition", overlay=true)

import ta

// Indicator inputs
band_length = input.int(title="Band Length", defval=10)
band_mult = input.float(title="Band Multiplier", defval=1.5)

// Calculate the band
basis = ta.sma(close, band_length)
dev = band_mult * ta.stdev(close, band_length)
upper_band = basis + dev
lower_band = basis - dev

// Define body
body = abs(close - open)

// Determine trend direction
up_trend = close > upper_band and ta.median(close - open, band_length) > (upper_band - basis) and close > high[1] and body >= body[1]
down_trend = close < lower_band and ta.median(open - close, band_length) > (basis - lower_band) and close < low[1] and body >= body[1]

// Plot the ribbon
fill(upper_band, lower_band, color=up_trend ? color.green : down_trend ? color.red : color.gray)

// Add horizontal lines to visualize the band
plot(upper_band, color=color.blue)
plot(lower_band, color=color.blue)

// Plot signals
signalColor = up_trend ? color.green : down_trend ? color.red : color.black
plotshape(series=up_trend, style=shape.triangleup, location=location.belowbar, color=signalColor, size=size.small, title="Up Trend")
plotshape(series=down_trend, style=shape.triangledown, location=location.abovebar, color=signalColor, size=size.small, title="Down Trend")

// Create alerts
alertcondition(up_trend, title="Up Trend", message="New uptrend detected")
alertcondition(down_trend, title="Down Trend", message="New downtrend detected")

关键修改

  1. 移除 indicator 与左括号之间的空格
  2. 移除 abs 与左括号之间的空格

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 04:22:54