TradingView indicator guides

Lorentzian Classification: features, labels and backtest leakage

The Lorentzian Classification indicator by jdehorty uses technical features, logarithmic distance and an approximate neighbor routine to produce a directional score. To evaluate it, inspect the exact source version and when its labels become known. A machine-learning name or colored signal does not establish predictive accuracy.

This audit uses the author team pinned Pine v6 reference, checked on October 17, 2026. The working diagnostic below isolates label timing; it does not reproduce the full classifier.

Which implementation is being audited?

The pinned v2 source imports jdehorty/MLExtensions/2 and jdehorty/KernelFunctions/2. Its defaults include close as the source, eight neighbors, a Max Bars Back value of 2,000 and five features. The public release notes add an Include Full History option; preserve that option in any comparison with an older copy.

The feature functions use normalized library outputs. Their units matter: substituting raw CCI or ADX changes the distance geometry. Feature Count selects two to five slots, and each slot can select RSI, WT, CCI or ADX. The defaults are:

Default feature slots in the pinned author source
SlotFeatureParameters A, BLibrary call
1RSI14, 1ml.n_rsi(close, A, B)
2WaveTrend (WT)10, 11ml.n_wt(hlc3, A, B)
3CCI20, 1ml.n_cci(close, A, B)
4ADX20, 2ml.n_adx(high, low, close, A); B unused
5RSI9, 1ml.n_rsi(close, A, B)

Distance is only one part of the algorithm

The distance is the sum of ln(1 + absolute feature difference) across selected slots. For illustrative normalized differences 0.10 and 0.40, it is ln(1.10) + ln(1.40) = 0.4318. Changing the second difference to 0.80 gives 0.6831. Log scaling compresses large differences; that mathematical property alone does not show better trading returns.

The executable neighbor rules deserve separate inspection. The pinned code accepts a candidate when its distance is at least lastDistance and its array index modulo four is nonzero. Indices 1, 2 and 3 can therefore all pass the index condition; index 4 cannot. Despite the surrounding comment, this condition does not guarantee four-bar spacing.

The label and distance arrays persist between bars. When their size exceeds the neighbor count, the code updates its threshold from an array position and removes the oldest pair. The resulting score sums the retained labels. This is different from sorting all distances and choosing the K smallest, and the score is not a percentage confidence.

Include Full History changes the loop start index to zero. The loop end remains capped by Max Bars Back minus one and the stored label count. The other start index uses last_bar_index. Audit the actual bounds on your loaded dataset instead of assuming the option scans every historical bar or creates a simple rolling window.

Volatility, regime and ADX filters gate the classifier signal. EMA/SMA and kernel conditions also affect entries. The kernel estimate is a separate price smoother; its color is not the neighbor vote. A nonzero score and a new entry marker are different events.

A four-bar label is not automatically a future label

In the pinned author source, the label is -1 when the current source exceeds its value four bars ago, +1 when it is lower, and 0 when equal. The current features and that label are appended at the same array position. This is the literal implementation, even though the comments describe prediction over the next four bars.

Hypothetical closed bars, using close as the source
TimeKnown dataLabel consequence
Bar 100 closeClose = 100; feature X100 knownThe outcome from 100 to 104 is unavailable.
Bar 104 closeClose = 104; X104 knownAuthor expression stores -1 alongside X104.
Separate forward-target designX100 paired with sign(104 - 100) = +1This pair may first enter training at bar 104 close.

The author expression shown here uses past and current prices; it is not itself evidence of future access. A forward-target rewrite is a different model. It leaks future information if the +1 outcome is made available to a prediction on bar 100, before bar 104 closes. For a clean target, store the earlier features with the matured outcome and exclude outcomes unavailable at prediction time.

Pine v6 diagnostic: compare availability, not performance

This standalone teaching script preserves the author label expression and contrasts it with a matured forward target. It uses RSI only as an example earlier feature, has no neighbors or kernel, and creates no trading signals. Both labels appear at their availability bar, with no negative plot offset. On the 100-to-104 example, orange is -1 and blue is +1.

