表格展示研究结果报错: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
相关产品推荐
相关产品推荐

