Is there a way to count non-consecutive and consecutive candles or to solve my problem in TradingView?

My stratedy is based on conditions:

From the last 4 candles, if:

3 out of 4 candles are with the trend, take the trade. BUT: if the last candle is against the trend, don't take the trade.

It sounds confusing but I attached the picture, so is stupid simple, however I have NO IDEA how to do this on pine, I am new at this and a little help would be appreciated. Thanks.

Upvotes: 1

Views: 206

Answers (2)

Wisang Jati Anggoro
Wisang Jati Anggoro

Reputation: 153

A little bit update to Daveatt's answer, because you say you won't take the trade if the last candle is not in the trend:

ThreeValidInLastFour = ta.sum(condition ? 1 : 0, 4) >= 3 and condition

Upvotes: 0

Dave
Dave

Reputation: 865

Like this

ThreeValidInLastFour = ta.sum(condition ? 1 : 0, 4) >= 3

Upvotes: 1

Related Questions