// 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")