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

Pine Script报错:newSupBox := box.new(行存在未续行换行匹配问题

Pine Script 报错解决:输入不匹配(未使用行续行符就换行)

问题描述

编写TradingView Pine Script时触发报错:输入不匹配:未使用行续行符就换行,期望输入')',报错定位在newSupBox := box.new(行。

官方文档中box.new内置函数语法为:

box.new(top_left, bottom_right, border_color, border_width, border_style, extend, xloc, bgcolor, text, text_size, text_color, text_halign, text_valign, text_wrap, text_font_family, force_overlay, text_formatting) → series box

返回的盒子对象ID可用于box.set_*和box.get_*系列函数。

用户提供的报错代码片段:

// Add new support zone
if not na(pivotLow) and show_zones
    float zoneLow = low[pivot_right_bars]
    float zoneHigh = zoneLow + (zoneLow * zone_width_pct)

if not should_cluster(zoneLow, supZonesLow)
    array.push(supZonesLow, zoneLow)
    array.push(supZonesHigh, zoneHigh)
    
    int zoneIdx = array.size(supZonesLow)
    color zoneColor = zoneIdx > max_zones - highlight_zones ? color.new(color.green, 60) : color.new(color.green, 85)
    
    newSupBox = box.new(
        bar_index - pivot_right_bars, zoneHigh, // left, top
        bar_index + 50, zoneLow,               // right, bottom
        border_color=color.green, 
        bgcolor=zoneColor, 
        extend=extend.right
    )
    array.push(supZoneBoxes, newSupBox)
    
    if show_labels
        supLabel = label.new(
            bar_index - pivot_right_bars, zoneLow, 
            "SZ", 
            color=color.new(color.green, 20), 
            style=label.style_label_up, 
            textcolor=color.white, 
            size=get_label_size()
        )
        array.push(supZoneLabels, supLabel)
    
    // Remove oldest zones if over max
    if array.size(supZonesLow) > max_zones
        box.delete(array.shift(supZoneBoxes))
        if show_labels and array.size(supZoneLabels) > 0
            label.delete(array.shift(supZoneLabels))
        array.shift(supZonesLow)
        array.shift(supZonesHigh)

// Add new resistance zone
if not na(pivotHigh) and show_zones
    float zoneHigh = high[pivot_right_bars]
    float zoneLow = zoneHigh - (zoneHigh * zone_width_pct)

if not should_cluster(zoneHigh, resZonesHigh)
    array.push(resZonesLow, zoneLow)
    array.push(resZonesHigh, zoneHigh)
    
    int zoneIdx = array.size(resZonesLow)
    color zoneColor = zoneIdx > max_zones - highlight_zones ? color.new(color.red, 60) : color.new(color.red, 85)
    
    newResBox = box.new(
        bar_index - pivot_right_bars, zoneHigh, // left, top
        bar_index + 50, zoneLow,               // right, bottom
        border_color=color.red, 
        bgcolor=zoneColor, 
        extend=extend.right
    )
    array.push(resZoneBoxes, newResBox)
    
    if show_labels
        resLabel = label.new(
            bar_index - pivot_right_bars, zoneHigh, 
            "RZ", 
            color=color.new(color.red, 20), 
            style=label.style_label_down, 
            textcolor=color.white, 
            size=get_label_size()
        )
        array.push(resZoneLabels, resLabel)

报错原因

Pine Script解析器对函数参数行末尾的注释处理存在限制:当你在参数行末尾添加//注释后直接换行,解析器会将注释后的换行判定为未使用续行符的换行,进而认为函数调用未完成,缺少闭合的),触发输入不匹配报错。

解决方法

将参数行末尾的注释移至单独行(参数上方或下方),避免干扰解析器识别函数参数:

修改后的代码示例:

// Add new support zone
if not na(pivotLow) and show_zones
    float zoneLow = low[pivot_right_bars]
    float zoneHigh = zoneLow + (zoneLow * zone_width_pct)

if not should_cluster(zoneLow, supZonesLow)
    array.push(supZonesLow, zoneLow)
    array.push(supZonesHigh, zoneHigh)
    
    int zoneIdx = array.size(supZonesLow)
    color zoneColor = zoneIdx > max_zones - highlight_zones ? color.new(color.green, 60) : color.new(color.green, 85)
    
    // 参数说明:left=bar_index - pivot_right_bars, top=zoneHigh; right=bar_index + 50, bottom=zoneLow
    newSupBox = box.new(
        bar_index - pivot_right_bars, zoneHigh,
        bar_index + 50, zoneLow,
        border_color=color.green, 
        bgcolor=zoneColor, 
        extend=extend.right
    )
    array.push(supZoneBoxes, newSupBox)
    
    if show_labels
        supLabel = label.new(
            bar_index - pivot_right_bars, zoneLow, 
            "SZ", 
            color=color.new(color.green, 20), 
            style=label.style_label_up, 
            textcolor=color.white, 
            size=get_label_size()
        )
        array.push(supZoneLabels, supLabel)
    
    // Remove oldest zones if over max
    if array.size(supZonesLow) > max_zones
        box.delete(array.shift(supZoneBoxes))
        if show_labels and array.size(supZoneLabels) > 0
            label.delete(array.shift(supZoneLabels))
        array.shift(supZonesLow)
        array.shift(supZonesHigh)

// Add new resistance zone
if not na(pivotHigh) and show_zones
    float zoneHigh = high[pivot_right_bars]
    float zoneLow = zoneHigh - (zoneHigh * zone_width_pct)

if not should_cluster(zoneHigh, resZonesHigh)
    array.push(resZonesLow, zoneLow)
    array.push(resZonesHigh, zoneHigh)
    
    int zoneIdx = array.size(resZonesLow)
    color zoneColor = zoneIdx > max_zones - highlight_zones ? color.new(color.red, 60) : color.new(color.red, 85)
    
    // 参数说明:left=bar_index - pivot_right_bars, top=zoneHigh; right=bar_index + 50, bottom=zoneLow
    newResBox = box.new(
        bar_index - pivot_right_bars, zoneHigh,
        bar_index + 50, zoneLow,
        border_color=color.red, 
        bgcolor=zoneColor, 
        extend=extend.right
    )
    array.push(resZoneBoxes, newResBox)
    
    if show_labels
        resLabel = label.new(
            bar_index - pivot_right_bars, zoneHigh, 
            "RZ", 
            color=color.new(color.red, 20), 
            style=label.style_label_down, 
            textcolor=color.white, 
            size=get_label_size()
        )
        array.push(resZoneLabels, resLabel)

也可以选择直接去掉行内注释,同样能解决报错问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 18:43:13