'How to turn a strategy into non repainting labels

I have a strategy built that only takes one trade in each direction at a time, but I'd like to turn it into just an indicator with labels using plotshape. Every method I have tried to use a variable increase when my buy or sell parameter hits more than once in a row, doesn't work to turn the labels off until the opposite signal comes in. So basically it is repainting a buy or sell signal multiple times when I want it to give one signal and then shut off until the opposite trade parameters are met. So one buy signal, then one sell signal, no irrelevant signals in the middle. How can I achieve this?

//Strategy Trade Signal Bull
if bull
    strategy.entry('Bull', strategy.long, comment='Bull')
    strategy.close('Bull', when=bear, comment='Bear')

//Strategy Trade Signal Bear
if bear
    strategy.entry('Bear', strategy.short, comment='Bear')
    strategy.close('Bear', when=bull, comment='Bull')


Solution 1:[1]

You need a variable to see if you are already long.

This should give you an idea:

var is_long = false

is_buy = barstate.isconfirmed and not is_long and bull  // Buy only if we are not already in a long position
is_sell = barstate.isconfirmed and is_long and bear  // Sell only if we are in a long position
is_long := is_buy ? true : is_sell ? false : is_long

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vitruvius