这段代码为什么没有将数值添加到数组中?

huangapple go评论58阅读模式
英文:

Why does this code NOT add values to the array?

问题

我尝试将支撑/阻力水平收集到一个数组中,但是我的代码似乎从不向数组中添加数据,因此其大小始终保持为0。我做错了什么?(当然,还有另一个类似的代码用于最低值,长度不同,这里的代码已经简化了。)

upper = ta.highest(50) 
prec = 2 // 这是GBPUSD

var SupportResistance = array.new_float() 

if math.round(upper[0], prec) < math.round(upper[1], prec)
    if array.size(SupportResistance) == 0 // 数组的第一个数据,怎么可能大小为零?
        array.push(SupportResistance, math.round(upper[1], prec))
    else 
        for i = 0 to array.size(SupportResistance) - 1
            if math.round(upper[1], prec) != array.get(SupportResistance, i) // 没有重复项
                array.push(SupportResistance, math.round(upper[1], prec))

希望这有帮助。

英文:

I try to collect Support/Resistance levels into an array but my code bele never adds data to the array so its size always remains 0. What do I do wrong? (Of course, there is another similar code for lowest values, with different length sizes, the code is simplified for you.)

upper = ta.highest(50) 
prec = 2 // its GBPUSD btw.

var SupportResistance = array.new_float() 

if math.round(upper[0], prec) &lt; math.round(upper[1], prec)
    if array.size(SupportResistance) == 0 // first data to the array, how could its size be zero?
        array.push(SupportResistance, math.round(upper[1], prec))
    else 
        for i = 0 to array.size(SupportResistance) - 1
            if math.round(upper[1], prec) != array.get(SupportResistance, i) // no duplications
                array.push(SupportResistance, math.round(upper[1], prec))

答案1

得分: 1

尝试这个:

//@version=5
indicator("我的脚本")

upper = ta.highest(50) 
prec = 2 // 这是GBPUSD

var SupportResistance = array.new_float() 

if math.round(upper[0], prec) < math.round(upper[1], prec)
    if not array.includes(SupportResistance, math.round(upper[1], prec)) 
        SupportResistance.push(math.round(upper[1], prec))

plot(SupportResistance.size())

如果您需要进一步的翻译或有其他问题,请随时提出。

英文:

try this:

//@version=5
indicator(&quot;My script&quot;)

upper = ta.highest(50) 
prec = 2 // its GBPUSD btw.

var SupportResistance = array.new_float() 

if math.round(upper[0], prec) &lt; math.round(upper[1], prec)
    if not array.includes(SupportResistance, math.round(upper[1], prec)) 
        SupportResistance.push(math.round(upper[1], prec))

plot(SupportResistance.size())

huangapple
  • 本文由 发表于 2023年7月27日 19:44:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定