How to populate arrays with a foor loop in Pine Script - v5

97 Views Asked by At

I am new into pine script v5 and I would like to ask for some help to the community. I would like to obtain different information from each of the previous bar graphs and store each of those values into the different arrays that I have created using a loop.

Here is what I have managed to code until now:

/@version=5
indicator(title = "Stochastic model test")

//I found the total number of graph bars displayed on the window

    Total_Number = 0.0
    Total_Number := nz(Total_Number[1])+1

//I declare the arrays in which I would like to store each of the bar's information

    DataHighest = array.new<float>(na, 0)
    DataLowest = array.new<float>(na, 0)
    DataOpening = array.new<float>(na, 0)
    DataClosing = array.new<float>(na, 0)
    VolumeQty = array.new<float>(na, 0)

//(Here is where I am blocked) I would like to store several information of each bar graph displayed into the corresponding array using a for loop. For exemple: I would like to store the highest value of the 1st graph displayed, into the first element of my array and the same for the rest of the other arrays until the last bar.

    for i=0 to Total_Number-1
        array.push(DataHighest, ta.highest(i)) //Store the highest value of the graph number "i" into the "i" element of the DataHighest array 
        array.push(DataLowest, ta.lowest(i)) //Store the lowest value of the graph number "i" into the "i" element of the DataLowest array
        array.push(DataOpening, ta.open(i)) //Store the opening value of the graph number "i" into the "i" element of the DataOpening array
        array.push(DataClosing, ta.close(i)) //Store the closing value of the graph number "i" into the "i" element of the DataClosing array 
        array.push(VolumeQty, volume(i)) Store the volume value of the graph number "i" into the "i" element of the VolumeQty array
0

There are 0 best solutions below