Search code examples
plotconditional-statementspine-scriptpine-script-v5

How to plot condition to avoid repeating results


I'm trying to do some things in pineScript using this condition:

if close > ema 34 -> plot "Long"

now, the "Long" is displayed each time, the condition is true, but I only want to see the plot the first time, when it's happening, and the other results should be ignored.

Another condition is probably missing here, but what does it have to look like?

//@version=5
indicator("EMA_Long", overlay = true)
ema = ta.ema(close,34)
longCondition = close \> ema
label = "Long Triangle"
plotshape(longCondition, label, location=location.belowbar, color=color.yellow, style=shape.triangleup,     text = "Long", textcolor = color.yellow)
plot(ema)

Solution

  • You can use :

    longCondition = close > ema and not(close[1] > ema[1])
    

    This way, your long Condition will be true only when it is happening