TradingView indicator calculations

Intraday Momentum Index: candle bodies and oscillator levels

The Intraday Momentum Index (IMI) measures bullish candle-body movement as a percentage of total candle-body movement over a rolling window. It uses close minus open within each bar, not the change from the previous close. An IMI of 70 means bullish bodies contributed 70% of the combined body magnitude; it does not mean 70% of bars rose or that a reversal is due.

See the decision guide

Separate each body into an up part and a down part

For each bar, set U = max(close − open, 0) and D = max(open − close, 0). Sum U and D over the latest N bars, including the current bar. Divide the up sum by the total and multiply by 100. This is a ratio of sums, not an average of separate per-bar percentages. TA-Lib implements this rolling body calculation; the thinkorswim reference confirms the open-to-close input distinction.

  • With a positive denominator, equal up and down totals give 50, only up bodies give 100, and only down bodies give 0.
  • An individual doji adds zero to both totals but still occupies one position in the N-bar window. Its arrival can change IMI by removing an older nonzero body.
Body conditionU contributionD contribution
Close above openClose − open0
Close below open0Open − close
Close equals open00

Reproduce a five-bar value of 66.67

These hypothetical prices isolate the calculation. Set N to 5 for this example. The two bullish bodies total 6 price units and the two bearish bodies total 3, so IMI = 100 × 6 / 9 = 66.67. Only two of the five bars are bullish; counting green candles would produce a different statistic.

  • Now add bar 6 with open 103 and close 103. Bar 1 leaves the five-bar window. The remaining up sum is 3 and down sum is 3, giving IMI 50 despite no body movement on bar 6.
  • Multiplying all body sizes by the same positive factor leaves the ratio unchanged. IMI describes directional balance, not the absolute amount of volatility.
BarOpenCloseUD
110010330
210310102
310110100
410110430
510410301
Window totals63

Keep IMI separate from RSI, Momentum, Qstick, and III

The name intraday momentum indicator can refer to several different studies. Identify the input and aggregation before comparing plots. TradingView documents RSI with changes in closing prices and Wilder smoothing. IMI here uses unsmoothed rolling sums of open-to-close bodies, so replacing close changes with bodies inside an RSI call does not automatically reproduce this version.

  • Gap example: previous close 100, next open 110, next close 108. IMI receives a bearish body of 2; the close-to-close input to RSI is a gain of 8. Both observations can be correct.
  • On a daily chart, the body covers the daily open to close. On a five-minute chart, it covers five minutes. Neither reading is a direct measurement of overnight return.
StudyMeasured quantityDistinction from IMI
RSISmoothed gains and losses between closesIncludes close-to-close gap movement; smoothing differs.
MomentumCurrent close minus a prior closeA price-unit difference without a fixed 0 to 100 scale.
QstickMoving average of signed close − open bodiesRetains price units rather than normalizing by total body magnitude.
Intraday Intensity (III)A volume-based indicatorUses volume information that IMI does not use.

Define levels and the zero-denominator policy

The thinkorswim IMI study displays 70 and 30 as default overbought and oversold levels. Treat these as reference thresholds. A value can stay above 70 while bullish bodies continue to dominate; the label alone supplies neither a short entry nor an exit rule.

  • Zero handling is an implementation choice. The TA-Lib source reviewed on October 17, 2026 returns 50 for an all-flat window. This page returns na so absent movement is distinguishable from balanced nonzero movement.
  • Do not replace missing warm-up values with 0: that would falsely display the lower extreme. Require a complete window before evaluating conditions.
Window or eventReadingInterpretation
U = 7, D = 37070% of total body magnitude is bullish.
U = 3, D = 73030% of total body magnitude is bullish.
U = 2, D = 250Nonzero movement is balanced.
U = 0, D = 0Undefined: 0 / 0No body movement to normalize; this example leaves a gap.
Prior IMI ≤ 70, current IMI > 70Cross above 70A threshold event, distinct from every bar above 70.

Audit the calculation in Pine Script v6

