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

Pine Script: print not NaN values of a series

The following script creates a label for each element of the series. How can one create a label only on candles with corresponding not NaN values?

//@version=5
indicator('Print text values', overlay=true)
length = input(2)
up1 = ta.pivothigh(high, length, length)

l = label.new(bar_index-length, high, str.tostring(up1))

enter image description here

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

>Solution :

There is actually a na() function to test if the value is na.

So, you can do the following.

//@version=5
indicator('Print text values', overlay=true)
length = input(2)
up1 = ta.pivothigh(high, length, length)

if not na(up1)
    l = label.new(bar_index-length, high, str.tostring(up1))
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