Indicator · Pine Script v5 · On the chart

CM Ultimate MA MTF V4

by theonetrade· code credited to ChrisMoody

CM Ultimate MA MTF V4 plots fast and slow moving averages directly on the price chart with multi-timeframe functionality.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code141
Settings28inputs
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

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

cm_ultimate_ma_mtf_v4_bkvQ5hNF.pine
//Update 08-24-2021
//Thanks for @sktennis for help with code
//Plots 8 Different types of Moving Averages
//Added Ability to Plot 1 or 2 Moving Averages - Fast MA & Slow MA
//Added Abaility to Plot Fast MA with Multi TimeFrame
//Added Abaility to Plot Slow MA with Multi TimeFrame
//Added Ability to Color Fast MA Based on Slope of MA
//Added Ability to Color Fast MA based on being Above/Below Slow MA
//Added Ability to Plot 8 Types of Moving Averages
//Simple, Exponential, Weighted, Hull, VWMA, RMA, TEMA, & Tilson T3
//Added Ability to Set Alerts Based on:
//Slope Change in the Fast MA Or Fast MA Crossing Above/Below Slow MA.
//Added Ability to Plot "Fill" if Both Moving Averages are Turned ON
//Added Ability to control Transparency of Fill

//Update 12-07-2021
//Converted to V5 PineScript

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChrisMoody

