Wanted to highlight candles which showing HH & LL formation as I'm still trying my luck with pine coding
- check the condition if High, Low & Close of current candle is greater than the previous candle High, Low & Close, once all the 3 conditions are met, will put a Green shape below.
- check the condition if High, Low & Close of current candle is less than the previous candle High, Low & Close, once all the 3 conditions are met, will put a Red shape above.
Additionally conditions that needs help are below 3. After checking 1st condition, if the next new candle is satisfying this condition don't want green shape below this new candle as the previous candle has already highlighted the price action 4. After checking 2st condition, if the next new candle is satisfying this condition don't want red shape above this new candle as the previous candle has already highlighted the price action 5. As well, if either one of the 3 price values are within the range of the previous candle, should use the same green or red trend without any shape.
Code for the first 2 condition is below which is giving too many indication of Green or Red shape which as well need to be indicated only at the start of the candle and not for all subsequent candles.
//@version=5
indicator("Price Comparison", shorttitle="PCS", overlay=true)
// Function to check if conditions are met
checkConditions() => high >= high[1] and low >= low[1] and close >= close[1]
checkOppositeConditions() => high <= high[1] and low <= low[1] and close <= close[1]
// Variable to track the starting bars for both conditions
var int startingBar = na
var int startingOppositeBar = na
// Update starting bars when conditions are met, considering consecutive candles
if (checkConditions() and not checkConditions()[1])
startingBar := bar_index
if (checkOppositeConditions() and not checkOppositeConditions()[1])
startingOppositeBar := bar_index
// Plotting shapes below/above the candle when conditions are met
plotshape(checkConditions() ? startingBar : na, style=shape.triangleup, color=color.green, size=size.tiny, location=location.belowbar)
plotshape(checkOppositeConditions() ? startingOppositeBar : na, style=shape.triangledown, color=color.red, size=size.tiny, location=location.abovebar)
Result from the above code:
