lazy_lazar
lazy_lazar

Reputation: 49

How to check is the last condition true?

I have 2 conditions:

cond_1 = rsi > 70
cond_2 = rsi < 30

Let say cond_2 has to be the last condition before:
cond_3 = close > base

How to do that? Thank you.

Upvotes: 0

Views: 456

Answers (1)

rumpypumpydumpy
rumpypumpydumpy

Reputation: 3813

By using a var bool that retains it's value and can be flipped when 1 & 2 occur. Once cond_2 has occurred, last_was_cond_2 will remain true until cond_1 happens.

cond_1 = rsi > 70
cond_2 = rsi < 30

var bool last_was_cond_2 = false

if cond_1
    last_was_cond_2 := false
else if cond_2
    last_was_cond_2 := true
    
cond_3 = last_was_cond_2 and close > base

Upvotes: 1

Related Questions