Indicator · Pine Script v6 · On the chart

Zen EMA Pullback Patterns

by Zen-Tim

Zen EMA Pullback Patterns identifies pullback formations relative to an Exponential Moving Average on the price chart.

View on GitHub

GitHub stars29on the repository
Pine versionv6current
Lines of code62
Settings7inputs
LicenceMIT
Last update2 weeks ago14 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

62 lines of Pine Script v6 from indicators/Zen-CTMC/zen-ctmc-v1.1.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

zen-ctmc-v1.1.txt
//@version=6
indicator("Zen EMA Pullback Patterns v1.1 · 20260923", shorttitle="Zen EMA PB", overlay=true)

// ── Inputs ─────────────────────────────────────────────
emaLen     = input.int(20, "EMA length", minval=1)
emaSrc     = input.source(close, "EMA source")
fullMC     = input.bool(false, "Full micro channel (bear: lower lows too / bull: higher highs too)")
everyBar   = input.bool(false, "Mark every bar that completes a pattern (off = first bar only)")
showEma    = input.bool(true, "Show EMA")
showLabels = input.bool(false, "Show labels")
colorBars  = input.bool(true, "Colour signal bar (bear pattern = red, bull pattern = green)")

// ── Core ───────────────────────────────────────────────
ema   = ta.ema(emaSrc, emaLen)
bear  = close < open          // doji (close == open) is neutral and breaks the run
bull  = close > open
above = close > ema
below = close < ema

// ── 3-bar pattern: 3 bear bars, all 3 closes above EMA / 3 bull bars, all 3 closes below EMA
bear3 = bear and bear[1] and bear[2] and above and above[1] and above[2]
bull3 = bull and bull[1] and bull[2] and below and below[1] and below[2]

// ── 4-bar micro channel: 3 lower highs, all 4 closes above EMA / 3 higher lows, all 4 closes below EMA
lowerHighs  = high < high[1] and high[1] < high[2] and high[2] < high[3]
lowerLows   = low  < low[1]  and low[1]  < low[2]  and low[2]  < low[3]
higherLows  = low  > low[1]  and low[1]  > low[2]  and low[2]  > low[3]
higherHighs = high > high[1] and high[1] > high[2] and high[2] > high[3]
above4 = above and above[1] and above[2] and above[3]
below4 = below and below[1] and below[2] and below[3]

bearMC = lowerHighs and (not fullMC or lowerLows) and above4
bullMC = higherLows and (not fullMC or higherHighs) and below4

// ── First-bar-only filter, confirmed bars only
fire(c) => (everyBar ? c : c and not c[1]) and barstate.isconfirmed
sBear3  = fire(bear3)
sBull3  = fire(bull3)
sBearMC = fire(bearMC)
sBullMC = fire(bullMC)

// ── Plots (split so shapes never overlap on the same bar)
plot(showEma ? ema : na, "EMA", color=color.new(color.blue, 0), linewidth=2)

// Signal bar colour: bar 3 of the 3-bar pattern, bar 4 of the micro channel
bearSig = sBear3 or sBearMC
bullSig = sBull3 or sBullMC
barcolor(colorBars and bearSig ? color.red : colorBars and bullSig ? color.green : na, title="Signal bar colour")

plotshape(showLabels and sBear3 and not sBearMC, "Bear 3 above EMA",  shape.triangledown, location.abovebar, color.new(color.red, 0),    text="3",    textcolor=color.red,    size=size.small)
plotshape(showLabels and sBearMC and not sBear3, "Bear MC above EMA", shape.triangledown, location.abovebar, color.new(color.orange, 0), text="MC",   textcolor=color.orange, size=size.small)
plotshape(showLabels and sBear3 and sBearMC,     "Bear 3 + MC",       shape.triangledown, location.abovebar, color.new(color.maroon, 0), text="3+MC", textcolor=color.maroon, size=size.small)

plotshape(showLabels and sBull3 and not sBullMC, "Bull 3 below EMA",  shape.triangleup, location.belowbar, color.new(color.green, 0), text="3",    textcolor=color.green, size=size.small)
plotshape(showLabels and sBullMC and not sBull3, "Bull MC below EMA", shape.triangleup, location.belowbar, color.new(color.teal, 0),  text="MC",   textcolor=color.teal,  size=size.small)
plotshape(showLabels and sBull3 and sBullMC,     "Bull 3 + MC",       shape.triangleup, location.belowbar, color.new(color.olive, 0), text="3+MC", textcolor=color.olive, size=size.small)

// ── Alerts
alertcondition(sBear3,  "Bear 3 above EMA",  "3 bear bars closed above the EMA")
alertcondition(sBull3,  "Bull 3 below EMA",  "3 bull bars closed below the EMA")
alertcondition(sBearMC, "Bear MC above EMA", "Bear micro channel above the EMA")
alertcondition(sBullMC, "Bull MC below EMA", "Bull micro channel below the EMA")

Overview

Zen EMA Pullback Patterns detects 3-bar pullbacks consisting of three consecutive bearish bars above the EMA or bullish bars below it, as well as 4-bar micro channels defined by sequential lower highs or higher lows. The script plots the EMA baseline, colors signal bars upon pattern completion, and displays optional labels. Settings allow customization of EMA parameters, full micro channel requirements, and filtering between initial trigger bars or all completing bars.

Details

Published by

Zen-Tim on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Moving averages, Candlestick patterns, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
EMA lengthint20emaLen
EMA sourcesourcecloseemaSrc
Full micro channel (bear: lower lows too / bull: higher highs too)boolfalsefullMC
Mark every bar that completes a pattern (off = first bar only)boolfalseeveryBar
Show EMAbooltrueshowEma
Show labelsboolfalseshowLabels
Colour signal bar (bear pattern = red, bull pattern = green)booltruecolorBars
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

55 stars

This indicator overlays on the price chart and provides trend and momentum analysis. It calculates and plots three exponential moving averages with fixed periods of 20, 50, and 200 using yellow, orange, and blue colors respectively. The script also computes th

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · Apache-2.0 GitHub repository of Trend & Momentum Analysis

Hanging Man - Bearish

by TWODS-CAPITAL
37 stars

This overlay indicator marks a bearish hanging man candlestick on the price chart. It looks for a small real body sitting in the upper part of the range, a lower shadow at least twice the body, and no upper shadow, and only while an uptrend filter is active. T

Indicator v5 Candlestick patternsTrend
Updated 3 years ago · MIT GitHub repository of Hanging Man - Bearish
15 stars

This indicator plots Bollinger Bands and smoothed HAMA candles on the price chart. It builds each candle from separate moving averages of open, high, low and close, using selectable EMA, SMA or WMA lengths. A simple moving average forms the band basis, and an

Indicator v5 Candlestick patternsMoving averages
Updated 4 months ago · Apache-2.0 GitHub repository of NSDT HAMA Candles with Bollinger Bands

Calculates adaptive arithmetic candles by blending price data with Kaufman Efficiency Ratio smoothing and a linear regression anchor. It measures trend health using a zero-to-hundred Quality Score derived from market efficiency, regression slope, and normalize

Indicator v6 TrendCandlestick patterns
Updated yesterday · MIT GitHub repository of Adaptive Arithmetic Candles + Quality Score [WavesUnchained]

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers