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

表格展示研究结果报错:Bar 101出现‘行超出范围’错误

解决Pine Script表格越界报错问题

错误原因

你遇到的error on bar 101 : row 1 is out of table bounds. number of rows is 1报错,核心原因是创建表格时仅初始化了1行(table.new的最后一个参数代表行数),但后续代码尝试写入索引为1的第二行,超出了表格的行数限制。

修复方案

直接在创建表格时指定足够的行数(你需要表头行+数据行,共2行),修改table.new的行数参数即可:

// Show the results on the chart
plotshape(condition1, location=location.belowbar, color=color.green, title="High Crossing")
plotshape(condition2, location=location.belowbar, color=color.orange, title="Low Crossing")

// Create a table for displaying results
var table myTable = na
if bar_index == 100
    myTable := table.new(position.bottom_left, 3, 2) // 初始化2行,满足表头和数据需求
    table.cell(myTable, 0, 0, "Condition 1 Hits")
    table.cell(myTable, 1, 0, "Condition 2 Hits")
    table.cell(myTable, 2, 0, "Success Percentage")

if bar_index > 100
    table.cell(myTable, 0, 1, str.tostring(hits1))
    table.cell(myTable, 1, 1, str.tostring(hits2))
    table.cell(myTable, 2, 1, str.tostring(successPercentage) + "%")

扩展说明

如果后续需要动态添加更多行,可以使用table.add_row()函数,示例逻辑如下:

// 检查当前表格行数是否足够,不足则添加新行
if table.row_count(myTable) < 2
    table.add_row(myTable)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 17:55:02