简体   繁体   English

PineScript 数组“索引超出范围”

[英]PineScript Array "Index is out of bounds"

I am attempting a very simple array and am encountering the following error when I call the 'array.clear()' function and attempt to create the new label "CCI1H End"我正在尝试一个非常简单的数组,当我调用 'array.clear()' function 并尝试创建新的 label “CCI1H End”时遇到以下错误

"In 'array.get()' function. Index 2 is out of bounds, array size is 0" “在 'array.get()' function 中。索引 2 超出范围,数组大小为 0”

The following code is an attempt to check if the last of the 3 sequential CCI pivot highs is the highest and if CCI drops below 50 then I want to clear the array and begin the count again.以下代码尝试检查 3 个连续 CCI pivot 高点中的最后一个是否最高,如果 CCI 降至 50 以下,那么我想清除阵列并再次开始计数。 I tried several different arrangements and ended with this nested arrangement thinking I could contain it within a local scope to no avail.我尝试了几种不同的安排,并以这种嵌套安排结束,认为我可以将它包含在本地 scope 中,但无济于事。 Please help, I barely know what I'm doing and would be very appreciative of an assist.请帮忙,我几乎不知道自己在做什么,并且非常感谢您的协助。

Here is the code:这是代码:

var CCI1H = array.new_float(3)

if cci > 50 
    if (cciPeakPivotHigh > 100)
        array.push(CCI1H, cciPeakPivotHigh)
        array.shift(CCI1H)
        CCI1Hval1 = array.get(CCI1H, 2)
        CCI1Hval2 = array.get(CCI1H, 1)
        CCI1Hval3 = array.get(CCI1H, 0)
        if array.size(CCI1H) == 3 and (CCI1Hval3 > CCI1Hval2 and CCI1Hval3 > CCI1Hval1)
            label.new(bar_index, na, "CCI1H End", yloc = yloc.abovebar, style = label.style_none, textcolor = color.white, size = size.normal)

else if cci < 50 
    array.clear(CCI1H) 

Thank you in advance!先感谢您!

var CCI1H = array.new_float(0)

if cci > 50 
    if (cciPeakPivotHigh > 100)
        array.push(CCI1H, cciPeakPivotHigh)
        if array.size(CCI1H) == 3
            CCI1Hval1 = array.get(CCI1H, 2)
            CCI1Hval2 = array.get(CCI1H, 1)
            CCI1Hval3 = array.get(CCI1H, 0)
                if (CCI1Hval3 > CCI1Hval2 and CCI1Hval3 > CCI1Hval1)
                    label.new(bar_index, na, "CCI1H End", yloc = yloc.abovebar, style = label.style_none, textcolor = color.white, size = size.normal)
                else
                    array.shift(CCI1H)
else if cci < 50 
    array.clear(CCI1H) 

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

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