I want to be able to show how many candles within a certain period of time are above EMA21.
So, if at the end of that period, there are 15 candles above EMA21, it should show a bubble with "15" above the last candle of that period.
In my code below, it shows "0" for some reason even though there are candles above EMA21, so it seems my recursive logic is not working as expected, not sure why.
Can anyone help out? Thanks!
So, if at the end of that period, there are 15 candles above EMA21, it should show a bubble with "15" above the last candle of that period.
In my code below, it shows "0" for some reason even though there are candles above EMA21, so it seems my recursive logic is not working as expected, not sure why.
Can anyone help out? Thanks!
Code:
def ema21 = ExpAverage(close, 21);
input startTime = 0929;
input endTime = 1300;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
def candleToShowBubbleOn = SecondsFromTime(1300) == 0 and secondsTillTime(1300) == 0;
def count = if targetPeriod and !targetPeriod[1] then close > ema21
else if targetPeriod then close > ema21 + count[1]
else count[1];
addChartBubble(candleToShowBubbleOn, high, count, Color.RED, yes);