Indicator · Pine Script v5 · Own pane

Standardized MA Difference

by Zettt

This indicator plots the percentage difference between a fast exponential moving average and a slow one, scaled by the close, in a separate pane.

View on GitHub

GitHub stars43on the repository
Pine versionv5runs as is
Lines of code45
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago23 Sep 2025

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

45 lines of Pine Script v5 from Standardized MA Difference.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Standardized MA Difference.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Zettt
// Plots difference of price to the difference of two EMAs in percent. The idea is that if price is rallying strongly
// it would naturally travel further away from a moving average. By calculating the percentage,
// we can standardize trend strength.

//@version=5
indicator(title="Standardized MA Difference", shorttitle="Standardized MA Diff", timeframe="", timeframe_gaps=true)
// Getting inputs
fastEMALength = input(title = "Fast Length", defval = 21)
slowEMALength = input(title = "Slow Length", defval = 55)
src = input(title = "Source", defval = close)
lookback = input.int(defval = 50, title = "Percentile Lookback", minval = 1, group = "Percentile Ranking")
percentileEMALength = input.int(defval = 20, title = "EMA Length", minval = 1, group = "Percentile Ranking")
percentileRankExtreme = input.int(defval = 5, title = "Percentile Extreme", minval = 1, step = 1, group = "Percentile Ranking")

// Calculating
fastEMA = ta.ema(src, fastEMALength)
slowEMA = ta.ema(src, slowEMALength)
macd = fastEMA - slowEMA

differenceToPrice = macd / close * 100

// Color gradient
bottomColor = input.color(defval = color.rgb(255, 235, 59, 0), title = "Bottom Color", group = "Gradient")
topColor = input.color(defval = color.rgb(242, 54, 69, 0), title = "Bottom Color", group = "Gradient")
// bottomColorCutoff = input.float(defval = 0, title = "Bottom Color Cutoff", minval = 0, step = 0.1, group = "Gradient", tooltip = "Below this value, the gradient will not take effect, i.e. the color will stay constant.")
// topColorCutoff = input.float(defval = 100, title = "Top Color Cutoff", minval = 0, step = 0.1, group = "Gradient", tooltip = "Above this value…")

// Calculations and plots
percentileRank = ta.percentrank(differenceToPrice, lookback)
percentileEMA = ta.ema(percentileRank, percentileEMALength)


// Plotting
hline(0, "Zero Line", color = color.new(#787B86, 50))

// plot(macd,   title = "MACD",   color = #2962FF)
plot(differenceToPrice,   title = "Difference to Price in Percent",   color = #2862ff)

// plot percentile ranking
plot(percentileRank, title = "Diff to Price Percentile Rank", color = color.from_gradient(percentileRank, 0, 100, bottomColor, topColor), display=display.none)
plot(percentileEMA, title = "Diff to Price Percentile EMA", color = color.new(#64b5f6, 20), display=display.none)
plot(percentileRank < percentileRankExtreme ? percentileRank : na, title="Lowest Rank", color=color.rgb(255, 235, 59, 80), style=plot.style_columns, histbase=100, display=display.none)
plot(percentileRank > 100-percentileRankExtreme ? percentileRank : na, title="Highest Rank", color=color.rgb(242, 54, 69, 80), style=plot.style_columns, histbase=0, display=display.none)

Overview

Standardized MA Difference treats that gap as a standardized measure of trend strength and draws a zero line. Users set both EMA lengths and the price source. A percentile rank over a chosen lookback, an EMA of that rank, and column marks at extreme ranks are calculated but hidden by default. It does not generate trade entries or exits.

Details

Published by

Zettt on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Moving averages, Oscillators & momentum, 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
Fast Lengthint21fastEMALength
Slow Lengthint55slowEMALength
Sourcesourceclosesrc
Percentile Lookbackint50lookback
EMA Lengthint20percentileEMALength
Percentile Extremeint5percentileRankExtreme
Bottom Colorcolorcolor.rgb(255, 235, 59, 0)bottomColor
Bottom Colorcolorcolor.rgb(242, 54, 69, 0)topColor
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

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Elder Impulse System

by mihakralj
99 stars

Elder Impulse System plots a column series in a separate pane. It compares a 13-period exponential moving average with its previous value and a MACD histogram with its previous value. A rising EMA and rising histogram print 1, a falling EMA and falling histogr

Indicator v5 TrendOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Elder Impulse System
47 stars

This indicator calculates the Williams Gator Oscillator derived from Bill Williams Alligator lines and plots dual histograms in a separate pane. The upper histogram displays the absolute difference between the Jaw and Teeth moving averages, while the lower his

Indicator v6 Oscillators & momentumMoving averages
Updated 8 months ago · MIT GitHub repository of Williams Gator Oscillator

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