What is Chaikin Money Flow?
Chaikin Money Flow (CMF) is a volume-based oscillator developed by Marc Chaikin, building upon his Accumulation/Distribution Line. CMF measures the amount of money flow over a specific lookback period (typically 20 or 21 periods). It essentially quantifies the degree of buying or selling pressure, relative to the volume, across a defined period. CMF ranges between +1.0 and -1.0.
The core concept behind CMF is that if a security closes in the upper half of its daily range, it's considered to be under accumulation (buying pressure). If it closes in the lower half, it's considered under distribution (selling pressure). CMF then integrates this with volume over a moving average period.
CMF is primarily used to:
- Confirm price trends: Positive CMF confirms an uptrend, negative CMF confirms a downtrend.
- Identify divergences: When price and CMF move in opposite directions, it can signal an impending trend reversal.
- Spot accumulation/distribution: Provides insight into the underlying buying and selling interest in an asset.
In Pine Script, CMF is a versatile tool for gauging market conviction by observing volume-weighted money flow.
Components and Calculation
The calculation of Chaikin Money Flow involves these steps:
- Money Flow Multiplier (MFM): For each period, this value determines the extent of buying or selling pressure. It ranges from -1 to +1.
`MFM = ((Close - Low) - (High - Close)) / (High - Low)`
* If `High - Low` is zero (a flat bar), MFM is typically 0. - Money Flow Volume (MFV): Multiply the MFM by the period's volume.
`MFV = MFM * Volume` - Chaikin Money Flow (CMF): Sum the MFV over the `length` periods and divide it by the sum of volume over the same `length` periods.
`CMF = Sum(MFV, length) / Sum(Volume, length)`
A common `length` for CMF is 20 or 21 periods.
Basic Chaikin Money Flow (CMF) Implementation in Pine Script
Pine Script v5 provides a convenient built-in function `ta.cmf()` for calculating Chaikin Money Flow.
//@version=5
indicator("My Chaikin Money Flow (CMF)", overlay=false, format=format.percent) // overlay=false to plot in a separate pane
// Input for CMF length
length = input.int(20, title="CMF Length", minval=1)
// Calculate CMF using the built-in function
// ta.cmf() implicitly uses 'high', 'low', 'close', and 'volume' for its calculation
cmfValue = ta.cmf(length)
// Plot the CMF line
plot(cmfValue, title="CMF", color=color.new(color.blue, 0), linewidth=2)
// Plot the Zero Line as a key reference point
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)
// Optional: Add reference levels for visual clarity, e.g., +0.20 and -0.20
// CMF values above +0.20 often indicate strong buying pressure.
// CMF values below -0.20 often indicate strong selling pressure.
hline(0.20, "Upper Ref (+0.20)", color=color.new(color.green, 0), linestyle=hline.style_dashed)
hline(-0.20, "Lower Ref (-0.20)", color=color.new(color.red, 0), linestyle=hline.style_dashed)
Practical CMF Trading Strategies
1. Zero-Line Crossovers (Trend Confirmation)
Crossovers of the zero line can provide signals about the underlying trend direction and strength based on money flow. These signals are best used to confirm price trends rather than as standalone entry signals.
- Bullish Confirmation: CMF crosses above the zero line. This indicates a shift to net buying pressure, supporting an uptrend or suggesting a potential bullish reversal.
- Bearish Confirmation: CMF crosses below the zero line. This indicates a shift to net selling pressure, supporting a downtrend or suggesting a potential bearish reversal.
//@version=5
strategy("CMF Zero Line Crossover Strategy", overlay=true)
length = input.int(20, title="CMF Length", minval=1)
cmfValue = ta.cmf(length)
plot(cmfValue, "CMF", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)
// Long entry: CMF crosses above zero
longCondition = ta.crossover(cmfValue, 0)
// Short entry: CMF crosses below zero
shortCondition = ta.crossunder(cmfValue, 0)
if (longCondition)
strategy.entry("Long CMF", strategy.long)
if (shortCondition)
strategy.entry("Short CMF", strategy.short)
// Basic exit: opposite signal
strategy.close("Long CMF", when=shortCondition)
strategy.close("Short CMF", when=longCondition)
2. CMF Divergence (Key Reversal Signal)
Divergence between price and CMF is often considered the most powerful signal from the indicator, suggesting a weakening trend and potential reversal, as money flow is not confirming price action.
- Bullish Divergence: Price makes a lower low, but CMF makes a higher low (or fails to make a significantly lower low). This indicates that despite falling prices, buying pressure (accumulation) is increasing, hinting at a potential upward reversal.
- Bearish Divergence: Price makes a higher high, but CMF makes a lower high (or fails to make a significantly higher high). This indicates that despite rising prices, selling pressure (distribution) is increasing, hinting at a potential downward reversal.
//@version=5
strategy("CMF Divergence Strategy", overlay=true)
length = input.int(20, title="CMF Length", minval=1)
cmfValue = ta.cmf(length)
plot(cmfValue, "CMF", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)
// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This example looks for recent higher/lower swings in price and CMF.
// Bullish Divergence: Price lower low, CMF higher low
bullishDiv = close < close[1] and close[1] < close[2] and cmfValue > cmfValue[1] and cmfValue[1] > cmfValue[2]
// Bearish Divergence: Price higher high, CMF lower high
bearishDiv = close > close[1] and close[1] > close[2] and cmfValue < cmfValue[1] and cmfValue[1] < cmfValue[2]
// Plot shapes on the chart to indicate divergence
plotshape(bullishDiv, title="Bullish CMF Divergence", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish CMF Divergence", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)
if (bullishDiv)
strategy.entry("Long Divergence", strategy.long)
if (bearishDiv)
strategy.entry("Short Divergence", strategy.short)
// Basic exit after a few bars or on opposite signal
strategy.exit("Long Divergence Exit", from_entry="Long Divergence", profit=close*0.02, loss=close*0.01)
strategy.exit("Short Divergence Exit", from_entry="Short Divergence", profit=close*0.02, loss=close*0.01)
3. CMF Extreme Readings (Overbought/Oversold Volatility)
While CMF does not have traditional overbought/oversold levels like RSI, sustained readings near its extremes (+0.50 or -0.50, though these are arbitrary and depend on the asset) can indicate very strong buying or selling pressure that might be unsustainable in the long run.
- Strong Accumulation: CMF consistently above +0.20 or +0.30. This confirms strong buying interest.
- Strong Distribution: CMF consistently below -0.20 or -0.30. This confirms strong selling interest.
- Reversal from Extremes: A pullback from extreme positive (negative) CMF readings towards the zero line can indicate a temporary pause or a weakening of the strong buying (selling) pressure.
//@version=5
indicator("CMF Extreme Readings", overlay=true)
length = input.int(20, title="CMF Length", minval=1)
cmfValue = ta.cmf(length)
plot(cmfValue, "CMF", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)
hline(0.30, "Strong Accumulation", color.new(color.green, 0), linestyle=hline.style_dashed, display=display.pane_only)
hline(-0.30, "Strong Distribution", color.new(color.red, 0), linestyle=hline.style_dashed, display=display.pane_only)
// Highlight background based on CMF strength
bgcolor(cmfValue > 0.30 ? color.new(color.lime, 90) : na, title="Accumulation Zone")
bgcolor(cmfValue < -0.30 ? color.new(color.maroon, 90) : na, title="Distribution Zone")
// Alert conditions for extreme readings
alertcondition(cmfValue > 0.30 and cmfValue[1] <= 0.30, "CMF Strong Accumulation", "CMF moved into strong accumulation zone.")
alertcondition(cmfValue < -0.30 and cmfValue[1] >= -0.30, "CMF Strong Distribution", "CMF moved into strong distribution zone.")
Optimizing Chaikin Money Flow Performance
To get the most from Chaikin Money Flow in Pine Script:
- Focus on Divergence: CMF's most reliable and actionable signals often come from divergences with price. Prioritize confirming these signals with other tools.
- Parameter Tuning: The `length` parameter (commonly 20 or 21) impacts the responsiveness of CMF. Shorter lengths will make it more volatile and reactive to short-term money flow. Longer lengths will smooth the indicator, providing a broader view of accumulation/distribution.
- Combine with Price Action: Always confirm CMF signals with price action. A strong CMF reading is more significant if accompanied by a strong breakout or a clear reversal candlestick pattern.
- Trend Context: Use CMF in the context of the larger trend. In an uptrend, look for positive CMF and bullish divergences for long entries. In a downtrend, look for negative CMF and bearish divergences for short entries.
- Volume Data Quality: CMF relies heavily on accurate volume data. Ensure the asset you are analyzing has reliable volume information.
- Chaikin Oscillator: Consider using the Chaikin Oscillator, which is an EMA of CMF minus another slower EMA of CMF. It smooths CMF and provides earlier crossover signals.
Common CMF Pitfalls
- Lag: As a cumulative indicator based on a moving average, CMF can lag price, meaning signals may appear after a significant portion of a move has already occurred.
- False Signals: In very choppy or low-volume markets, CMF can fluctuate around the zero line, generating ambiguous or false signals.
- No Fixed Overbought/Oversold Levels: Unlike some oscillators, CMF does not have universal overbought/oversold levels. Its interpretation requires historical context for the specific asset.
- Volume Dependency: The accuracy of CMF is highly dependent on reliable and consistent volume data. Issues with volume data can render CMF signals unreliable.
- Not a Standalone Indicator: CMF is a powerful analytical tool but should never be used in isolation. It works best as a confirming indicator within a broader trading strategy.
Conclusion
Chaikin Money Flow (CMF) is a sophisticated and highly insightful volume-based technical indicator available in Pine Script for TradingView. By quantifying the balance of buying (accumulation) and selling (distribution) pressure over time, it provides traders with a deeper understanding of market conviction and potential future price movements. While its greatest strength lies in identifying powerful divergences with price, it also excels at confirming existing trends and validating shifts in market sentiment. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with price action and other technical analysis tools, you can leverage CMF to enhance your trading decisions and gain a clearer understanding of the underlying money flow in any market.