Search code examples
pine-scripttradingview-apiindicator

Is there a way to stop it from plotting label shape every time it's True? I only want it to plot it once the conditions true


It's plotting the buy and sell signal repeatedly, instead of just the first time the conditions come true.


// Buy and Sell signals
Buy= math.abs(buying_volume) > math.abs(selling_volume)
Sell= math.abs(selling_volume) > math.abs(buying_volume)

plotshape( Buy ? Buy : na, text='Buy', textcolor=color.white, style=shape.labeldown, color=color.rgb(10, 132, 87), location=location.absolute, size=size.tiny)
plotshape( Sell ? Sell : na, text='Sell', textcolor=color.white, style=shape.labelup, color=color.rgb(188, 12, 12), location=location.absolute, size=size.tiny)

Solution

  • You can use a Boolean. You will need to have a way to reset the boolean though as well.

    BuyBool = true 
            
    // Buy signals
    Buy= math.abs(buying_volume) > math.abs(selling_volume)
    BuyBool := buy ? false : BuyBool
            
    plotshape( Buy and BuyBool == true ? Buy : na, text='Buy', textcolor=color.white, style=shape.labeldown, color=color.rgb(10, 132, 87), location=location.absolute, size=size.tiny)