Indicator · Pine Script v6 · Own pane

Moving Average Shift [ChartPrime]

by theonetrade· code credited to ChartPrime

Moving Average Shift [ChartPrime] computes a user-selected moving average directly on the price chart while plotting a momentum oscillator in a separate pane.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code79
Settings10inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

79 lines of Pine Script v6 from assets/indicator/bit-exact/moving_average_shift_chartprime_aApUyBnk.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

moving_average_shift_chartprime_aApUyBnk.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime

//@version=6
indicator("Moving Average Shift [ChartPrime]", "MA Shift [ChartPrime]", overlay = false)

// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{

type_ma = input.string("SMA", "Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "MA")
length = input.int(40, "Length", inline = "ma", group = "MA")
source = input.source(hl2, "", inline = "ma", group = "MA")
grp = "MA Shift Oscillator"
osc_len = input.int(15, "Length", group = grp, inline = "osc")
osc_threshold = input.float(0.5, "", step = 0.1, group = grp, inline = "osc")
osc_cross = input.bool(true, "⯁", group = grp, inline = "osc")

// Colors
osc_col_up1 = input.color(#1dd1c2, "", inline = "c", group = "color")
osc_col_up2 = input.color(#17a297, "", inline = "c", group = "color")
osc_col_dn1 = input.color(color.yellow, "", inline = "c", group = "color")
osc_col_dn2 = input.color(color.orange, "", inline = "c", group = "color")

// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{

// Smoothing MA Calculation
ma(source, length, MAtype) =>
    switch MAtype
        "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)

// MA 
MA = ma(source, length, type_ma) 
color = source >= MA ? osc_col_up2 : osc_col_dn2

// Osc 
diff = source - MA 
perc_r = ta.percentile_linear_interpolation(diff, 1000, 99)

osc = ta.hma(ta.change(diff / perc_r, osc_len), 10)
osc_col = osc > 0 ? (osc > osc[1] ? osc_col_up1 : osc_col_up2) : (osc < osc[1] ? osc_col_dn1 : osc_col_dn2)


// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{

// MAs Plot
plot(MA, "SMA-based MA", color=color, force_overlay = true, linewidth = 2)
plot(MA, "SMA-based MA", color=color.new(color, 80), force_overlay = true, linewidth = 7)

barcolor(color)
plotcandle(open, high, low, close, title='Title', 
         color = color, wickcolor=color, bordercolor = color, force_overlay = true)

// Oscillator Plot
top = osc_threshold
bot = -top
plot(osc, style = plot.style_columns, color = osc_col)
p1 = plot(top, display = display.none, editable = false)
p0 = plot(0, display = display.none, editable = false)
p2 = plot(bot, display = display.none, editable = false)

fill(p1, p0, top, 0, color.new(osc_col, 70), color.new(osc_col, 100))
fill(p2, p0, 0, bot, color.new(osc_col, 100), color.new(osc_col, 80))


bool sig_up = osc_cross ? ta.crossover(osc, osc[2]) and osc < -osc_threshold : bool(na)
bool sig_dn = osc_cross ? ta.crossunder(osc, osc[2]) and osc > osc_threshold : bool(na)

plotshape(sig_up, "Up", shape.diamond, location.belowbar, osc_col_up1, force_overlay = true, size = size.tiny)
plotshape(sig_dn, "Dn", shape.diamond, location.abovebar, osc_col_dn1, force_overlay = true, size = size.tiny)
// --------------------------------------------------------------------------------------------------------------------}

Overview

The oscillator measures normalized price deviations from the moving average, smoothed via a Hull Moving Average and scaled using historical percentile linear interpolation. It recolors price candles based on trend direction and highlights threshold crossovers. Settings allow customizing the moving average type, calculation lengths, thresholds, and color palettes.

Details

Published by

theonetrade on GitHub

Code credit

ChartPrime, as written in the script's header

Draws

Separate pane below the chart

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
TypestringSMAtype_ma
Lengthint40length
sourcesourcehl2source
Lengthint15osc_len
osc_thresholdfloat0.5osc_threshold
⯁booltrueosc_cross
osc_col_up1color#1dd1c2osc_col_up1
osc_col_up2color#17a297osc_col_up2
osc_col_dn1colorcolor.yellowosc_col_dn1
osc_col_dn2colorcolor.orangeosc_col_dn2
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

947 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 5 weeks ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
408 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

MACD

by Alorse
368 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 3 months ago · None stated GitHub repository of MACD

[TVT] OBV with EMA

by namuan
321 stars

Calculates On-Balance Volume (OBV) alongside two Exponential Moving Averages (EMAs) applied directly to the cumulative OBV line. The indicator tracks volume flow relative to price movement and smooths it using short-term and longer-term EMAs to highlight volum

Indicator v6 VolumeOscillators & momentum
Updated 8 days ago · MIT GitHub repository of [TVT] OBV with EMA
228 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 4 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

MACD-V

by harryguiacorn
220 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers