xmartinezuk
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: February 15th, 2021

arrays

Hi all,

I am working in a script where I'd like to use some arrays... but I am having some issues on including the arrays into a loop. I hope someone can help.
In the code below I am initialising an array in to ways, the called option 2 does not work.
Would someone be able to help?

Thank you very much.

var c_fills = array.new_color(5)
// Initialize the array elements with progressively lighter shades of the fill color.

// Option 1
array.set(c_fills, 0, color.new(c_fillColor, 70))
array.set(c_fills, 1, color.new(c_fillColor, 75))
array.set(c_fills, 2, color.new(c_fillColor, 80))
array.set(c_fills, 3, color.new(c_fillColor, 85))
array.set(c_fills, 4, color.new(c_fillColor, 90))

// Option 2
transp = 70
for i = 0 to 4
array.set(c_fills, i, color.new(c_fillColor, transp))
transp := transp + 5

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: arrays

I don't think your issue is with the array but with the color.new function. color.new only accepts a constant integer for the transp parameter. When you use := to change the tranp variable it changes from a constant integer to a series[integer]. color.new will not accept a series[integer] as the transp value.

I'm not aware of any workaround to this limitation.

Return to “Pine Script Q&A”