OPEN-SOURCE SCRIPT

raka 3-Candle Pattern with 20 MA

//version=5
indicator("3-Candle Pattern with 20 MA", overlay=true)

// Input settings
maLength = input.int(20, title="Moving Average Length")
patternLookback = input.int(3, title="Pattern Lookback Period")

// Calculate 20-period moving average
ma = ta.sma(close, maLength)

// Define 3-candle pattern conditions for a buy signal
// Example pattern: Higher Highs and Higher Lows over the last 3 candles
isPattern = ta.highest(high, patternLookback) == high[0] and ta.lowest(low, patternLookback) == low[patternLookback - 1]

// Buy signal: 3-candle pattern and current close above the 20-period MA
buySignal = isPattern and close > ma

// Plot the moving average
plot(ma, color=color.blue, linewidth=2, title="20 MA")

// Plot buy signals
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", title="Buy Signal")

// Optional: Highlight the 3-candle pattern on the chart
bgcolor(isPattern ? color.new(color.green, 90) : na, title="Pattern Highlight")
Moving Averages

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer