TradingView indicator guides

Chaikin Money Flow on TradingView

The Chaikin Money Flow index (CMF) measures where bars close within their high-low ranges, weighted by volume over a rolling window. A positive value favors upper-range closes; a negative value favors lower-range closes. It is a price-and-volume proxy for pressure, not a record of cash entering or leaving an asset.

Start with the calculation and the feed behind it. A gap down can still produce positive money flow, and an unfinished bar can move across zero before closing.

Inspect the Pine Script example

CMF formula: position first, volume second

Multiplier = (2 × Close - High - Low) / (High - Low)
Money Flow Volume = Multiplier × Volume
CMF(N) = Sum(Money Flow Volume, N) / Sum(Volume, N)

The multiplier is +1 at the high, 0 at the midpoint and -1 at the low. With valid nonnegative volume and a positive total, CMF is a weighted average bounded by -1 and +1. The official CMF calculation uses a rolling lookback, rather than a cumulative total from the start of the chart.

Hypothetical two-bar example, with volume in shares
BarHigh / Low / CloseVolumeMultiplierFlow
A110 / 100 / 1081,000+0.60+600
B108 / 98 / 1003,000-0.60-1,800

CMF(2) = (600 - 1,800) / (1,000 + 3,000) = -0.30. There is one upper-range close and one lower-range close, but the second bar carries three times the weight. Counting positive bars would miss that difference. These are illustrative numbers, not historical market data or trade results.

A zero-range bar makes the raw multiplier undefined. The example below assigns that bar zero money flow and retains its reported volume in the denominator. Missing volume invalidates the whole window; an all-zero volume window has no CMF value.

CMF vs MFI vs ADL

IndicatorWhat sets the direction?AggregationReading
CMFClose within the current rangeRolling MFV divided by rolling volume-1 to +1; zero reference
MFITypical price rising or falling versus the prior barPositive/negative typical-price × volume ratio0 to 100; often compared with 80/20
ADLSame range multiplier as CMFRunning sum of MFVUnbounded; direction and changes matter

MFI uses typical price, (high + low + close) / 3. An upper-range close can still have a lower typical price than the previous bar, so positive CMF contribution and negative MFI flow can coexist. MFI's 80/20 thresholds do not transfer to CMF.

ADL retains earlier contributions; CMF drops them when they leave its window. In the two-bar example above, ADL changes by -1,200 shares of weighted flow, while CMF reports the normalized -0.30. Changing the start of the dataset changes ADL's starting level. It does not change a later CMF window with identical bars.

For the oscillator's own calculation and examples, see the MFI guide. OBV offers another comparison: its direction follows close-to-close changes rather than CMF's close-within-range multiplier.

Why gaps and intraday volume change the reading

A gap down can add positive money flow

Suppose yesterday closed at 100. Today opens at 90, trades from 88 to 94, then closes at 93 with 12,000 shares of volume. Its multiplier is (186 - 94 - 88) / 6 = +0.667, and its money flow volume is +8,000. Price fell 7% from the previous close, yet this bar contributes positively to CMF. The final CMF still depends on the other bars in its window.

This hypothetical example follows the formula: the previous close is absent. ADL shares the same gap limitation. A positive CMF contribution cannot by itself establish that the overnight decline has reversed.

Bar volume is different from a session total

On a five-minute chart, volume belongs to each five-minute bar. During the open bar it accumulates from that bar's opening update; it is not the entire day's volume. A 20-bar CMF rolls across 20 available bars and does not automatically reset at the session open. See TradingView's chart data documentation.

Consider two illustrative intraday bars with multipliers +1 and -1 and volumes 100 and 300. Their two-bar CMF is -0.50. Substituting session-cumulative volumes of 100 and 400 produces -0.60: the first bar's volume is counted again. Do not feed a running daily volume total into the standard CMF formula.

Calculating CMF from daily OHLCV is also different from summing intraday MFV: a daily bar has one high-low range and one closing position. Keep symbol, provider, timeframe and session settings fixed when comparing results. Extended-hours bars can change both the window and its weights.

Check what the feed reports. TradingView documents symbols with missing volume or tick volume. A tick count describes price-update activity. It is not interchangeable with a traded-share total, and one exchange's crypto volume is not a consolidated total across all venues.

Pine Script v6: CMF with confirmed zero crosses

This educational indicator uses a 20-bar CMF and an optional 50-bar simple moving average of price. A long candidate requires a cross above zero and a close above the SMA; a short candidate requires the reverse. Both require a closed bar. The periods are example inputs, with no performance claim.

Pine Script v6
//@version=6
indicator("CMF with confirmed zero crosses", overlay = false)

length = input.int(20, "CMF length", minval = 1)
trendLength = input.int(50, "Price SMA length", minval = 1)
usePriceFilter = input.bool(true, "Require price above/below SMA")

