admin管理员组

文章数量:1291044

Not a big coding guru here. Wondering why I get

Error on bar 0: In 'array.get()' function. Index 0 is out of bounds, array size is 0.

for this:

if array.size(vah_levels) > 0
    for i = 0 to array.size(vah_levels) - 1
        if not array.get(trades_taken, i)
            current_vah = array.get(vah_levels, i)
            current_val = array.get(val_levels, i)
            [above_vah, below_val] = f_detect_swing(current_vah, current_val)

Some research points to array.size(vah_levels) being 0 in the beginning. Should tell it to ignore such cases? Grateful for any advice. Thanks

Not a big coding guru here. Wondering why I get

Error on bar 0: In 'array.get()' function. Index 0 is out of bounds, array size is 0.

for this:

if array.size(vah_levels) > 0
    for i = 0 to array.size(vah_levels) - 1
        if not array.get(trades_taken, i)
            current_vah = array.get(vah_levels, i)
            current_val = array.get(val_levels, i)
            [above_vah, below_val] = f_detect_swing(current_vah, current_val)

Some research points to array.size(vah_levels) being 0 in the beginning. Should tell it to ignore such cases? Grateful for any advice. Thanks

Share Improve this question asked Feb 13 at 23:19 Svetoslav GeievSvetoslav Geiev 32 bronze badges 2
  • What is trades_taken? Is it an array? Where is it initialized? – PM 77-1 Commented Feb 13 at 23:31
  • As I am doing some codes "stitching and changes", it is possible this to be a complete disaster... for trades_taken I have. 'var bool[] trades_taken = array.new_bool()' It later has: 'if proceed if not na(pvah) and not na(pval) array.push(trades_taken, false)' – Svetoslav Geiev Commented Feb 14 at 9:12
Add a comment  | 

1 Answer 1

Reset to default 0

You have three arrays you are working with. Before doing any kind of accessing their elements you need to check if there is something in them.

Currently, you are only testing one of your arrays. So, the issue is probably coming from the other two.

Below should at least prevent the error.

len_vah = array.size(vah_levels)
len_val = array.size(val_levels)
len_trades = array.size(trades_taken)

if ((len_vah > 0) and (len_val > 0) and (len_trades > 0))
    for i = 0 to len_vah - 1
        if not array.get(trades_taken, i)
            current_vah = array.get(vah_levels, i)
            current_val = array.get(val_levels, i)
            [above_vah, below_val] = f_detect_swing(current_vah, current_val)

本文标签: