TradingView indicator guides

Trend Intensity Index: deviation balance and signals

The Trend Intensity Index (TII) is the positive share of total absolute price deviation from an SMA, expressed from 0 to 100. Above 50, positive deviations outweigh negative ones. Below 50, negative deviations outweigh positive ones. The number depends on which SMA you use for historical bars.

A reading you can check

Positive deviations totaling 5 and negative deviations totaling 2 give TII = 100 × 5 / 7 = 71.43. This is a balance of distances, not a count of rising bars.

Educational indicator example. It is not investment advice, a tested trading strategy, or a return guarantee.

Choose the baseline before comparing TII values

M.H. Pee introduced TII in the June 2002 issue of Technical Analysis of Stocks & Commodities. His spreadsheet sidebar, page 3 compares the recent 30 closes with one current 60-day SMA. A different implementation compares each close with its own historical SMA. Pineify's existing visual-editor TII function uses that second convention.

Two calculations with the same indicator name
ConventionDeviation for bar i bars agoFull history at 60/30
Current SMAclose[i] - SMA[today]60 bars
Each bar's SMAclose[i] - SMA[i]89 bars

The example below defaults to the current SMA. Its checkbox selects the per-bar convention. On complete history, the latter matches the baseline alignment in Pineify's existing function; this example deliberately adds stricter warm-up and zero-denominator handling. The two modes can disagree even with identical 60/30 lengths.

Formula: aggregate distances on each side

Let L be the SMA length and N the deviation window. For each of the N closes, subtract the baseline selected above. Positive deviations contribute to U; absolute negative deviations contribute to D. A close exactly at the baseline contributes zero to both.

U = sum(max(deviation, 0))
D = sum(max(-deviation, 0))
TII = 100 * U / (U + D), when U + D > 0

At 50, U equals D. At 80, U is four times D; at 20, D is four times U. If all nonzero deviations are positive, the ratio is 100 regardless of whether those distances are small or large. TII does not report volatility in price units or the size of the next move.

The rolling aggregation already combines N observations. There is no extra signal-line smoothing in this example. Adding an EMA or SMA of the output creates a separate smoothed series whose crossings can occur on different bars.

Worked example: a six-bar SMA and three deviations

Use six hypothetical closes, oldest first: 98, 100, 102, 99, 103, 104. With L = 6 and N = 3 in current-SMA mode, the baseline is 606 / 6 = 101. Only the latest three closes contribute deviations.

Synthetic prices, not market performance
CloseDeviation from 101U contributionD contribution
99-202
103220
104330

U = 5 and D = 2, so TII = 71.4286. Two of three closes are above the baseline, but that count is 66.67%. The different percentages show why counting closes cannot reproduce the deviation formula.

To check the other convention, prepend two closes of 100 to the same sequence. The historical six-bar SMAs for the last three closes are 99.8333, 100.3333, and 101. Their per-bar deviations are -0.8333, +2.6667, and +3. With U = 5.6667 and D = 0.8333, per-bar TII is 87.1795. Current-SMA TII remains 71.4286 on the same final bar.

A higher close can accompany lower intensity

For a separate synthetic sequence 90, 90, 90, 105, 95, 110, the six-bar SMA is 96.6667. The latest three deviations are +8.3333, -1.6667, +13.3333. U = 21.6667 and D = 1.6667 produce TII = 92.8571.

Append a new high at 111. The six-bar window becomes 90, 90, 105, 95, 110, 111, with SMA = 100.1667. The latest deviations are -5.1667, +9.8333, +10.8333. U = 20.6667 and D = 5.1667 produce TII = 80. The latest price rose, but its deviation balance weakened. Both readings remain above 50.

If all six closes instead equal 100, the SMA is 100 and every deviation is zero. U + D = 0 makes the ratio undefined; the supplied script returns na. These examples use unrounded values for the final ratios.

TII versus RSI and the two TSI indicators

TradingView's RSI calculation smooths gains and losses between consecutive closes with Wilder's RMA. TII measures distance from an SMA. Sharing a 0-to-100 scale does not make their thresholds interchangeable.

For example, a close falling from 104 to 103 contributes a loss of 1 to RSI. If the chosen SMA reference is 101, the close at 103 still contributes a positive deviation of 2 to TII. This describes their inputs; the final oscillator values also depend on earlier observations.

True Strength Index compares double-smoothed price changes and absolute changes. Trend Strength Index measures price/bar-index correlation. Neither uses the TII deviation balance. When importing a script, inspect its formula instead of relying on the acronym.

Select periods by the question you want to test

