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

求助修复TradingView指标语法错误:行末无续行符期待')'

修复TradingView趋势线指标的Line 21语法错误

你遇到的Line 21错误是因为Pine Script v6的语法解析器不允许函数调用的左括号(后直接换行,必须让第一个参数和左括号处于同一行。原代码中line.new(单独占一行,导致解析器无法识别后续的多行参数,触发了“end of line without line continuation”的错误提示。

修复后的完整代码

//@version=6
indicator("手动复刻趋势线", overlay=true)

// === 输入参数 ===
startBarIndex = input.int(20, title="起始K线偏移(左锚点)")
endBarIndex   = input.int(5, title="结束K线偏移(右锚点)")
startPrice    = input.float(100.0, title="起始价格(左锚点)")
endPrice      = input.float(105.0, title="结束价格(右锚点)")
extendLine    = input.bool(true, title="向右延伸趋势线")

// === 计算K线位置 ===
barStart = bar_index - startBarIndex
barEnd   = bar_index - endBarIndex

// === 定义延伸属性 ===
lineExtension = extendLine ? extend.right : extend.none

// === 绘制趋势线 ===
var line myTrendline = na
if na(myTrendline)
    myTrendline := line.new(x1 = barStart,
        y1 = startPrice,
        x2 = barEnd,
        y2 = endPrice,
        extend = lineExtension,
        color = color.blue,
        width = 2,
        style = line.style_solid
    )
else
    line.set_xy1(myTrendline, barStart, startPrice)
    line.set_xy2(myTrendline, barEnd, endPrice)

修复说明

仅调整了line.new()函数的换行位置,将第一个命名参数x1 = barStart,与左括号放在同一行,其余逻辑完全保留。你也可以选择将所有参数写在同一行,同样能解决该语法错误。

内容的提问来源于stack exchange,提问作者b-Water

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 06:51:14