Search code examples
pine-scriptpine-script-v4

Pinescript v4 change function


Why are these implementations has different results?

highChange = change(high)
lowChange = change(low)
plot(((change(high) > change(low) and change(high) > 0 ? change(high) : 0)), linewidth = 1, color = color.red)
plot(((highChange > lowChange and highChange > 0 ? highChange : 0)), linewidth = 1, color = color.blue)

enter image description here


Solution

  • Some of your calculations are behind a conditional statement thus they don't get calculated with each tick and Pine is throwing a warning:

    The function 'change' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope.

    Tradingview warning