'indicator for 3 consecutive bars

I am working on some code to fire off an alert when there are 3 consecutive bars accelerating in size, see attached screenshot of XLV(5 mins chart) on 3-25 for example. below is my code so far, what I have noticed is that it sometime seems work fine, but there are also many false alarms, see attached pictures. I have looked my code multiple times but don't see a defect, but I might be missing something, can anyone help to take a look? or is there a better way to achieve the same results?

study("3 CCBA", overlay=true)
// * overlay = true will prevent the indicator from showing in seperate panel

// * Using bull case: 3 consecutive bars, most recent one closes at or around its high(90% of high - low), the -1 bar and -2 bar should have the body (close - open) that is more than 50% of the bar size (high - low), and bar body size is accelerating
// * (close - open) / (high - low) > 0.5, this is to filter out doji bars, the body of the bar has to be more than 50% of the bar size (high - low).

higherCloses = (close > open) and ((close - low) / (high - low) >= 0.9) and ((close - open) / (high - low) >= 0.5) and
                (close[1] > open[1]) and ((close[1] - low[1]) / (high[1] - low[1]) >= 0.5) and 
                (close[2] > open[2]) and ((close[2] - low[2]) / (high[2] - low[2]) >= 0.4) and
                (low[2] < low[1]) and (low[1] < low) and
                (high[2] < high[1]) and (high[1] < high) and
                ((close[2] - open[2]) <= (close[1] - open[1])) and ((close[1] - open[1]) <= (close - open))

lowerCloses = (close < open) and ((close - high) / (low - high) >= 0.9) and ((open - close) / (high - low) >= 0.5) and
                (close[1] < open[1]) and ((close[1] - high[1]) / (low[1] - high[1]) >= 0.5) and 
                (close[2] < open[2]) and ((close[2] - high[2]) / (low[2] - high[2]) >= 0.4) and
                (high[2] > high[1]) and (high[1] > high) and
                (low[2] > low[1]) and (low[1] > low) and
                ((open[2] - close[2]) <= (open[1] - close[1])) and ((open[1] - close[1]) <= (open - close))

allConditions = higherCloses or lowerCloses
alertcondition(allConditions, title='3 CCBA!', message= '3 CCBA!')
plot(series=close)

xlv tsla false alarm



Solution 1:[1]

Turns out the code is fine, the reason it is not doing exactly what I am looking for is because I didn't recreate the alert after making code changes to the script. Once I delete the old alert and recreate the new one, false alarm goes away.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 diabloooo0