0
votes

I'm having a tough time getting this figured out.

Basically I have an indicator I'm trying to make a condition for bullish vs bearish.

The components are a channel and a moving average, and I want to have the crossover(sma, lower_bound) make the bullish condition true until the moving average crosses above the upper bound and have the bearish condition become true on crossunder(sma, upper_bound)

I have attempted a few different ways but what ends up happening is that the bullish condition only occurs on the crossover bar and doesn't persist until the crossunder.

TLDR I need to make a one time condition (cross) turn a state on and continue until a different cross turns it off.

thanks in advance

1

1 Answers

0
votes

You need to use a var declared variable which persists across bars until changed. Like so :

var bool bullish = false

bull_start = crossover(sma, lower_bound)
bull_stop = crossover(sma, upper_bound)

if bull_start
    bullish := true
else if bull_stop
    bullish := false