This is a port of jdehorty's Lorentzian Classification, which is one of the few genuinely interesting ideas to come out of the TradingView script library. Two things make it worth the install, and neither is the word "machine learning".

Gold H1. The Nadaraya-Watson kernel line takes its colour from its own slope; green arrows are long entries, faded red arrows are shorts, and the small crosses are the default exits four bars later.

One: distance is measured with a logarithm

A normal k-nearest-neighbour classifier measures how similar two bars are with Euclidean distance — square the differences, add them up. Big differences dominate, which is exactly wrong when the thing producing big differences is a news event rather than a change in market character.

This measures similarity as

distance = Σ  log(1 + |feature_now − feature_then|)

over however many features you enable. The logarithm compresses large gaps. A bar that differs enormously on one feature is not automatically ruled out as a neighbour, because the one outlier no longer swamps the other four.

The original author's framing is that price data sits in a warped space, the way spacetime warps around mass, and a distance measure should account for the warping. You can take or leave the physics. What survives is the arithmetic: log(1+|Δ|) behaves better than Δ² on data with fat tails, and financial data has fat tails.

Two: it does not take the nearest neighbours

This is the part that surprises people, and it is worth being precise because almost every description of this indicator gets it wrong.

The selection loop reads:

if(d >= lastDistance && j % 4 == 0)

Two conditions, both deliberate. j % 4 == 0 means only every fourth bar is even considered. And d >= lastDistance means a candidate is accepted only if it is at least as far away as the last one accepted.

So the eight "neighbours" are not the eight most similar bars in the window. They are a chronologically spaced sample whose distances are non-decreasing — a spread across the lookback rather than a cluster.

The reason is that the eight most similar bars are usually eight consecutive bars from one recent stretch, which tells you the market currently resembles itself and nothing else. Forcing the sample apart in time and in distance is what makes the prediction about market character rather than about last Tuesday.

If you were told this finds the most similar historical bars, you were told something the code does not do.

What it looks at

Default What it measures
Feature 1 RSI(14) momentum, medium
Feature 2 Wave Trend(10, 11) momentum, oscillator
Feature 3 CCI(20) deviation from the mean
Feature 4 ADX(20, 2) trend strength
Feature 5 RSI(9) momentum, fast

Five features, each swappable, each with two parameters. The prediction is a vote of the selected neighbours' labels, where a bar's label is whether price was higher or lower four bars later.

Max Bars Back defaults to 500 — the panel confirms what it actually used, and on a short chart that number will be lower than you set.

The filters, and which ones are on

Four filters sit between the raw prediction and a drawn arrow:

  • Volatility filter — on. Suppresses signals when recent range collapses.
  • Regime filter — on, threshold −0.1. A Kalman-style slope measure; blocks signals in ranging conditions.
  • ADX filter — off by default, threshold 20.
  • EMA / SMA filter — both off, period 200 each.

Turning all four off roughly triples the signal count and is the fastest way to see what the classifier alone thinks. I would look at that once, then put the volatility and regime filters back.

The kernel line

The blue and brown line is a Nadaraya-Watson regression using a rational quadratic kernel, and it is a separate mechanism from the classifier. Lookback window 8, relative weighting 8, regression level 25, lag 2.

With Trade with Kernel on — the default — an entry also requires the kernel to agree with the direction. That is the single most effective filter here, and it is the reason the arrows cluster where they do rather than firing on every prediction flip.

EURUSD H1. Twenty entries across three weeks, with the exits marked. This is what the model looks like when a symbol is producing signals.

Exits are fixed at four bars

Default exits fire exactly four bars after an entry. That is not a trading opinion — it is the label horizon the classifier is built around. The model was constructed to answer "will price be higher or lower in four bars", so the honest exit is four bars.

Use Dynamic Exits switches to a kernel-based exit that tries to let winners run. It is off by default, and it breaks the correspondence between what the model predicts and what the chart shows. Worth trying, worth knowing that is the trade.

The panel, and the number on it

LC winrate
B/S     #    %
Buy    11    55
Sell    9    78
Historical bar: 499

The percentages are the indicator counting, over the bars it scanned, how often price went the predicted way within the exit window it drew.

Read that as a calibration dial for the settings above, which is exactly what the original author intended it for, and nothing more. It knows nothing about spread, slippage, or the fact that you would not have taken all twenty. Change a feature and watch the number move; that is what it is for. You won't find a win rate table in this listing, and I would treat any indicator listing that has one with some care — including one built from this panel.

What it can't do

It draws a kernel line, entry arrows and exit crosses. No zones, no structure, no levels, no session logic.

The classifier is a vote over eight sampled bars from a 500-bar window. That is a small sample by any statistical standard, and it will produce runs of wrong signals. The filters exist because the raw classifier alone is noisy.

On the forming bar the kernel line can drop away to the axis until it has enough data for the current bar; you will see it as a vertical stroke at the right-hand edge. It resolves as the bar fills.

The MT4 build is a reduced version, and this is the biggest difference between the two files in this whole catalogue. It has:

  • no alert system beyond a plain terminal alert — no push, no email, no Telegram, and no notification-type selector
  • no bar colouring by prediction value
  • no printed prediction numbers on the bars

The engine is the same: same Lorentzian distance, same every-fourth-bar sampling, same kernel, same filters, same panel. What is missing is the display and notification layer. If alerts are why you want this, use the MT5 build.

Questions you'll have

Is it really machine learning? It is k-nearest-neighbour, which is a real ML algorithm that does no training. There are no weights and nothing is fitted. It is a structured lookup over history, and it is honest work — but nobody trained a model here.

Why only every fourth bar? To stop all eight neighbours coming from one recent stretch. See above; it is the most important design decision in the indicator.

Should I turn the filters off? Once, to see the classifier bare. Then put the volatility and regime filters back on.

What timeframe? H1 and H4. The 500-bar window on M5 covers less than two days, which is not enough history for the neighbour search to mean anything.

MT4 or MT5? Both, and your subscription covers both — but read the reduced-build note above first. This is the one product where I would tell you the MT5 version is meaningfully better.

Support

Message me through the site with a screenshot that includes the panel, plus the symbol and timeframe. Updates are included for as long as your subscription is running.

Analysis tool. It places no trades and makes no profitability claim. Past price behaviour is not a guide to future price behaviour.