在栏 10514 上出现错误:
在“array.get()”函数中。索引 46 超出范围,数组大小为 45。
我无法解决原因。此代码的目的是从数组(numbersWHOLE 和numbersHALF)中删除数组(numbersBIG 和numbersBIGhalf)中的一组值。
问题所在的代码:
//@version=5
indicator("snippet", overlay=true, max_lines_count = 500, max_bars_back = 500)
TRange = 1.2700
BRange = 1.2205
ArrFreq = 100*syminfo.mintick
BRange00 = 1.2200
bigArrFreq = 1000*syminfo.mintick
BRangeBigHALF = 1.2250
var numbersWHOLE=array.new_float(0)
var numbersHALF=array.new_float(0)
var numbersBIG=array.new_float(0)
var numbersBIGhalf=array.new_float(0)
if barstate.islast and timeframe.isintraday
for i = BRange00 to TRange by bigArrFreq
array.push(numbersBIG,i)
for i = BRangeBigHALF to TRange by bigArrFreq
array.push(numbersBIGhalf,i)
for i = BRange to TRange by ArrFreq
array.push(numbersHALF,i)
for i = BRange00 to TRange by ArrFreq
//if array.indexof(numbersBIG,i) != array.get(numbersWHOLE,i)
array.push(numbersWHOLE,i)
for i = 0 to (array.size(numbersWHOLE) == 0 ? na : array.size(numbersWHOLE) - 1)
ju = numbersWHOLE.get(i)
if numbersBIG.includes(ju)
//label.new(bar_index-i*2,low,str.tostring(array.get(numbersHALF,i)))
numbersWHOLE.remove(i)
for i = 0 to array.size(numbersHALF) - 1
line.new(bar_index - 20, array.get(numbersHALF,i),bar_index + 20, array.get(numbersHALF,i), style = line.style_dashed, color = color.red, width = 1) //, extend = extend.both
for i = 0 to array.size(numbersWHOLE) - 1
line.new(bar_index - 20, array.get(numbersWHOLE,i),bar_index + 20, array.get(numbersWHOLE,i), style = line.style_dashed, color = color.red, width = 1) //, extend = extend.both
for i = 0 to array.size(numbersBIGhalf) - 1
line.new(bar_index - 400, array.get(numbersBIGhalf,i),bar_index + 100, array.get(numbersBIGhalf,i), style = line.style_dashed, color = color.white, width = 1, extend = extend.both) //, extend = extend.both
for i = 0 to array.size(numbersBIG) - 1
line.new(bar_index - 400, array.get(numbersBIG,i),bar_index + 100, array.get(numbersBIG,i), style = line.style_dashed, color = color.white, width = 1, extend = extend.both) //, extend = extend.both
我尝试了... in , while 的多种表达变化,但仍然无法让这个想法发挥作用。
这里是一个使用
array.includes()
、array.indexof()
和 array.remove()
函数的示例。
//@version=5
indicator("snippet", overlay=true)
test_arr_1 = array.from(1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0)
test_arr_2 = array.from(1.0, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2.0)
num_to_remove_arr = array.from(1.1, 1.8)
s1 = "------ Before ------" + "\n" +
"test_arr_1: " + str.tostring(test_arr_1) + "\n" +
"test_arr_2: " + str.tostring(test_arr_2) + "\n" +
"num_to_remove_arr: " + str.tostring(num_to_remove_arr) + "\n"
len = array.size(num_to_remove_arr)
if (len > 0)
for i = 0 to len - 1
num_to_remove = array.get(num_to_remove_arr, i)
if (array.includes(test_arr_1, num_to_remove))
idx = array.indexof(test_arr_1, num_to_remove)
array.remove(test_arr_1, idx)
if (array.includes(test_arr_2, num_to_remove))
idx = array.indexof(test_arr_2, num_to_remove)
array.remove(test_arr_2, idx)
s2 = "------ After ------" + "\n" +
"test_arr_1: " + str.tostring(test_arr_1) + "\n" +
"test_arr_2: " + str.tostring(test_arr_2) + "\n" +
"num_to_remove_arr: " + str.tostring(num_to_remove_arr) + "\n"
s = s1 + s2
if barstate.islast
label.new(bar_index, high, s, textcolor=color.white)