Pine Script Chande Momentum Oscillator (CMO)

Master this unique momentum oscillator in TradingView's Pine Script for identifying trend strength, overbought/oversold conditions, and divergence.

Last Updated on: Expertise: Intermediate

What is the Chande Momentum Oscillator (CMO)?

The Chande Momentum Oscillator (CMO), developed by Tushar Chande, is a technical momentum indicator that measures the difference between the sum of recent gains and the sum of recent losses, divided by the sum of all price changes over a specific period. Unlike other oscillators like RSI or Stochastic which limit their range, CMO ranges from -100 to +100. This broad range allows it to directly quantify pure momentum without being skewed by fixed scaling, providing a clearer picture of trend strength and potential turning points.

In Pine Script, CMO is a valuable tool for traders seeking to identify the underlying directional bias and conviction of price movements, as well as classic overbought/oversold and divergence signals.

Components and Calculation

The calculation of CMO involves tracking positive and negative price changes:

  1. Calculate Upward and Downward Momentum:
    • `SM_Up = Sum of (Current Close - Previous Close)` for positive changes over `length` periods. (If `Current Close < Previous Close`, the change is 0 for `SM_Up`).
    • `SM_Down = Sum of (Previous Close - Current Close)` for positive changes over `length` periods. (If `Current Close > Previous Close`, the change is 0 for `SM_Down`).
  2. CMO Formula:
    `CMO = ((SM_Up - SM_Down) / (SM_Up + SM_Down)) * 100`
    The result is multiplied by 100 to scale it between -100 and +100.

A CMO value near +100 indicates strong upward momentum, while a value near -100 indicates strong downward momentum. Values near 0 suggest low momentum or a flat trend.

Basic Chande Momentum Oscillator Implementation in Pine Script

Pine Script v5 provides a convenient built-in function `ta.cmo()` for straightforward implementation.

//@version=5
indicator("My Chande Momentum Oscillator", overlay=false) // overlay=false to plot in a separate pane

// Input for CMO length
length = input.int(9, title="CMO Length", minval=1)

// Calculate CMO value using the built-in function
cmoValue = ta.cmo(close, length)

// Plot the CMO line
plot(cmoValue, title="CMO", color=color.new(color.blue, 0), linewidth=2)

// Plot horizontal lines for overbought and oversold levels
h_overbought = hline(50, "Overbought (+50)", color=color.new(color.red, 0), linestyle=hline.style_dashed)
h_oversold = hline(-50, "Oversold (-50)", color=color.new(color.green, 0), linestyle=hline.style_dashed)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

// Fill background between CMO and levels for visual clarity
fill(h_overbought, h_oversold, color=color.new(color.gray, 90))

Standard Levels: Typical overbought levels are +50 and oversold levels are -50, though these can be adjusted.

Practical Chande Momentum Oscillator Trading Strategies

1. Overbought and Oversold Conditions

When CMO moves significantly above +50, the asset is considered overbought, indicating strong bullish momentum that might be nearing exhaustion. Conversely, a move significantly below -50 is oversold, suggesting strong bearish momentum that might be nearing exhaustion.

//@version=5
strategy("CMO Overbought/Oversold Strategy", overlay=true)

// Inputs for CMO
length = input.int(9, title="CMO Length", minval=1)
overboughtLevel = input.int(50, title="Overbought Level")
oversoldLevel = input.int(-50, title="Oversold Level")

// Calculate CMO
cmoValue = ta.cmo(close, length)

// Define conditions for entries and exits
// Buy when CMO moves below oversold and then crosses back above it
longCondition = ta.crossunder(cmoValue, oversoldLevel) // CMO goes oversold
longExitCondition = ta.crossover(cmoValue, oversoldLevel) // CMO exits oversold (potential buy)

// Sell when CMO moves above overbought and then crosses back below it
shortCondition = ta.crossover(cmoValue, overboughtLevel) // CMO goes overbought
shortExitCondition = ta.crossunder(cmoValue, overboughtLevel) // CMO exits overbought (potential sell)

// Strategy entries/exits (entry upon exiting extreme zones)
if (longExitCondition)
    strategy.entry("Long", strategy.long)

if (shortExitCondition)
    strategy.entry("Short", strategy.short)

// Optional: Plot CMO in a separate pane for visualization
// plot(cmoValue, "CMO", color.blue)
// hline(overboughtLevel, "Overbought", color.red)
// hline(oversoldLevel, "Oversold", color.green)
// hline(0, "Zero Line", color.gray)

2. CMO Zero Line Crossover (Trend Direction)

The zero line in CMO serves as a crucial indicator of momentum bias. A crossover suggests a shift in the short-term trend.

//@version=5
strategy("CMO Zero Line Crossover Strategy", overlay=true)

// Inputs for CMO
length = input.int(9, title="CMO Length", minval=1)
zeroLine = 0

// Calculate CMO
cmoValue = ta.cmo(close, length)

// Define conditions for entries
longSignal = ta.crossover(cmoValue, zeroLine)
shortSignal = ta.crossunder(cmoValue, zeroLine)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)

// Optional: Plot CMO in a separate pane
// plot(cmoValue, "CMO", color.blue)
// hline(zeroLine, "Zero Line", color.gray)

3. CMO Divergence Strategy

Divergence between price and CMO can signal potential trend reversals. This occurs when price makes a new high/low, but CMO fails to confirm it, indicating weakening momentum.

//@version=5
indicator("CMO Divergence Scanner", overlay=true)

// Inputs for CMO
length = input.int(9, title="CMO Length", minval=1)
overboughtLevel = input.int(50, title="Overbought Level")
oversoldLevel = input.int(-50, title="Oversold Level")
centerLine = input.int(0, title="Zero Line")

// Calculate CMO
cmoValue = ta.cmo(close, length)

// Plot CMO in a separate pane
plot(cmoValue, "CMO", color.blue)
hline(overboughtLevel, "Overbought (+50)", color.red)
hline(oversoldLevel, "Oversold (-50)", color.green)
hline(centerLine, "Zero Line", color.gray)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This is a simplified example focusing on price vs CMO divergence.

// Bullish Divergence (Price lower low, CMO higher low)
bullishDivergence = close[2] > close[1] and close[1] > close and cmoValue[2] < cmoValue[1] and cmoValue[1] < cmoValue

// Bearish Divergence (Price higher high, CMO lower high)
bearishDivergence = close[2] < close[1] and close[1] < close and cmoValue[2] > cmoValue[1] and cmoValue[1] > cmoValue

plotshape(bullishDivergence, title="Bullish Divergence", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(bearishDivergence, title="Bearish Divergence", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)

alertcondition(bullishDivergence, "Bullish CMO Divergence", "Potential bullish reversal based on CMO divergence.")
alertcondition(bearishDivergence, "Bearish CMO Divergence", "Potential bearish reversal based on CMO divergence.")

Optimizing CMO Performance

To get the most from the Chande Momentum Oscillator in Pine Script:

Relative to Price Changes: CMO measures the relative strength of positive vs. negative price changes. A strong CMO (near +100 or -100) indicates high conviction in the current direction.

Common CMO Pitfalls

Conclusion

The Chande Momentum Oscillator (CMO) is a unique and highly effective momentum indicator in Pine Script for TradingView. Its distinct calculation provides a clear measure of directional conviction and trend strength, making it valuable for identifying overbought/oversold conditions, shifts across the zero line, and potential reversals through divergence. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically within your comprehensive trading approach, you can leverage the CMO to gain deeper insights into market dynamics and enhance your trading decisions.