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.
| Step | Calculation | Check |
|---|
| Window range R | max(close) − min(close) | Use the same N closes throughout. |
| Normalized price y[i] | (close[i] − min(close)) / R | Defined only when R > 0. |
| Time increment dx | 1 / (N − 1) | There are N − 1 adjacent segments. |
| Path length L | Σ sqrt(dx² + (y[i] − y[i−1])²), i = 1 to N − 1 | Normalize first, then sum segment lengths. |
| Dimension estimate D | 1 + 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.
| Sample | N = 5 | N = 9 | N = 17 |
|---|
| Trend | 1.166667; lower | 1.125000; lower | 1.100000; lower |
| Noise-like | 1.494799; lower | 1.557548; higher | 1.626799; higher |
| Mixed | 1.681244; higher | 1.752796; higher | 1.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 case | Why it matters | Verification |
|---|
| Open current candle | The current close and window extrema can change. | Evaluate the final classification on a completed chart bar. |
| Large isolated move | A changed window range rescales every segment. | Inspect R and L, not just the resulting color. |
| Flat or incomplete window | Normalization or required observations are unavailable. | Show an undefined state and suppress classification alerts. |
| Different script formula | Katz and Sevcik are separate estimators. | Match the exact formula and segment count first. |
| Extra smoothing or higher-timeframe input | The 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.