如何实现box.get_top()与array.get()的实时点数计算?
实现点数(Pips)的实时统计方案
可以实现实时计算,当前代码仅在K线闭合时更新文本的原因是你把box.set_text放在了if barstate.islast判断内。要改为实时更新,只需调整触发逻辑:
修改后的代码片段
t = 0 for i = 0 to array.size(bricks) - 1 GetBoxTopValue_t = box.get_top(array.get(bricks,i - t)) GetBoxBotomValue_t = box.get_bottom(array.get(bricks,i - t)) // 移除barstate.islast判断,让文本在每一次脚本运行时(实时tick)更新 box.set_text(array.get(bricks,i-t), ' ' + str.tostring(GetBoxTopValue_t - GetBoxBotomValue_t) + ' pips.') // 保留你的实时删除逻辑 if high >= GetBoxTopValue_t and low <= GetBoxBotomValue_t box.delete(array.get(bricks,i - t)) array.remove(bricks,i - t) t := t + 1
关键说明
- 移除
if barstate.islast后,脚本会在每一个实时tick执行box.set_text,从而实现点数的实时显示。 - 由于盒子的顶部(
box.get_top)和底部(box.get_bottom)值是固定的(除非你动态修改盒子参数),每次计算的差值其实是固定的,但这样修改后会确保文本在盒子存在的整个周期内实时可见,而非仅在K线闭合时才显示。 - 你的删除逻辑已经支持实时运行,无需改动这部分代码。
内容的提问来源于stack exchange,提问作者tomcraziest
相关产品推荐
相关产品推荐

