关于London Session Highlight指标绘制天数受限的技术咨询
问题描述
在M15时间框架下使用London Session Highlight指标时,该指标仅能绘制回溯至4月4日的箱体图形;移除第二个箱体后,可绘制回溯至2月26日的图形。已知TradingView指标的图形绘制存在数量限制,特此咨询:不同类型图形的限制程度是否存在差异?
指标代码
//@version=6 indicator("London Session Highlight", overlay=true) // Note: Be sure to select "Pinned to right scale" // === Background during London session (08:00–17:00 UTC+2) === startHour = 8 startMin = 0 endHour = 16 endMin = 15 sessionStart = timestamp('UTC', year, month, dayofmonth, startHour, startMin) sessionEnd = timestamp('UTC', year, month, dayofmonth, endHour, endMin) isInSession = sessionStart <= time and time <= sessionEnd bgcolor(isInSession ? color.new(color.blue, 80) : na) // === 9am M15 candle === var white = color.new(color.white, 80) var yellow = color.new(color.yellow, 80) isNineAM = (hour(time, 'UTC') == startHour) and (minute == 0) isNineFifteenAM = (hour(time, 'UTC') == startHour) and (minute == 15) bgcolor(isNineAM ? color.new(color.orange, 80) : na) if isNineFifteenAM and not na(high[1]) and not na(low[1]) and high[1] != low[1] and barstate.isconfirmed startIndex = bar_index-1 endIndex = bar_index + 32 box.new(left=startIndex, right=endIndex, top=high[1]+(high[1]-low[1]), bottom=low[1]-(high[1]-low[1]), border_color=na, bgcolor=yellow) box.new(left=startIndex, right=endIndex, top=high[1], bottom=low[1], border_color=na, bgcolor=white)
解答
TradingView对不同类型的绘图对象确实存在不同的数量限制:
- 箱体(box)、标签(label)、线条(line)这类独立绘图对象,有明确的创建数量上限(当前官方限制为每个指标最多创建500个这类对象)
- 而
bgcolor、plot这类基于K线的绘图函数,没有独立对象的数量限制——它们直接绑定在K线上渲染,不会占用独立对象的配额
你的案例正好验证了这一点:每次触发条件时创建2个箱体,会更快耗尽500个的上限,因此回溯时间更短;移除一个箱体后,创建数量减半,就能支持更早的历史数据绘制。
若要进一步扩展回溯范围,可通过以下方式优化:
- 复用已创建的箱体对象:使用
box.set_left()、box.set_right()、box.set_top()、box.set_bottom()等函数更新旧箱体的位置和尺寸,而非创建新对象 - 自动清理旧对象:只保留最近N个箱体,当创建新箱体时删除超出数量的旧箱体
内容的提问来源于stack exchange,提问作者Matt W
相关产品推荐
相关产品推荐