Label timing audit

Copy diagnostic

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Label expression adapted from Lorentzian Classification, ©jdehorty.
// Diagnostic wrapper and delayed-label comparison © Pineify.
//@version=6
indicator("Lorentzian label timing audit (not a classifier)", overlay = false)
source = input.source(close, "Source")
feature = ta.rsi(close, 14)
ready = barstate.isconfirmed and not na(source[4]) and not na(feature[4])

// Reproduces the author's label expression at its availability bar.
authorLabel = source[4] < source ? -1 : source[4] > source ? 1 : 0
// A separate teaching target: forward outcome for the feature FOUR bars ago.
forwardLabel = source > source[4] ? 1 : source < source[4] ? -1 : 0

plot(ready ? authorLabel : na, "Author expression at current bar", color = color.orange, style = plot.style_circles, linewidth = 3)
plot(ready ? forwardLabel : na, "Matured forward target for bar t-4", color = color.blue, style = plot.style_circles, linewidth = 2)
plot(ready ? feature[4] : na, "Feature at t-4 (Data Window only)", display = display.data_window)
hline(0, "Unchanged source", color = color.gray)
// No backdated plots, entries, alerts, neighbors, or performance estimates.

The adapted expression retains attribution to ©jdehorty and the MPL 2.0 license. Keep applicable headers when modifying the original script or its libraries. TradingView republication also has platform rules. This page diagnostic is not an author-endorsed replacement.

Separate repainting, leakage and overfitting

The TradingView repainting documentation distinguishes changing realtime values from future information used in the past. Waiting for a confirmed bar addresses fluid prices; it cannot repair a mislabeled training set or settings chosen with test data.

  1. Save the script version, library versions, symbol, timeframe, session, data start and all inputs. Record Include Full History explicitly. Dataset-dependent bounds can change the candidate pool after a reload.
  2. Log prediction time, feature time, outcome end time and selected neighbor indices. A forward-outcome sample is eligible only after its outcome end. Check whether the query bar can select itself, and whether persistent arrays behave as intended.
  3. Record closed-bar markers and alerts during replay or forward observation, reload, then compare identical timestamps. Use alerts configured for bar close if that is the tested decision time. This tests stability, not profitability.
  4. Choose settings on an earlier training interval and freeze them before a later test interval. For a four-bar forward target, exclude training rows whose outcomes cross into that test interval. Decide in advance whether the model stays frozen or may learn from newly matured test samples.
  5. Specify entries, exits, position size, fees, slippage and fill timing. Test multiple later market periods and compare the same execution rules with a simple baseline. Report trade count and drawdown alongside returns.

For Strategy Tester, the author Backtest Adapter reads the indicator Backtest Stream. Add both to the same chart and select that stream as the adapter Source. Check its orders and assumptions; the indicator calibration table alone is not a full execution simulation.

Educational code analysis, not investment advice. No win rate or profitable setting is established here. Syntax validity does not establish correct labels, stable historical signals or live trading performance.

Continue the audit in Pineify

Give the Pine Script AI Coding Agent the lawful source version you use and ask it to explain the indexing, add diagnostic plots or modify explicit rules. Review the generated changes and validate them in TradingView. The agent does not prove predictive accuracy or certify that a model is free of leakage.

Explain the feature and label timestamps in this source. Preserve ©jdehorty and the MPL header. Add Data Window diagnostics for candidate index and label availability without changing the classifier. Identify any dependence on last_bar_index.
Review Pine Script with the AI Coding Agent

After creating a separate strategy test, upload its TradingView trade CSV to Backtest Deep Report. It analyzes exported trades; it does not retrain the classifier, accept arbitrary OHLC as a substitute for trades, or detect hidden label leakage from that CSV.

Lorentzian Classification FAQ

Sources and related reading

Verified October 17, 2026. Source-code observations refer to the pinned revision, not every script sharing this name.