I am writing a basic candlestick detection functionality where I want to also detect 2-candles and 3-candles pattern.
I am able to detect two candles patterns like Inside Candle or Engulfing.
But I want to encircle the two candles into a circle such that anyone checking it can be benefited with this, specially the new learners.
How can I do it?
My current detection code is:
// Two Candles Patterns ///////////////////////////////////////////////////////////////////////////////////////
// Engulfing Pattern
// op: Open Prev, cp: Close Prev .. so on
bullish_engulfing(op, cp, hp, lp, o, c, h, l) => red(op, cp) and green(o, c) and (StrictEngulf ? (c > hp and o < lp) : (h > hp and l < lp))
bearish_engulfing(op, cp, hp, lp, o, c, h, l) => green(op, cp) and red(o, c) and (StrictEngulf ? (o > hp and c < lp) : (h > hp and l < lp))
plotshape(bullish_engulfing(open[1], close[1], high[1], low[1], open, close, high, low), title='Bull-Engulf', text='Bull-Engulf', location=location.belowbar, style=shape.triangleup, color=color.green, textcolor=color.green)
plotshape(bearish_engulfing(open[1], close[1], high[1], low[1], open, close, high, low), title='Bear-Engulf', text='Bear-Engulf', location=location.abovebar, style=shape.triangledown, color=color.red, textcolor=color.red)
// Inside Candle (Harami) Pattern
// op: Open Prev, cp: Close Prev .. so on
bullish_inside_candle(op, cp, hp, lp, o, c, h, l) => red(op, cp) and green(o, c) and (StrictInsideCandle ? (op > h and cp < l) : (hp > h and lp < l))
bearish_inside_candle(op, cp, hp, lp, o, c, h, l) => green(op, cp) and red(o, c) and (StrictInsideCandle ? (cp > h and op < l) : (hp > h and lp < l))
plotshape(bullish_inside_candle(open[1], close[1], high[1], low[1], open, close, high, low), title='Bull-IC', text='Bull-IC', location=location.belowbar, style=shape.triangleup, color=color.green, textcolor=color.green)
plotshape(bearish_inside_candle(open[1], close[1], high[1], low[1], open, close, high, low), title='Bear-IC', text='Bear-IC', location=location.abovebar, style=shape.triangledown, color=color.red, textcolor=color.red)
The photo I get is:
I have two queries:
- How can I add the circle across the 2 or 3 candles in case of multi-candlestick patterns?
- How, if needed, I can erase out any
plotscharorplotshapeI did in the previous candles? Because when I can encircle 2 or more candles to detect a multi-candle pattern, then keeping the previous candle type does not make a lot of sense (e.g. morning/evening star .. where I want to erase out the Doji on the second candle after I detect the 3 candle formed a definite pattern).

