Indicator · Pine Script v6 · On the chart

Zen rEMA

by Zen-Tim

Zen rEMA is an overlay indicator that calculates an exponential or simple moving average and an ATR-normalized slope angle over a chosen lookback.

View on GitHub

GitHub stars29on the repository
Pine versionv6current
Lines of code86
Settings12inputs
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

86 lines of Pine Script v6 from indicators/Zen-REMA/zen-rema-v6.0.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

zen-rema-v6.0.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Zen_Tim_Trades

//@version=6
indicator('Zen rEMA v6.0 · 20260923', shorttitle = 'Zen rEMA v6.0', overlay = true, max_lines_count = 300, max_labels_count = 200)

// ─── Inputs ───────────────────────────────────────────────
grpMA = 'Moving Average'
len    = input.int(20, 'Length', minval = 1, group = grpMA)
src    = input.source(close, 'Source', group = grpMA)
useEma = input.bool(true, 'Use EMA? (Off = SMA)', group = grpMA)
offset = input.int(0, 'Offset', minval = -500, maxval = 500, group = grpMA)

grpAng = 'Slope'
i_lookback   = input.int(3, 'Lookback', minval = 1, group = grpAng)
i_atrPeriod  = input.int(10, 'ATR Period', minval = 1, group = grpAng)
acceleration = input.int(10, 'Acceleration angle', minval = 1, group = grpAng)
showAccel    = input.bool(false, 'Show Acceleration?', group = grpAng)

grpSig = 'Signals'
showAlwaysIn = input.bool(false, 'Show Always In from MA?', group = grpSig)
showMIG      = input.bool(false, 'Show MIG Reversals?', group = grpSig)
ignoreBars   = input.int(2, 'Bars to ignore at start of day', minval = 0, group = grpSig)

grpScalp = 'Scalp size'
scalpLookback = input.int(8, 'Avg bar range lookback', minval = 1, group = grpScalp)

// ─── Moving average and slope ─────────────────────────────
ma    = useEma ? ta.ema(src, len) : ta.sma(src, len)
angle = math.todegrees(math.atan((ma - ma[i_lookback]) / ta.atr(i_atrPeriod) / i_lookback))

// ─── Bar types ────────────────────────────────────────────
isBull = close > open
isBear = close < open

// Two bars in a row closing on the same side of the MA (each bar vs its own MA value)
twoBullCloseAbove = isBull and isBull[1] and close > ma and close[1] > ma[1]
twoBearCloseBelow = isBear and isBear[1] and close < ma and close[1] < ma[1]

// ─── New day and ignore window ────────────────────────────
newDay = timeframe.isintraday and timeframe.change('D')
var int barsIntoDay = 0
barsIntoDay := newDay ? 0 : barsIntoDay + 1
inIgnore = timeframe.isintraday and barsIntoDay < ignoreBars

// ─── Always In state ──────────────────────────────────────
ailSwitch = twoBullCloseAbove and not twoBullCloseAbove[1] and not inIgnore
aisSwitch = twoBearCloseBelow and not twoBearCloseBelow[1] and not inIgnore

var int alwaysIn = 0
if newDay
    alwaysIn := 0
if ailSwitch
    alwaysIn := 1
else if aisSwitch
    alwaysIn := -1

plotshape(showAlwaysIn and ailSwitch, title = 'AIL switch', style = shape.triangleup,   location = location.belowbar, color = color.blue)
plotshape(showAlwaysIn and aisSwitch, title = 'AIS switch', style = shape.triangledown, location = location.abovebar, color = color.red)

// ─── MIG reversal ─────────────────────────────────────────
// Gap between this bar and the bar two back, with both bars the same colour
migBull = low > high[2] and isBull[2] and isBull
migBear = high < low[2] and isBear[2] and isBear

if showMIG and not inIgnore and migBull and alwaysIn < 0
    label.new(bar_index, low, 'MIG Rev', style = label.style_label_up, color = color.white, textcolor = color.black, size = size.small)
if showMIG and not inIgnore and migBear and alwaysIn > 0
    label.new(bar_index, high, 'MIG Rev', style = label.style_label_down, color = color.white, textcolor = color.black, size = size.small)

// ─── MA line ──────────────────────────────────────────────
maColor = angle > 0 ? (twoBullCloseAbove ? color.blue : color.green) : angle < 0 ? (twoBearCloseBelow ? color.red : color.orange) : #9598a1
plot(ma, title = 'MA', color = maColor, linewidth = 1, offset = offset)

// ─── Acceleration lines ───────────────────────────────────
if showAccel and angle > acceleration
    line.new(bar_index, ma, bar_index, high, color = color.rgb(76, 175, 79, 20), width = 1)
if showAccel and angle < -acceleration
    line.new(bar_index, ma, bar_index, low, color = color.rgb(255, 82, 82, 20), width = 1)

// ─── Data window only (does not touch the price scale) ────
avgBarRange = ta.sma(high - low, scalpLookback)
plot(angle, title = 'MA Angle', display = display.data_window)
plot(alwaysIn, title = 'Always In', display = display.data_window)
plot(avgBarRange * 0.8, title = 'Scalp with trend', display = display.data_window)
plot(avgBarRange * 0.4, title = 'Scalp counter-trend', display = display.data_window)

Overview

Optional markers show an always-in state that turns long after two bull bars close above the average and short after two bear bars close below it, resetting on each new day. Separate markers flag MIG reversals when a same-color gap appears against that state. A start-of-day window can suppress these signals on intraday charts. Acceleration and average bar-range inputs are also provided.

Details

Published by

Zen-Tim on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Moving averages, Trend, Candlestick patterns

Markets

Any symbol

Timeframes

M1-M5, M15-H1

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
Lengthint20len
Sourcesourceclosesrc
Use EMA? (Off = SMA)booltrueuseEma
Offsetint0offset
Lookbackint3i_lookback
ATR Periodint10i_atrPeriod
Acceleration angleint10acceleration
Show Acceleration?boolfalseshowAccel
Show Always In from MA?boolfalseshowAlwaysIn
Show MIG Reversals?boolfalseshowMIG
Bars to ignore at start of dayint2ignoreBars
Avg bar range lookbackint8scalpLookback
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