Momen
Pine Script Rookie
Pine Script Rookie
Posts: 4
Joined: June 9th, 2021

Strange PineScript Issue

Team,

I wrote this very simple code which basically checks if close is less than open, if is then i just add a label. I added arrays to debug the values, so you may ignore.

However, "checkEntryCondition()" function is not working as expected. Although, close & open values are reported correctly. Can somebody extend their help.

Appreciate your inputs.

Code: Select all

//@version=4
study("Test", overlay=true)

valsOpen = array.new_float(1, 0)
valsClose = array.new_float(1, 0)

// Function to validate if a candle meets the given criteria
checkEntryCondition() => 
    array.insert(valsOpen, 0, open)
    array.insert(valsClose, 0, close)
    close < open

scr_label = 'Screener: \n##########\n'
//long
s5 = security("AIAENG", "75", checkEntryCondition())

scr_label := s5 ? scr_label + "AIAENG" + '\n'  : scr_label
scr_label := scr_label + "close->" + tostring(array.get(valsClose, 0)) + " open->" + tostring(array.get(valsOpen, 0)) + '\n' 

if barstate.islast 
    lab_l = label.new(bar_index, high, scr_label, color=color.green, textcolor=color.white, style =  label.style_labeldown)
    label.delete(lab_l[1])

plot(close, color=color.new(color.white, 100))

CanYouCatchMe01
Pine Script Rookie
Pine Script Rookie
Posts: 6
Joined: June 28th, 2021

Re: Strange PineScript Issue

I got it to work.
Image

You have assigned your function when you wrote:

Code: Select all

checkEntryCondition() =>
    close < open
But you are never calling the function, so the function never runs. You run the function by typing:

Code: Select all

checkEntryCondition()
Here is the full code:

Code: Select all

//@version=4
study("My Script", overlay=true)

checkEntryCondition() =>
    close < open

plotshape(checkEntryCondition(), text="Buy",  style=shape.labeldown, color=color.white, textcolor=color.black, location=location.abovebar)

Return to “Pine Script Q&A”