//@version=5
indicator(title="_CM_Ultimate_MA_MTF_V4", shorttitle="_CM_Ult_MA_MTF_V4", overlay=true)
//inputs
//Fast MA Inputs
res1                = input.timeframe("",  "Fast MA TimeFrame", group="Fast MA")
fast_ma_len         = input.int(defval=20, minval=1, maxval=999, title="Fast MA Length",  group="Fast MA")
src1                = input.source(defval=close, title="Fast MA Source", group="Fast MA")
fast_ma_off         = input.int(defval=0, minval=-200, maxval=200, title="Fast MA Offset",  group="Fast MA")
fast_ma_source      = input.string(defval="SMA", title="Fast MA Type", options=["SMA", "EMA", "WMA", "Hull MA", "VWMA", "RMA", "TEMA", "TIL T3"], group="Fast MA")
fast_factorT3       = input.float(defval=.7, title="Fast MA Tilson T3 Factor", minval=0, maxval=99, step = .1, tooltip="Default = .7", group="Fast MA")
//Slow MA Inputs
show_slow_ma        = input.bool(false,title="Show Slow MA?", group="Slow MA")
res2                = input.timeframe("",  "Slow MA TimeFrame", group="Slow MA")
slow_ma_len         = input.int(defval=50, minval=1, maxval=999, title="Slow MA Length",  group="Slow MA")
src2                = input.source(defval=close, title="Slow MA Source", group="Slow MA")
slow_ma_off         = input.int(defval=0, minval=-200, maxval=200, title="Slow MA Offset",  group="Slow MA")
slow_ma_source      = input.string(defval="SMA", title="Slow MA Type", options=["SMA", "EMA", "WMA", "Hull MA", "VWMA", "RMA", "TEMA", "TIL T3"], group="Slow MA")
slow_factorT3       = input.float(defval=.7, title="Slow MA Tilson T3 Factor", minval=0, maxval=99, step= .1, tooltip="Default = .7", group="Slow MA")
//Plot Settings
fast_ma_col         = input.color(#2962FF, title="Fast MA  ", group="Plot Settings", inline="P10")
slow_ma_col         = input.color(#FF6D00, title="Slow MA  ", group="Plot Settings", inline="P10")
fast_ma_wid         = input.int(defval=3, minval=0, maxval=5, title="Fast MA Width",  group="Plot Settings")
slow_ma_wid         = input.int(defval=3, minval=0, maxval=5, title="Slow MA Width",  group="Plot Settings")
show_fast_ma_cc     = input.bool(false, title="Change Fast MA Color Based On Slope?", group="Plot Settings")
fast_ma_smooth      = input.int(defval=2, minval=1, maxval=20, title="Color Smoothing", tooltip="Setting 1 = No Smoothing", group="Plot Settings")
bullish_col         = input.color(color.new(color.green, 0), "Bull Col  ", group="Plot Settings", inline="P40")
bearish_col         = input.color(color.new(color.red, 0),   "Bear Col  ", group="Plot Settings", inline="P40")
show_fast_ma_tr     = input.bool(false, title="Change Fast MA Color Above/Below Slow MA?", group="Plot Settings")
show_fill           = input.bool(true, title="Show Fill?", group="Plot Settings", inline="P50")
fill_transp         = input.int(defval=50, title="Transparency", minval=0, maxval=100, group="Plot Settings", inline="P60")
// Alerts T/F Inputs
alert_Slope_Bull    = input.bool(false, title = "Fast MA Slope Bull", group = "Alerts", inline="Alert10")
alert_Slope_Bear    = input.bool(false, title = "Fast MA Slope Bear", group = "Alerts", inline="Alert10")
alert_Cross_Bull    = input.bool(false, title = "Fast MA Cross Bull", group = "Alerts", inline="Alert20")
alert_Cross_Bear    = input.bool(false, title = "Fast MA Cross Bear", group = "Alerts", inline="Alert20")

//Begin Coding Calcs & Definitions
//Fast MA Calcs
//Hull MA Definition
hullma = ta.wma(2*ta.wma(src1, fast_ma_len/2)-ta.wma(src1, fast_ma_len), math.round(math.sqrt(fast_ma_len)))
//TEMA definition
ema1 = ta.ema(src1, fast_ma_len)
ema2 = ta.ema(ema1, fast_ma_len)
ema3 = ta.ema(ema2, fast_ma_len)
tema = 3 * (ema1 - ema2) + ema3
//Tilson T3
factor = fast_factorT3 * 1 //.10
gd(src1, fast_ma_len, factor) => ta.ema(src1, fast_ma_len) * (1 + factor) - ta.ema(ta.ema(src1, fast_ma_len), fast_ma_len) * factor 
t3(src1, fast_ma_len, factor) => gd(gd(gd(src1, fast_ma_len, factor), fast_ma_len, factor), fast_ma_len, factor) 
tilT3 = t3(src1, fast_ma_len, factor)
//Fast MA mapped to fast_ma_source
fast_ma = request.security(syminfo.tickerid, res1, fast_ma_source == "SMA" ? ta.sma(src1, fast_ma_len) : 
  fast_ma_source == "EMA" ? ta.ema(src1, fast_ma_len) : 
  fast_ma_source == "WMA" ? ta.wma(src1, fast_ma_len) : 
  fast_ma_source == "Hull MA" ? hullma : 
  fast_ma_source == "VWMA" ? ta.vwma(src1, fast_ma_len) : 
  fast_ma_source == "RMA" ? ta.rma(src1, fast_ma_len) : 
  fast_ma_source == "TEMA" ? tema : tilT3)
//Slow MA Calcs
//Hull MA Definition for 2nd MA
hullma_Slow = ta.wma(2*ta.wma(src2, slow_ma_len/2)-ta.wma(src2, slow_ma_len), math.round(math.sqrt(slow_ma_len)))
//TEMA definition for 2nd MA
ema1_Slow = ta.ema(src2, slow_ma_len)
ema2_Slow = ta.ema(ema1_Slow, slow_ma_len)
ema3_Slow = ta.ema(ema2_Slow, slow_ma_len)
tema_Slow = 3 * (ema1_Slow - ema2_Slow) + ema3_Slow
//Tilson T3 for 2nd MA
factor_Slow = slow_factorT3 * 1 //.10
gd_Slow(src2, slow_ma_len, factor_Slow) => ta.ema(src2, slow_ma_len) * (1 + factor_Slow) - ta.ema(ta.ema(src2, slow_ma_len), slow_ma_len) * factor_Slow 
t3_Slow(src2, slow_ma_len, factor_Slow) => gd_Slow(gd_Slow(gd_Slow(src2, slow_ma_len, factor_Slow), slow_ma_len, factor_Slow), slow_ma_len, factor_Slow) 
tilT3_Slow = t3_Slow(src2, slow_ma_len, factor_Slow)
//Slow MA mapped to slow_ma_source for 2nd MA
slow_ma = request.security(syminfo.tickerid, res2, slow_ma_source == "SMA" ? ta.sma(src2, slow_ma_len) : 
  slow_ma_source == "EMA" ? ta.ema(src2, slow_ma_len) : 
  slow_ma_source == "WMA" ? ta.wma(src2, slow_ma_len) : 
  slow_ma_source == "Hull MA" ? hullma_Slow : 
  slow_ma_source == "VWMA" ? ta.vwma(src2, slow_ma_len) : 
  slow_ma_source == "RMA" ? ta.rma(src2, slow_ma_len) : 
  slow_ma_source == "TEMA" ? tema_Slow : tilT3_Slow)

//Color Change for Fast MA based on Slope
fast_ma_up     = fast_ma >= fast_ma[fast_ma_smooth]
fast_ma_dn     = fast_ma  < fast_ma[fast_ma_smooth]
col_fast_ma_cc = show_fast_ma_cc and fast_ma_up ? bullish_col : show_fast_ma_cc and fast_ma_dn ? bearish_col : color.new(fast_ma_col, 0)
//Color Change for Fast MA Above/Below Slow MA
fast_Above_slow = fast_ma >= slow_ma
fast_Below_slow = fast_ma <  slow_ma
col_fast_Above_Below = show_fast_ma_tr and fast_Above_slow ? bullish_col : show_fast_ma_tr and fast_Below_slow ? bearish_col : color.new(fast_ma_col, 0)
//Color Change Condition Final
col_Final = show_fast_ma_tr ? col_fast_Above_Below : col_fast_ma_cc

//Begin Plot Statements
plot(fast_ma, title="Fast MA",  color=color.new(col_Final, 0), style=plot.style_line, linewidth=fast_ma_wid, offset=fast_ma_off)
plot(show_slow_ma and slow_ma ? slow_ma : na, title="Slow MA",  color=color.new(slow_ma_col, 0), style=plot.style_line, linewidth=slow_ma_wid, offset=slow_ma_off)
//Plot Statements if Fill is ON
p1 = plot(show_fill and fast_ma ? fast_ma : na, title="Fast MA",  color=color.new(col_Final, 0), style=plot.style_line, linewidth=fast_ma_wid, offset=fast_ma_off, editable=false)
p2 = plot(show_fill and show_slow_ma and slow_ma ? slow_ma : na, title="Slow MA",  color=color.new(slow_ma_col, 0), style=plot.style_line, linewidth=slow_ma_wid, offset=slow_ma_off, editable=false)
fill(p1, p2, title="1", color=color.new(col_Final,fill_transp))

//Alert Conditions
//Alert Conditions Based on Sloe of Fast MA
alert_Fast_MA_Slope_UP = fast_ma[1] < fast_ma[1 + fast_ma_smooth] and fast_ma[0] >= fast_ma[0 + fast_ma_smooth]
alert_Fast_MA_Slope_DN = fast_ma[1] > fast_ma[1 + fast_ma_smooth] and fast_ma[0] <  fast_ma[0 + fast_ma_smooth]
//Alert Conditions when Fast MA Crosses Above/Below Slow MA
alert_Cross_UP = fast_ma[1] < slow_ma[1] and fast_ma >= slow_ma
alert_Cross_DN = fast_ma[1] > slow_ma[1] and fast_ma <  slow_ma

//Alerts
//Alerts Based on Slope of Fast MA
if alert_Slope_Bull and alert_Fast_MA_Slope_UP
    alert("Symbol = (" + syminfo.tickerid + ") Fast MA TimeFrame = (" + res1 + ") Current Price (" + str.tostring(close) + ") Fast MA Slope Up.", alert.freq_once_per_bar_close)
if alert_Slope_Bear and alert_Fast_MA_Slope_DN
    alert("Symbol = (" + syminfo.tickerid + ") Fast MA TimeFrame = (" + res1 + ") Current Price (" + str.tostring(close) + ") Fast MA Slope Down.", alert.freq_once_per_bar_close)
//Alerts Based on Fast MA Crossing Above/Below Slow MA
if alert_Cross_Bull and alert_Cross_UP
    alert("Symbol = (" + syminfo.tickerid + ") Fast MA TimeFrame = (" + res1 + ") Slow MA TimeFrame = (" + res2 + ") Current Price (" + str.tostring(close) + ") Fast MA Crosses Above Slow MA.", alert.freq_once_per_bar_close)
if alert_Cross_Bear and alert_Cross_DN
    alert("Symbol = (" + syminfo.tickerid + ") Fast MA TimeFrame = (" + res1 + ") Slow MA TimeFrame = (" + res2 + ") Current Price (" + str.tostring(close) + ") Fast MA Crosses Below Slow MA.", alert.freq_once_per_bar_close)

//End Code

Overview

Users can choose from eight moving average types, including SMA, EMA, WMA, Hull MA, VWMA, RMA, TEMA, and Tillson T3. The script provides custom color-coding based on the fast moving average slope or its position relative to the slow moving average, alongside visual background fill options between both lines. Built-in alerts trigger on slope direction changes or crossover events between the fast and slow moving averages.

Details

Published by

theonetrade on GitHub

Code credit

ChrisMoody, as written in the script's header

Draws

On the price 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
Fast MA TimeFrametimeframeres1
Fast MA Lengthint20fast_ma_len
Fast MA Sourcesourceclosesrc1
Fast MA Offsetint0fast_ma_off
Fast MA TypestringSMAfast_ma_source
Fast MA Tilson T3 Factorfloat.7fast_factorT3
Show Slow MA?boolfalseshow_slow_ma
Slow MA TimeFrametimeframeres2
Slow MA Lengthint50slow_ma_len
Slow MA Sourcesourceclosesrc2
Slow MA Offsetint0slow_ma_off
Slow MA TypestringSMAslow_ma_source
Show all 28 settings
SettingTypeDefaultVariable
Slow MA Tilson T3 Factorfloat.7slow_factorT3
Fast MA  color#2962FFfast_ma_col
Slow MA  color#FF6D00slow_ma_col
Fast MA Widthint3fast_ma_wid
Slow MA Widthint3slow_ma_wid
Change Fast MA Color Based On Slope?boolfalseshow_fast_ma_cc
Color Smoothingint2fast_ma_smooth
Bull Col  colorcolor.new(color.green, 0)bullish_col
Bear Col  colorcolor.new(color.red, 0)bearish_col
Change Fast MA Color Above/Below Slow MA?boolfalseshow_fast_ma_tr
Show Fill?booltrueshow_fill
Transparencyint50fill_transp
Fast MA Slope Bullboolfalsealert_Slope_Bull
Fast MA Slope Bearboolfalsealert_Slope_Bear
Fast MA Cross Bullboolfalsealert_Cross_Bull
Fast MA Cross Bearboolfalsealert_Cross_Bear
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 Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 5 weeks ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
368 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
321 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 8 days ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 4 weeks ago · MIT GitHub repository of NVDA Trend Ribbon
257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 2 months ago · None stated GitHub repository of Donald SPX - Options Trading
228 stars

This indicator computes moving average and RSI bias signals across the current timeframe and four higher timeframes. It sums biases from the MA and RSI to derive an overall bullish or bearish signal. The results appear in a configurable table that displays eac

Indicator v6 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of Multi-Timeframe Analysis Template

More Trend 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