The historical 60/30 pair is a reference, not a best setting for every market. L controls the baseline; N controls which deviations enter the ratio. For current-SMA mode, changing L can move the reference for every close in the deviation window at once.

  • Keep N fixed when testing a faster or slower SMA. Record how the baseline shift reclassifies the same historical closes.
  • Keep L fixed when testing N. A shorter window discards older deviations sooner; a longer one retains them. Neither guarantees fewer false signals.
  • Record the chart timeframe and session. Sixty hourly chart bars and sixty daily bars cover different histories; a chart with session gaps is not a continuous clock.
  • Use the same baseline convention and output smoothing for every comparison. Under complete close data, the required history is max(L, N) bars in current-SMA mode and L + N - 1 in per-bar mode.

If testing a rule such as a confirmed cross above 50, define the entry, exit, position size, and costs separately. Freeze parameter choices before evaluating another period. Signal frequency alone does not establish a profitable strategy.

Pine Script v6 with an explicit baseline switch

Copy the code into TradingView's Pine Editor and add it to the chart. The separate pane plots TII with 20, 50, and 80 references; the Data Window exposes both sums and the current SMA for inspection. Start with a standard candle chart and close prices.

Pine Script v6
//@version=6
indicator("Trend Intensity Index: baseline comparison", overlay = false, max_bars_back = 1000)

smaLength = input.int(60, "SMA length", minval = 1, maxval = 500)
tiiLength = input.int(30, "Deviation window", minval = 1, maxval = 500)
perBar = input.bool(false, "Use each bar's SMA instead of current SMA")
baseline = ta.sma(close, smaLength)

float upSum = 0.0
float downSum = 0.0
bool ready = not na(baseline)
for i = 0 to tiiLength - 1
    reference = perBar ? baseline[i] : baseline
    if na(close[i]) or na(reference)
        ready := false
    else
        deviation = close[i] - reference
        upSum += math.max(deviation, 0.0)
        downSum += math.max(-deviation, 0.0)

total = upSum + downSum
tii = ready and total > 0 ? 100.0 * upSum / total : na
lineColor = tii > 80 ? color.green : tii < 20 ? color.red : color.blue
plot(tii, "TII", color = lineColor, linewidth = 2, style = plot.style_linebr)
plot(ready ? upSum : na, "Positive deviation sum", display = display.data_window)
plot(ready ? downSum : na, "Negative deviation sum", display = display.data_window)
plot(baseline, "Current SMA", display = display.data_window)
hline(80, "Upper reference", color = color.gray, linestyle = hline.style_dotted)
hline(50, "Equal deviation sums", color = color.gray, linestyle = hline.style_dashed)
hline(20, "Lower reference", color = color.gray, linestyle = hline.style_dotted)
bgcolor(tii > 80 ? color.new(color.green, 92) : tii < 20 ? color.new(color.red, 92) : na)

crossUp = ta.crossover(tii, 50)
crossDown = ta.crossunder(tii, 50)
confirmedUp = barstate.isconfirmed and crossUp
confirmedDown = barstate.isconfirmed and crossDown
alertcondition(confirmedUp, "TII crossed above 50", "TII crossed above 50 on a closed chart bar.")
alertcondition(confirmedDown, "TII crossed below 50", "TII crossed below 50 on a closed chart bar.")

For the first arithmetic example, the equivalent input lengths are 6 and 3 with the checkbox off. The synthetic sequence is a hand-calculation fixture, not data that this chart indicator injects into TradingView.

The live line can change before a bar closes. Alert conditions use barstate.isconfirmed on the chart timeframe. Create the desired alert in TradingView after adding the indicator. This code neither creates an alert automatically nor submits orders.

Where TII readings can mislead

  • Persistent extremes can continue during a trend. A reading above 80 does not establish an exit or short entry, and a reading below 20 does not establish a bottom.
  • A single large deviation can dominate the sum. TII measures the size of deviations, so it can disagree with a count of up and down bars.
  • A tiny positive denominator can yield an extreme ratio even when price barely moves. Inspect the sums and the price chart before assigning economic significance.
  • Price oscillating around the baseline can generate repeated 50 crossings. A second indicator does not automatically turn these crossings into a validated trading edge.
  • A changing current SMA can lower TII without a new price low. Divergence describes a disagreement; it does not provide a reversal deadline.

Use the chosen formula in Pineify

Pine Script AI Coding Agent can help draft or revise an indicator from explicit rules. Supply the baseline convention before requesting a trend filter or alert. Pineify's existing visual-editor TII uses historical SMA values per bar, so do not assume it matches the current-SMA default shown here.

Create a Pine Script v6 TII using close prices, SMA 60, and a 30-bar deviation window. Compare every close in the window with the current SMA. Return na for missing history or a zero denominator. Add a confirmed chart-bar alert when TII crosses above 50. Show both deviation sums in the Data Window.

Review the generated source, check its syntax, and compare its values on closed bars. Agent access and usage depend on your account and plan; the code on this page can be copied without an agent request.

Explore Pine Script AI Coding Agent

Trend Intensity Index questions

Sources and related reading

Sources checked October 17, 2026. The numerical examples are synthetic calculations. They are not backtest results.

Continue with RSI, Trend Strength Index, or the TradingView indicators category.