英文:
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) < 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("My script")
upper = ta.highest(50)
prec = 2 // its GBPUSD btw.
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())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论