Indicator · Pine Script v6 · Own pane

Chande Momentum Oscillator

by SiegerTerpstra· code credited to sajjetti

This indicator calculates the Chande Momentum Oscillator by comparing the sum of price gains to the sum of price losses over a defined lookback period.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code148
Settings7inputs
LicenceNone statedfile: MPL-2.0
Last update9 months ago14 Jan 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

148 lines of Pine Script v6 from 4 - CMO (v6).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

4 - CMO (v6).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sajjetti

//@version=6

//-------------------------------------

// Release:                     2025-12-29
// Update:                      2026-01-04
// Author:                      sajjetti
// Email:                       contact@sajjetti.ai
// Website:                     sajjetti.ai
// Profile:                     https://www.tradingview.com/u/stmd/
// Pineversion:                 6
// Filename:                    4 - CMO (v6).pine

//-------------------------------------
// PURPOSE
// Chande Momentum Oscillator (CMO) - measures momentum by comparing
// the sum of gains to the sum of losses over a specified period.
// Developed by Tushar Chande to capture both up and down momentum.

//-------------------------------------
// FEATURES
// - Multi-timeframe support via Indicator Timeframe input
// - Measures momentum on both up and down days
// - Oscillates between -100 and +100
// - Optional smoothing via MA
// - Offset parameter for historical analysis
// - Dynamic color based on rising/falling values

//-------------------------------------
// NOTES
// - Values above +50 = overbought condition
// - Values below -50 = oversold condition
// - Zero line crossovers indicate momentum shifts
// - CMO = 100 * (sumUp - sumDown) / (sumUp + sumDown)
// - Similar to RSI but unbounded on both sides
// - Division-by-zero protected when no price movement

//-------------------------------------
// INDICATOR PARAMETERS

vVersion                        = "V2.1"
vPineVersion                    = "ps6"
vTitle                          = "Chande Momentum Oscillator"
vShort                          = "CMO"
vOverlay                        = false
vPrecision                      = 2

indicator( title = vTitle+" ["+vVersion+"|"+vPineVersion+"]", shorttitle = vShort+" ["+vVersion+"|"+vPineVersion+"]", overlay = vOverlay, precision = vPrecision )

//-------------------------------------
// INPUTS

var groupCmo                    = "CMO (Standard: close, 5, 1)"

vTimeframe                      = input.timeframe( defval = "", title = "Indicator Timeframe" )
vSource                         = input.source( defval = close, title = "Source", group = groupCmo )
vLength                         = input.int( defval = 5, minval = 1, maxval = 1024, title = "Length", group = groupCmo )
vSmooth                         = input.int( defval = 1, minval = 1, maxval = 1024, title = "Smooth", group = groupCmo )
vOffSet                         = input.int( defval = 0, minval = 0, maxval = 1024, title = "Offset", group = groupCmo )
vUpperBandValue                 = input.int( defval = 20, minval = 1, maxval = 100, title = "Upper Band", group = groupCmo )
vLowerBandValue                 = input.int( defval = -20, minval = -100, maxval = -1, title = "Lower Band", group = groupCmo )

//-------------------------------------
// COLORS

cBullish                        = #26A69A
cBearish                        = #EF5350
cZeroLine                       = #787B86
cUpperBand                      = #787B86
cLowerBand                      = #787B86

//-------------------------------------
// FUNCTIONS

// @function    Simple Moving Average
// @param       n (int) Offset for lookback starting point
// @param       s (series float) Source data
// @param       le (int) Length of the averaging period
// @returns     (float) Average value over the specified period
fMa( n, s, le ) =>
    r = float( 0 )
    for i = n + 0 to ( n + ( le - 1 ) )
        r := ( r + s[ i ] )
    a = r / le
    a

// @function    Calculate upward momentum for current bar
// @param       s (series float) Source data
// @returns     (float) Positive momentum if price increased, else 0
fMomentumUp( s ) =>
    mom = s - s[ 1 ]
    r = mom >= 0.0 ? mom : 0.0
    r

// @function    Calculate downward momentum for current bar
// @param       s (series float) Source data
// @returns     (float) Absolute value of negative momentum if price decreased, else 0
fMomentumDown( s ) =>
    mom = s - s[ 1 ]
    r = mom >= 0.0 ? 0.0 : -mom
    r

// @function    Chande Momentum Oscillator calculation
// @param       n (int) Offset for lookback
// @param       s (series float) Source data
// @param       le (int) Length for summation period
// @returns     (float) CMO value between -100 and +100
fCmo( n, s, le ) =>
    up      = fMomentumUp( s )
    down    = fMomentumDown( s )
    sumUp   = math.sum( up, le )[ n ]
    sumDown = math.sum( down, le )[ n ]
    total   = sumUp + sumDown
    r       = total == 0.0 ? 0.0 : 100.0 * ( sumUp - sumDown ) / total
    r

// @function    Calculate CMO with smoothing for MTF support
// @returns     (float) Smoothed CMO value
fCalcCmo() =>
    cmoBase = fCmo( vOffSet, vSource, vLength )
    fMa( 0, cmoBase, vSmooth )

// @function    Determines plot color based on trend direction
// @param       n (int) Offset for comparison
// @param       s (series float) Source data to evaluate
// @returns     (color) Green if rising, red if falling
fColor( n, s ) =>
    r = ( s[ n + 1 ] < s[ n ] ) ? cBullish : cBearish
    r

//-------------------------------------
// CALCULATIONS

vCmo                            = vTimeframe == "" ? fCalcCmo() : request.security( syminfo.tickerid, vTimeframe, fCalcCmo() )

//-------------------------------------
// PLOT

vLineMedian                     = hline( 0, color = cZeroLine, linestyle = hline.style_dotted, linewidth = 1, title = "Zero Line" )
vUpperBand                      = hline( vUpperBandValue, color = cUpperBand, linestyle = hline.style_dotted, linewidth = 1, title = "Upper Band" )
vLowerBand                      = hline( vLowerBandValue, color = cLowerBand, linestyle = hline.style_dotted, linewidth = 1, title = "Lower Band" )

vPlotCmo                        = plot( vCmo, style = plot.style_line, color = fColor( 0, vCmo ), linewidth = 2, title = "CMO - ST" )

//-------------------------------------

Overview

Chande Momentum Oscillator plots the resulting oscillator line in a separate pane alongside configurable upper, lower, and zero reference levels. Users can customize the price source, calculation length, optional moving average smoothing, display offset, upper and lower band thresholds, and indicator timeframe. It serves as a visual momentum tool without providing automated trade entries or exits.

Details

Published by

SiegerTerpstra on GitHub

Code credit

sajjetti, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum

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

tradingviewindicatorindicators

Settings

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

SettingTypeDefaultVariable
Indicator TimeframetimeframevTimeframe
SourcesourceclosevSource
Lengthint5vLength
Smoothint1vSmooth
Offsetint0vOffSet
Upper Bandint20vUpperBandValue
Lower Bandint-20vLowerBandValue
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

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

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
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

KD指標

by TaichiS
219 stars

This script calculates and plots a Stochastic Oscillator (KD indicator) in a separate chart pane. It determines the fast stochastic value over a 9-period lookback, then applies a 3-period Simple Moving Average (SMA) to create the %K line, and a second 3-period

Indicator v4 Oscillators & momentum
Updated 5 years ago · None stated GitHub repository of KD指標

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