Search code examples
pine-scriptpine-script-v5

Trying to collect all LTF data into a single array


just wondering how I could concatenate all of the values from ltf arrays into one single array. In other words, rather than resetting the ltf array for each new chart bar, I'd like to add to that array so it contains all the ltf data in a single array that updates.

I've tried looping through the ltf array and pushing each value to a new array but it doesnt' seem to add past the index of the max size of ltf values, rather it just resets the loop to index 0 and writes over the previous values.

The purpose of this large array will be to run statistics on the entire population vs. just the current chart bar's


Solution

  • You should be able to do this using an array initialized with var. Image below shows my ltfData array size, when each bar only has a size of 5.

    var ltfData = array.new<float>()
    
    ltfC = request.security_lower_tf(syminfo.tickerid,'78',close)
    
    for c in ltfC
        ltfData.push(c)
    
    if barstate.islast
        label.new(bar_index,high,str.tostring(ltfData.size()))
    

    Array size