Add this indicator to a standard candle chart in TradingView. It uses the chart session and timeframe, carries its rolling window across sessions, and plots only confirmed bars. The Data Window exposes both sums for manual checks. Change the length to 5 to reproduce the worked example on matching input data.

  • The example default is 14 bars, not an optimized setting. With continuous valid data, the first possible value appears on the fourteenth bar; it remains na if the denominator is zero.
  • Create an alert in TradingView and choose the required condition. A crossing requires valid adjacent IMI values; recovery from na is not itself a crossing signal.
  • A live close can change before the bar ends. The confirmed-bar gate delays plotted values and alert conditions until the closing update; it does not make the calculation predictive.
Chart-timeframe indicator with an explicit na policy for zero total body movement. Alert conditions describe observations and do not place orders.pine
//@version=6
indicator("IMI candle-body audit", overlay = false, precision = 2)
length = input.int(14, "Window bars", minval = 1)
upBody = math.max(close - open, 0.0)
downBody = math.max(open - close, 0.0)
upSum = math.sum(upBody, length)
downSum = math.sum(downBody, length)
totalBody = upSum + downSum
hasWindow = bar_index >= length - 1 and not na(totalBody)
imi = hasWindow and totalBody > 0 ? 100.0 * upSum / totalBody : na
crossAbove70 = ta.crossover(imi, 70.0)
crossBelow30 = ta.crossunder(imi, 30.0)
showValue = barstate.isconfirmed
plot(showValue ? imi : na, "IMI", color = color.blue, linewidth = 2, style = plot.style_linebr)
hline(70, "Upper reference", color = color.gray)
hline(50, "Midpoint", color = color.gray)
hline(30, "Lower reference", color = color.gray)
plot(showValue and hasWindow ? upSum : na, "Bullish body sum", display = display.data_window)
plot(showValue and hasWindow ? downSum : na, "Bearish body sum", display = display.data_window)
alertcondition(showValue and crossAbove70, "IMI crosses above 70", "Confirmed IMI crossed above 70.")
alertcondition(showValue and crossBelow30, "IMI crosses below 30", "Confirmed IMI crossed below 30.")

Match timeframe and sessions before comparing signals

Session selection changes the bars available to the calculation. A rolling IMI does not reset merely because a new trading day begins. Record regular versus extended hours, chart timeframe, and candle type before comparing two scripts or threshold counts.

  • Fourteen five-minute bars cover 70 minutes of bars only when those bars are continuous and complete. Fourteen daily bars cover a different sample. Session gaps can make elapsed clock time longer.
  • Aggregating candles changes the body ratio. Two bars, 100 to 103 and 103 to 101, give IMI 60 for N = 2. Combined into one 100-to-101 candle with N = 1, the same path gives 100. Comparing equal elapsed periods does not guarantee equal IMI.
  • A session-reset version must specify whether it waits for N new-session bars or uses a growing window. That is a different calculation from the rolling example above.
  • Use standard candles when validating market-price bodies. Heikin-Ashi and other synthetic charts can supply transformed open and close values.
  • Threshold events need a separately tested strategy with exits, sizing, commissions, slippage, and out-of-sample checks before any performance claim.

Give Pineify the body formula and comparison rules

Use the Pine Script AI Coding Agent to draft or revise IMI threshold conditions. Specify rolling body sums, a length of 14, na for a zero denominator, and confirmed-bar alerts. Keep the two diagnostic sums so you can compare the generated output with the arithmetic above.

  • For a timeframe comparison, ask for separate runs on five-minute and fifteen-minute standard charts with the same session selection. Compare timestamps and signal counts without assuming identical windows.
  • Ask for the distinction between a level state and a crossing event to remain visible in the source. Review the code and verify the final calculation in TradingView after any changes.
  • The agent can help write and explain code. It does not establish that an IMI threshold is profitable or automatically reproduce every third-party variant.
Where Pineify fits

Pine Script AI Coding Agent

Draft IMI conditions with explicit body inputs, window length, zero handling, and bar-close timing, then inspect the generated source.

Draft an IMI condition

Frequently asked questions

Educational information, not investment advice. The prices are hypothetical calculation fixtures, not backtest results. Oscillator levels and syntax validation do not establish trading profitability.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.