In Pine V5, I have used array in one indicator. array.get() , array.set(), mattrix.get() these kind of functions are used in that code. I am capturing values of different indicators, across different time frames, inside this array. This indicator working fine in 1 min, 5 min and 15 min time frames. But as soon as I am shifting to hourly time frame, it is showing following error and indicator is not being displayed,
Study Error - Error on bar 0: Cannot call array methods when id of array is na.
//@version=5
indicator("Learning Array V3", shorttitle = "Learning Array V3", overlay = true)
_sma_source = close
_sma01_Length = 10
_sma02_Length = 30
_sma03_Length = 100
_sma04_Length = 200
_my_array_func() =>
array_output = array.new<float>(4, float(na))
_sma10 = ta.sma(_sma_source, _sma01_Length)
_sma30 = ta.sma(_sma_source, _sma02_Length)
_sma100 = ta.sma(_sma_source, _sma03_Length)
_sma200 = ta.sma(_sma_source, _sma04_Length)
[_sma10, _sma30, _sma100, _sma200]
array.set(array_output, 0, _sma10)
array.set(array_output, 1, _sma30)
array.set(array_output, 2, _sma100)
array.set(array_output, 3, _sma200)
array_output
//========================== Getting Data inside Array ===========
_data_mtly = request.security(syminfo.tickerid, "1M", _my_array_func())
_data_wkly = request.security(syminfo.tickerid, "1W", _my_array_func())
_data_daly = request.security(syminfo.tickerid, "1D", _my_array_func())
_data_hrly = request.security(syminfo.tickerid, "60", _my_array_func())
_data_15mn = request.security(syminfo.tickerid, "15", _my_array_func())
My_Array = matrix.new<float>(5, 4, na)
matuu(mtx1, _row1, _data) =>
if not na(array.get(_data, 0))
matrix.set(mtx1, _row1, 0, array.get(_data, 0)) // SMA10
matrix.set(mtx1, _row1, 1, array.get(_data, 1)) // SMA50
matrix.set(mtx1, _row1, 2, array.get(_data, 2)) // SMA100
matrix.set(mtx1, _row1, 3, array.get(_data, 3)) // SMA200
matuu(My_Array, 0, _data_mtly)
matuu(My_Array, 1, _data_wkly)
matuu(My_Array, 2, _data_daly)
matuu(My_Array, 3, _data_hrly)
matuu(My_Array, 4, _data_15mn)
// Just to check what value is being stored in the Array ....
Show_Array_Table = table.new(position.top_right, 4, 5, #000000, #000000, 1, #000000, 1)
for i = 0 to 4
table.cell(Show_Array_Table, 0, i, str.tostring(matrix.get(My_Array, i, 0)), text_size = size.small, bgcolor = #000000, text_color = #FFFFFF)
table.cell(Show_Array_Table, 1, i, str.tostring(matrix.get(My_Array, i, 1)), text_size = size.small, bgcolor = #000000, text_color = #FFFFFF)
table.cell(Show_Array_Table, 2, i, str.tostring(matrix.get(My_Array, i, 2)), text_size = size.small, bgcolor = #000000, text_color = #FFFFFF)
table.cell(Show_Array_Table, 3, i, str.tostring(matrix.get(My_Array, i, 3)), text_size = size.small, bgcolor = #000000, text_color = #FFFFFF)
I don't understand how come same piece of code is working fine in 1 min / 5 min / 15 min but the same is failing in hourly TF.