// Zero-range bars contribute zero money flow, but retain their volume weight.
multiplier = high == low ? 0.0 : (2.0 * close - high - low) / (high - low)
invalidVolume = na(volume) or volume < 0
barVolume = invalidVolume ? 0.0 : volume
volumeSum = math.sum(barVolume, length)
flowSum = math.sum(multiplier * barVolume, length)
invalidCount = math.sum(invalidVolume ? 1.0 : 0.0, length)
validWindow = bar_index >= length - 1 and invalidCount == 0 and volumeSum > 0
cmf = validWindow ? flowSum / volumeSum : na
priceSma = ta.sma(close, trendLength)

crossUp = ta.crossover(cmf, 0.0)
crossDown = ta.crossunder(cmf, 0.0)
longCandidate = barstate.isconfirmed and crossUp and (not usePriceFilter or close > priceSma)
shortCandidate = barstate.isconfirmed and crossDown and (not usePriceFilter or close < priceSma)

plot(cmf, "CMF", color = color.blue, linewidth = 2, style = plot.style_linebr)
hline(0, "Zero", color = color.gray)
plotshape(longCandidate, "Long candidate", shape.triangleup, location.bottom, color.green, text = "L")
plotshape(shortCandidate, "Short candidate", shape.triangledown, location.top, color.red, text = "S")
alertcondition(longCandidate, "CMF long candidate", "CMF crossed above zero with the selected price filter at bar close.")
alertcondition(shortCandidate, "CMF short candidate", "CMF crossed below zero with the selected price filter at bar close.")

var table status = table.new(position.top_right, 1, 1)
if barstate.islast
    table.cell(status, 0, 0, validWindow ? "CMF uses this chart feed's volume" : "CMF unavailable: check history and volume", text_color = color.white, bgcolor = color.new(color.black, 20))
  1. Open Pine Editor in TradingView, paste the example into a new indicator and add it to a standard candle chart.
  2. Inspect the Volume pane and compare CMF against the built-in indicator at the same length. The explicit missing-volume policy can produce different availability.
  3. Wait for enough history: CMF needs its full window; the optional price filter also needs its SMA history. Turning the filter off removes that SMA requirement.
  4. Create an alert using the long or short candidate condition and select Once Per Bar Close. Recreate alerts after changing the script or inputs.

The line updates during an open candle. Signal markers wait for barstate.isconfirmed. If the SMA filter fails on the crossing bar, a later move above the SMA does not trigger a delayed candidate; another CMF crossing is required. No orders, exits, stops or position sizing are included.

Repeated crosses around zero can whipsaw. A threshold buffer or persistence rule changes the experiment and delays some signals; it needs its own evaluation. Before converting candidates into a strategy, define exits, costs and sizing, then test on data not used to choose the inputs. A divergence alone has no guaranteed reversal date, and automated pivot comparisons require an explicit confirmation delay.

Build a CMF rule in Pineify

Use the AI Coding Agent to draft or revise an explicit rule, then inspect the generated Pine Script in TradingView. Include your volume policy and confirmation timing in the request.

Create a Pine Script v6 CMF indicator with length 20. Mark a cross above zero only at bar close when price is above its 50-bar SMA. Add the symmetric bearish condition. Hide CMF when the lookback contains missing volume or its volume sum is zero. Include alert conditions and explain when no signal can appear.
Build a CMF rule with the AI Coding Agent

The Visual Editor also includes CMF with a configurable length and a CMF output for conditions. Check the exported volume handling: its current CMF implementation substitutes 1 when volume is missing. That differs from this example's stricter policy, so use a feed with reported volume and review the output before relying on it.

Educational information, not investment advice. Syntax checks and chart signals do not establish profitability or suitability for a live trade.

Chaikin Money Flow FAQ

No. CMF weights the close within each bar range by volume and normalizes a rolling window around zero. MFI separates typical-price rises and falls, then expresses their money-flow ratio on a 0 to 100 scale. Their readings can disagree without either calculation being wrong.

It means the volume-weighted closing positions were positive over the selected window. It does not measure fund inflows, identify institutions or classify individual trades by buyer and seller aggression. A high-volume bar can outweigh several lower-volume bars.

Twenty or twenty-one bars are common starting points. This example uses twenty. Length counts chart bars: twenty five-minute bars cover 100 trading minutes, while twenty daily bars cover twenty trading sessions. Choose and test settings for the exact feed and session; no length is established here as best.

CMF compares the close with the current high and low, not with the previous close. A bar that gaps down and then finishes near its own high contributes positive money flow even though its close is below yesterday. Inspect the gap and the rolling window before interpreting the sign.

The current value changes when price, range or volume changes during the bar. The example waits until bar close before showing candidate signals, while its CMF line remains live. Closing confirmation adds waiting time; it does not prevent later feed corrections or make a signal profitable.

It requires a full lookback window, no missing or negative volume inside that window, and a positive volume sum. Individual zero-volume bars are allowed but add no weight. Check the Volume pane, exact exchange or provider and available history. A usable numerical reading still does not establish that a feed reports traded volume rather than tick activity.