Find a series of 5 or more bars?

twelvester

New member
Hi,
Need some help with recursion.

If i would like to find a series of 3 Bullish bars:
i could manually compare close > open and close[1] > open[1] and close[2] > open[2].
What if i changed the number to 5 or more? How can i handle this in a function or loop?
 
Last edited by a moderator:

thanos

New member
Here you go
#define your bull bar condition
def bullBar = close > open
#assign the value of 1 to bullbar else 0
def isBullBar = if bullBar then 1 else 0;
# count the consecutive occurrences of the bullish bars.
def bullBarCount = CompoundValue(1, if isBullBar > 0 then bullBarCount[1] + 1 else 0, 0);
# do something with the bullbarCount like paint a histogram of the consecutive bars.
plot bullTrend = if bullBarCount > 0 then bullBarCount else nan;
bullTrend.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 

Similar threads

Top