To remove pyramiding from your TradingView study, your order conditions need to alternate. This is achieved by using the occurrence time of a condition and comparing the condition times against each other.
Only when one condition is true and the opposite condition was previously true, does the signal reflect a positive condition.
long = YourLongCondition
short = YourShortCondition
last_long = long ? time : nz(last_long)
last_short = short ? time : nz(last_short)
long_signal = crossover(last_long, last_short)
short_signal = crossover(last_short, last_long)
strategy.entry("Long", strategy.long, when=long_signal)
strategy.entry("Short", strategy.short, when=short_signal)