TradingView indicator calculations

Fractal Dimension Index on TradingView: trend and range tests

The Fractal Dimension Index estimates the roughness of a price path over a chosen window. Lower readings describe a smoother path; higher readings describe more back-and-forth movement under the selected estimator. FDI supplies no upward or downward forecast. This guide uses the Sevcik normalized path-length estimate and reproducible synthetic samples, so you can check the formula before interpreting the colors or thresholds of a TradingView script.

See the decision guide

Choose one published calculation

The Sevcik paper normalizes a sampled waveform into a unit square, measures its path length L, and estimates D = 1 + ln(L) / ln[2(N − 1)]. Here the waveform is N consecutive chart closes, ordered oldest to newest. Use equally spaced bar indices and integer N ≥ 3. These choices define the example; a community script with Katz, another normalization or extra smoothing need not match it.

  • Return no value until N valid closes exist. For a fully flat window, return no value and label it flat/undefined: the price normalization divides by zero. Do not silently label a flat market a strong trend.
  • For this example, a missing observation invalidates the window. Wait for N consecutive valid closes rather than treating missing data as zero or skipping bars.
  • No recursive seed or previous FDI value is needed. Each valid window is recalculated independently, using its own minimum and maximum.
StepCalculationCheck
Window range Rmax(close) − min(close)Use the same N closes throughout.
Normalized price y[i](close[i] − min(close)) / RDefined only when R > 0.
Time increment dx1 / (N − 1)There are N − 1 adjacent segments.
Path length LΣ sqrt(dx² + (y[i] − y[i−1])²), i = 1 to N − 1Normalize first, then sum segment lengths.
Dimension estimate D1 + ln(L) / ln[2(N − 1)]Use full precision before comparing a threshold.

What the 1 to 2 scale means for a finite window

For this formula with R > 0, each segment has horizontal length 1/(N − 1) and vertical length at most 1. Thus 1 ≤ L ≤ sqrt[(N − 1)² + 1], giving 1 ≤ D < 2 for N ≥ 3. This is a bound for the stated estimator, not a guarantee for every script named FDI.

  • A perfectly straight non-flat ramp has L = sqrt(2). For N = 5 it gives D = 1.166667; for N = 17 it gives D = 1.100000. Neither is exactly 1, despite both paths being straight.
  • Replacing every price p with a + bp, for any nonzero b, preserves the normalized segment lengths. Reversing a rise into an equally shaped fall therefore leaves D unchanged.
  • Multiplying tiny price fluctuations by 100 also leaves D unchanged. Roughness is not the same as volatility in dollars, tradeable range or position risk.
  • Some TradingView authors use 1.5 to separate trend-like and range-like conditions. Below, use D < 1.5 for lower roughness, D > 1.5 for higher roughness, and equality as the boundary. These labels describe the sample only.

Reproduce trend, noise and mixed-window results

The following 17-close samples are hypothetical arithmetic fixtures, not market observations or backtests. Read each from oldest to newest. The irregular sample is constructed noise-like data, not a statistical claim that the prices follow a random process. Every shorter window uses the last N values of the same sample.

  • Trend: 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116.
  • Noise-like: 100, 103, 99, 104, 100, 98, 103, 101, 105, 99, 102, 98, 104, 100, 103, 99, 101.
  • Mixed: 100, 101, 102, 103, 104, 105, 106, 107, 108, 107, 108, 107, 108, 107, 108, 107, 108.
SampleN = 5N = 9N = 17
Trend1.166667; lower1.125000; lower1.100000; lower
Noise-like1.494799; lower1.557548; higher1.626799; higher
Mixed1.681244; higher1.752796; higher1.232193; lower

Explain the mixed sample classification reversal

The latest five mixed closes are 108, 107, 108, 107, 108. Their range is 1, dx = 1/4, and each normalized price change has magnitude 1. Therefore L = 4 × sqrt(1/16 + 1) = sqrt(17), and D = 1 + ln(sqrt(17))/ln(8) = 1.681244. The short window records repeated reversals.

  • Across all 17 mixed closes, the range is 8 and every raw adjacent change has magnitude 1. Now dx = 1/16 and each normalized price change has magnitude 1/8. L = 16 × sqrt(1/256 + 1/64) = sqrt(5), giving D = 1.232193.
  • The longer window includes the earlier rise and compresses the later oscillation relative to the whole range. It receives a lower-roughness label even though its final nine prices repeatedly reverse.
  • The noise-like sample also crosses the 1.5 convention when N changes. Its five-bar value of 1.494799 is only about 0.0052 below that line. A binary label can hide how close a reading is to the boundary.
  • Keep N fixed when comparing timestamps. If testing several lengths, report each length and the disagreement instead of choosing whichever label supports a trade.

Check the TradingView script and its timing

Record the author, version, estimator, source, length, session, chart type and timeframe. Compare intermediate range, L and D before comparing colors. A title alone cannot establish numerical parity. The Williams Fractal indicator instead marks local high/low patterns, commonly across five bars; its arrows are a different output from this window statistic.

  • For an alert that first enters lower roughness, require a valid previous D ≥ 1.5 and a valid current D < 1.5 at the chart close. Do not fire repeatedly just because the state remains below 1.5.
  • TradingView documents chart-bar confirmation separately from higher-timeframe data handling. A closed chart bar alone does not settle an unfinished higher-timeframe input.
  • A low reading does not choose long versus short. Entries, exits, position size and trading costs require separate rules and separate testing.
Failure caseWhy it mattersVerification
Open current candleThe current close and window extrema can change.Evaluate the final classification on a completed chart bar.
Large isolated moveA changed window range rescales every segment.Inspect R and L, not just the resulting color.
Flat or incomplete windowNormalization or required observations are unavailable.Show an undefined state and suppress classification alerts.
Different script formulaKatz and Sevcik are separate estimators.Match the exact formula and segment count first.
Extra smoothing or higher-timeframe inputThe plotted value or its confirmation time changes.Disable additions for the fixture comparison; audit them separately.

Give Pineify a calculation that can be reviewed

The Pine Script AI Coding Agent can draft a script from a written specification. Supply this public formula, the three fixtures, N-close initialization, undefined-state handling and chart-close alert rule. Request visible diagnostic values for R, L and D, then compare the generated output in TradingView before relying on alerts.

  • Require the raw, unsmoothed Sevcik estimate with no future bars or plot offset. State that flat and missing windows must not inherit a previous classification.
  • Ask for the 5-, 9- and 17-close fixture checks, plus a falling ramp and a constant-price window. Syntax validation and numerical agreement are separate checks.
  • Use a published algorithm or source you have permission to use. This workflow does not recover protected or invite-only source code, and it does not establish predictive value.
Where Pineify fits

Pine Script AI Coding Agent

Draft an FDI implementation from the stated formula and verification fixtures, then inspect its numerical output and alert timing in TradingView.

Draft an FDI calculation

Frequently asked questions

Educational calculations, not investment advice. All sample prices are hypothetical. No trading performance or predictive accuracy has been tested; a dimension estimate does not guarantee any future market behavior.

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.