Search code examples
comparepine-scriptseries

Get a value of float from a series float in PineScript


I have a 'series float' that was given from ta.atr() function. I need to compare the last element of this 'series float' to another float number. But anything I do, I can not get the element as a float number to make the comparison. What can I do?

Here is part of my code that I'm dealing with the problem:

int min_dev = 1
ATR = ta.atr(length) *100 /close[1] 
var float dev_threshold = min_dev * ATR[1]

if (math.abs(dev) >= dev_threshold)
    iline = line.new(iLast, pLast, index, price, color = color.blue, xloc = xloc.bar_index)

In the code above, the comparison does not complete, and if doesn't complete.


Solution

  • With the var keyword, this code will be executed only once, at the first bar of your chart.

    Maybe you should remove the var keyword no?

    var being executed at the first bar and referring to ATR[1] being the previous value of ATR, I'm not sure if there is any previous value to fetch here actually....