Lorentzian Classification: what it actually does
It gets called machine learning in the title and "a dressed-up indicator" in the comments. Both are partly right. It is a real machine-learning algorithm — and that fact tells you nothing about whether it makes money.
Lorentzian Classification became widely known through "Machine Learning: Lorentzian Classification", an open-source TradingView indicator by jdehorty released in 2023 that drew a very large following. The name sounds like physics. What it describes is a k-nearest-neighbours classifier — one of the oldest algorithms in machine learning — that measures the distance between market states with a Lorentzian formula instead of the usual Euclidean one.
Strip the vocabulary away and the idea is old and sound: find the moments in history that most resemble right now, and see what happened next. This guide is about what that means in practice, why the distance metric was chosen, whether the indicator repaints, and what to ask of it before you trade it.
How nearest-neighbour classification works
A nearest-neighbour model does not learn weights the way a regression or a neural network does. There is no training step that fits parameters. The model keeps the data and answers every question by lookup:
- Describe each historical bar by a handful of features — in the TradingView script, RSI, WaveTrend, CCI, ADX and a second RSI, by default — so every bar is a point in five-dimensional space.
- Label each historical bar by what happened next: did price go up or down over the following few bars?
- For the current bar, measure the distance from its point to every historical point, and take the k closest — the neighbours.
- Vote. If most neighbours were followed by a rise, predict a rise. The margin of the vote is the model's confidence.
That is the entire algorithm. It is genuinely machine learning — it makes predictions from data without hand-written rules — and it is genuinely simple. Both are true at once.
Why the Lorentzian distance, specifically
Euclidean distance — the straight-line distance you learned in school — squares each feature's difference and adds them up, so one feature that is very far away dominates everything. The Lorentzian distance used in the script replaces each squared difference with log(1 + |difference|). The log grows slowly, so large differences are compressed and no single feature can swamp the others.
A worked example
Two historical bars, compared to now on two features. Bar A differs by 1 unit on RSI and 1 unit on ADX. Bar B differs by 0 on RSI and 4 on ADX.
- Euclidean: A = √(1² + 1²) ≈ 1.41. B = √(0² + 4²) = 4. Bar A is much closer.
- Lorentzian: A = log(2) + log(2) ≈ 1.39. B = log(1) + log(5) ≈ 1.61. Bar A is still closer — but only just. The one large difference on B has been compressed.
The script's author justifies this with an analogy to how mass warps space in relativity — the idea being that big market events "warp" the feature space, and a metric that discounts extreme differences finds better neighbours through them. It is a rationalisation, not a proof. What the metric actually does is make the neighbour search robust to outliers in any one feature, which is a reasonable thing to want. It is a reasonable choice, not a discovery, and other robust metrics would behave similarly.
Does it repaint?
The original script's documentation states that once a bar has closed, neither the predictions nor its kernel-regression estimate are recalculated. On that account it does not repaint in the damaging sense — the centred-window kind where past signals move once the future is known. Three honest caveats:
- It does update on the current bar while that bar is forming, like almost every indicator. Act on closed bars only, or your live trades will not match the historical plot.
- "Does not repaint" is a property of an implementation, not of the algorithm. The many forks, ports and "ultimate" variants each need the bar-replay test run on them separately.
- Not repainting is not the same as not leaking. If the features are computed on the current bar's close and the fill is assumed at that same close, the historical signals used information that was not available when a trader could have acted. That is leakage by another route, and it applies to any indicator.
What to ask of it
Does the result survive a one-bar shift?
Delay every signal by one bar — enter at the next open instead of the signal bar's close — and rerun. A real edge gets slightly worse. A result that depended on acting at a price you could not have had collapses. This test takes one setting change and settles more than any argument about the name.
How many neighbours, chosen how?
k is a parameter. Small k is noisy; large k averages everything into the base rate. If k was chosen by looking at which value produced the best chart, it was fitted, and the parameter-plateau test applies: does k ± 2 give a similar result?
Which features, picked when?
Five default features, each with a lookback. Were they chosen before looking at results, or after? The script exposes them for a reason, and every change you make is a parameter with the same plateau question attached.
Do the neighbours overlap the present?
A nearest-neighbour search over a rolling window will, unless prevented, find that the most similar bar to now is the bar immediately before now — whose label depends on bars that have not happened yet. The original script skips very recent bars and samples the window sparsely, partly for this reason. Any implementation that does not is leaking through the labels, the same overlap problem the purge gap exists to fix.
Where nearest-neighbour methods genuinely struggle
| Property | Why it matters here |
|---|---|
| Transparent | You can look at the neighbours and see why it voted the way it did — rare among ML models |
| No training step | Nothing to overfit in the fitting sense; everything to overfit in the feature and k choices |
| Curse of dimensionality | With many features, every point is far from every other and "nearest" stops meaning anything. Five features is a sensible limit, not a small one |
| Non-stationarity | The neighbours come from past regimes. A bar that looks like 2019 may behave nothing like 2019. Rolling windows help; nothing fixes it |
| Base-rate drift | In a long bull market, most neighbours were followed by a rise regardless of features, and the vote learns the drift, not the setup |
The useful conclusion
Lorentzian Classification is a legitimate, simple, transparent classifier with a sensible robustness tweak. It is neither the AI its title implies nor the trick its critics call it. Treat it as one model among several: run it through the shift test, sweep k and the feature lookbacks, validate it with a chronological purged split, and compare it to a boosted tree and a regularised linear model on the same features. The model families guide covers what to expect from each. If it earns its place, keep it. If it does not, the name was never the point.
Lorentzian Classification in Wise Apple
Wise Apple includes Lorentzian Classification as one of its three k-nearest-neighbour models, alongside eighteen others across six families, and it is validated the same way as every other model: chronological split, Embargo Bars between train and test, fills after the decision bar, and precision and MCC reported on out-of-sample windows. You can run it alone, sweep its settings, or put it in an Ensemble Voting group next to a boosted tree and see whether they agree. The MPL-licensed indicator itself also ships as a WiseApple Script built-in, attributed to its author, and any script's output can be used as a model feature.
Questions traders ask about Lorentzian Classification
Is Lorentzian Classification real machine learning?
Yes. It is a k-nearest-neighbours classifier, one of the oldest supervised learning algorithms, using a Lorentzian distance instead of Euclidean. It predicts from data without hand-written rules, which is the definition. That is a low bar, and clearing it says nothing about whether the predictions hold up out of sample.
Does Lorentzian Classification repaint?
The original TradingView script's documentation states that closed-bar predictions are not recalculated, so it does not repaint in the damaging sense. It does update on the forming bar, so act on closed bars. Forks and ports need their own bar-replay test, and not repainting does not rule out leakage through same-bar fills or overlapping labels.
What is the Lorentzian distance and why use it?
A distance between two feature vectors computed as the sum of log(1 + |difference|) over each feature, instead of the sum of squared differences used by Euclidean distance. The log compresses large differences so no single extreme feature dominates the neighbour search. It is a reasonable robustness choice; the relativity analogy used to explain it is a metaphor, not a derivation.
Is Lorentzian Classification better than other ML models for trading?
Not in general. On tabular market data, regularised gradient-boosted trees are usually the stronger default, and a regularised linear model is the benchmark any model must beat. kNN's advantages are transparency and having nothing to fit; its weaknesses are sensitivity to feature choice, the curse of dimensionality, and neighbours drawn from regimes that no longer apply. Test it against the alternatives on the same features and split.