Indicator · Pine Script v5 · On the chart

Zen MIG Reversal

by Zen-Tim

Zen MIG Reversal is a price action overlay indicator that identifies potential reversal setups using three-bar candlestick sequences, gap rules, and moving average filters.

View on GitHub

GitHub stars29on the repository
Pine versionv5runs as is
Lines of code74
Settings10inputs
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

74 lines of Pine Script v5 from indicators/Zen-MIG-Reversal/zen-mig-reversal-v2.0.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

zen-mig-reversal-v2.0.txt
//@version=5
indicator(title="Zen MIG Reversal v2.0 · 20260923", shorttitle="Zen MIG Reversal", overlay=true, max_boxes_count=500)

// =====================================================
// Moving Average
// =====================================================
maType   = input.string("EMA", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving Average")
maLength = input.int(20, title="MA Length", minval=1, group="Moving Average")
showMA   = input.bool(true, title="Show MA Line", group="Moving Average")

ma(source, length, type) =>
    switch type
        "SMA"        => ta.sma(source, length)
        "EMA"        => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA"        => ta.wma(source, length)
        "VWMA"       => ta.vwma(source, length)

maLine = ma(close, maLength, maType)
plot(showMA ? maLine : na, title="MA", color=color.blue)

// =====================================================
// Signal Settings
// =====================================================
gapMode     = input.string("Micro gap (Brooks)", title="Gap Rule", options=["Micro gap (Brooks)", "Visible gap (strict)"], group="Signal")
maTest      = input.string("Tail beyond MA", title="MA Test", options=["Tail beyond MA", "Close beyond MA", "Whole bar beyond MA"], group="Signal")
confirmOnly = input.bool(true, title="Signal on bar close only", group="Signal")

// =====================================================
// Display
// =====================================================
showArrows = input.bool(true,  title="Show Arrows", group="Display")
showBoxes  = input.bool(true,  title="Show Gap Boxes", group="Display")
bullCol    = input.color(color.blue, title="Bull Colour", group="Display")
bearCol    = input.color(color.red,  title="Bear Colour", group="Display")

// =====================================================
// Logic
// =====================================================
isBull(i) => close[i] > open[i]
isBear(i) => close[i] < open[i]

bullBars = isBull(0) and isBull(1) and isBull(2)
bearBars = isBear(0) and isBear(1) and isBear(2)

bullGap = gapMode == "Visible gap (strict)" ? (low > high[2] and low[1] > high[2]) : low > high[2]
bearGap = gapMode == "Visible gap (strict)" ? (high < low[2] and high[1] < low[2]) : high < low[2]

bullMA = maTest == "Close beyond MA" ? close < maLine : maTest == "Whole bar beyond MA" ? high < maLine : low < maLine
bearMA = maTest == "Close beyond MA" ? close > maLine : maTest == "Whole bar beyond MA" ? low > maLine : high > maLine

confirmed = not confirmOnly or barstate.isconfirmed

bullReversal = bullBars and bullGap and bullMA and confirmed
bearReversal = bearBars and bearGap and bearMA and confirmed

// =====================================================
// Drawing
// =====================================================
if bullReversal and showBoxes
    box.new(left=bar_index[2], right=bar_index, top=low, bottom=high[2], border_color=bullCol, bgcolor=color.new(bullCol, 80))

if bearReversal and showBoxes
    box.new(left=bar_index[2], right=bar_index, top=low[2], bottom=high, border_color=bearCol, bgcolor=color.new(bearCol, 80))

plotshape(showArrows and bullReversal, title="Bull Arrow", style=shape.arrowup, location=location.belowbar, color=bullCol, size=size.small)
plotshape(showArrows and bearReversal, title="Bear Arrow", style=shape.arrowdown, location=location.abovebar, color=bearCol, size=size.small)

// =====================================================
// Alerts
// =====================================================
alertcondition(bullReversal, title="Bull MIG Reversal", message="Bull MIG Reversal — {{ticker}} {{interval}} @ {{close}}")
alertcondition(bearReversal, title="Bear MIG Reversal", message="Bear MIG Reversal — {{ticker}} {{interval}} @ {{close}}")
alertcondition(bullReversal or bearReversal, title="Any MIG Reversal", message="MIG Reversal — {{ticker}} {{interval}} @ {{close}}")

Overview

Zen MIG Reversal checks for consecutive directional bars combined with either Al Brooks micro gaps or strict visible gaps relative to a moving average line. When valid conditions occur, the script draws colored gap boxes and plots signal arrows directly on the price chart. Key settings allow customization of moving average types, gap modes, testing conditions, and bar close confirmation.

Details

Published by

Zen-Tim on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Moving averages, 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
MA TypestringEMAmaType
MA Lengthint20maLength
Show MA LinebooltrueshowMA
Gap RulestringMicro gap (Brooks)gapMode
MA TeststringTail beyond MAmaTest
Signal on bar close onlybooltrueconfirmOnly
Show ArrowsbooltrueshowArrows
Show Gap BoxesbooltrueshowBoxes
Bull Colourcolorcolor.bluebullCol
Bear Colourcolorcolor.redbearCol
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