简体   繁体   English

Pinescript 循环绘图

[英]Pinescript loop through drawings

I'm trying to write a code in pinescript that will loop through an array that have price levels in it.我正在尝试用 pinescript 编写一个代码,该代码将遍历一个包含价格水平的数组。 It then draws a box based on set parameters.然后它根据设置的参数绘制一个框。 My issue is this - I'm getting a ton of duplicate lines as it cycles through the loop.我的问题是 - 我在循环中循环时收到大量重复的行。 If I have 10 items in the array, the first line/box gets drawn 10 times over.如果数组中有 10 个项目,则第一行/框被绘制 10 次。 How do I avoid that?我该如何避免?

for i = 0 to array.size(myarray) - 1
    var box _box = na
    _box := box.new(bar_index[100], x, bar_index[0], x + y, color, border, style, extend.both, xloc.bar_index, color.new(color.red,70))
    box.delete(_box[i])

Please ignore x, y, border, color, style within the box.new.请忽略box.new 中的x、y、边框、颜色、样式。 I'm simplifying here.我在这里简化。 How do fix this to only create one box per i ?如何解决这个问题,使每个 i 只创建一个盒子? Thank you very much非常感谢

I was able to fix it by adding an if statement before the loop.我能够通过在循环之前添加 if 语句来修复它。 This way it only loads on last bar and avoid looping over from history这样它只会在最后一个柱上加载并避免从历史中循环

if (barstate.islastconfirmedhistory)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM