Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Array does not gets filled

the arrays DZarr and SZarr do not get filled when using array.push().
I check the array size of DZarr on each bar by using label as a kind of printf and it always shows 0. Its weird since the boxes get displayed on screen but somehow cant just get into the arrays.

//@version=5
//This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
indicator('simple OBs', overlay=true, max_boxes_count=500, max_lines_count=500)


// functions
DZ()=>
    r = (close[2] < open[2]) and (close[1] > open[1]) and (close[1] > high[2]) ? 1 : 0

SZ()=>
    r = ( close[2] > open[2]) and (close[1] < open[1]) and (close[1] < low[2]) ? 1 : 0

limit = 10
box[] DZarr = array.new_box()
box[] SZarr = array.new_box()

if DZ()
    DZ = box.new(left=bar_index-2, right=bar_index, top=high[2] ,bottom=math.min(low[2],low[1]), border_color = color.black, bgcolor = color.new(color.lime, 75))
    array.push(DZarr,DZ)
    
if SZ()
    SZ = box.new(left=bar_index-2, right=bar_index, top=math.max(high[2],high[1]) ,bottom=low[2], border_color = color.black, bgcolor = color.new(color.red, 75))
    array.push(SZarr,SZ)

l=label.new(x=bar_index,y=close, yloc=yloc.belowbar, color=color.white,textcolor=color.black, text=str.tostring(array.size(DZarr)), size=size.large)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to use the var keyword while declaring your arrays. Otherwise your arrays will be initialized on each bar.

var is the keyword used for assigning and one-time initializing of the
variable.

var box[] DZarr = array.new_box()
var box[] SZarr = array.new_box()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading