A moving average takes the last N bars and averages them. Every bar in the window counts, including the ones that look nothing like what the market is doing now.

This one does something different. It looks back over a window, finds the k bars whose value is closest to the current bar's target, and averages only those. Recency is not the criterion. Similarity is.

That is k-nearest-neighbour, and it is the whole idea. Everything else here is plotting.

Gold H1. The fast line takes its colour from its own slope - green rising, red falling, orange flat. The slow blue line underneath is the classifier.

Say plainly what "AI" means here

It means k-nearest-neighbour averaging, which is a lookup, not a model. Nothing is trained. Nothing is fitted. There are no weights, and there is no learning between one bar and the next.

I would rather set that expectation than let the name do work it hasn't earned. What you get is a smoother that resists being dragged around by bars unlike the present one, and that is a real and useful property. It is not a forecast, and anything sold to you as an AI that predicts price is being sold dishonestly.

The two lines

Knn MA (thin, tri-colour) is the k-nearest-neighbour average, then smoothed by a 5-period weighted average. Its colour is purely its own slope: green if it rose against the previous bar, red if it fell, orange if it did neither.

Knn Classifier Line (thick, two-colour) is an RMA of the same k-NN series over smoothingPeriod, default 50. Its colour comes from a separate vote described below.

The pair are meant to be read like a fast/slow crossover, and the alerts fire on exactly that. But note what they actually are: both are derived from the same k-NN series, one lightly smoothed and one heavily smoothed. They are not independent evidence.

Value and target: the two halves you choose

Setting Options What it feeds
PriceValue hl2, VWAP, SMA, WMA, EMA The value stored for each historical bar
TargetValue price action, VWAP, volatility (ATR), SMA, WMA, EMA The target the current bar is matched against
numberOfClosestValues default 3 How many neighbours get averaged
smoothingPeriod default 50 The classifier line's RMA length

Defaults are hl2 for value and price action for target, which means: find the three bars in the recent window whose hl2 was nearest to where price is now, and average them.

Change TargetValue to volatility and the neighbours are chosen by ATR similarity instead — bars that had the same character of movement, regardless of price level. That is a genuinely different indicator with the same code, and it is the input worth experimenting with first.

The lookback window is max(numberOfClosestValues, 30) bars. It is not directly settable, which is a limitation worth knowing: raising the number of neighbours past 30 is the only way to widen it.

EURUSD H1. The fast line's colour flips track each swing; the classifier only becomes relevant when price comes back to it.

The classifier vote, and its honest limitation

The blue/red colour on the slow line comes from a vote over the ten bars before the current one. For each, the routine tracks the nearest price match found so far and counts whether a fast RMA sat above or below a slow RMA at that bar. Positive count beats negative count, and the result is smoothed by a 3-period weighted average.

Two things follow that I would want to know as a buyer.

First, the vote only counts a bar when it sets a new nearest match. Bars further away than one already seen are skipped. In practice that means the vote is usually decided by two or three bars, not ten.

Second, with smoothingPeriod = 50 the classifier line needs fifty bars of history before it means anything, and it starts far below price. On a fresh chart it will sit well away from the candles for a long stretch, as it does in both screenshots above. That is the RMA warming up, not a signal.

Repainting

The calculation runs only when a new bar opens, and it writes the current forming bar as well as the closed one. So the rightmost point of both lines is provisional: it is computed once at bar open and recomputed with final data when the bar closes.

Everything behind the last bar is fixed and does not move. If you need a value you can rely on, read the second-to-last bar.

I would rather say this than claim a non-repainting badge the code does not support.

Alerts

Six of them: the fast line crossing above or below the classifier line, the classifier changing colour in either direction, and the fast line changing colour in either direction. All go through whichever channel noti_type selects — terminal alert (the default), mobile push, or email.

Nothing fires on the first pass, so loading the indicator does not replay history at you.

The MT4 build has no Telegram. Terminal, push and email work on both platforms; the Telegram path exists only in the MT5 build, because the shared MT4 library this is built on does not carry it.

What it can't do

It draws two lines. No zones, no structure, no levels, no panel.

Six alerts on two lines derived from one series is a lot of alerts for the amount of independent information present. I would turn most of them off and keep the crossover.

The bgcolor option promises a trend-prediction background and is off by default. Leave it off; the colour on the classifier line already carries the same vote and does it more legibly.

You won't find a win rate table in this listing. The name says AI, and I have been deliberate above about what that does and does not mean here — putting a performance number underneath it would undo all of that.

Questions you'll have

Is it actually machine learning? It is a k-nearest-neighbour lookup, which is a textbook ML algorithm and also one that does no training. Both halves of that sentence are true and the second is the one people skip.

Why does the slow line start so far from price? RMA(50) warming up. Give it a few hundred bars of history.

What should I change first? TargetValue. Switching it to volatility changes which bars count as neighbours, and that is the most substantive setting here.

What timeframe? H1 and above. The neighbour window is only about 30 bars, so on M1 it is matching against half an hour of noise.

MT4 or MT5? Both, and your subscription covers both — see the notes above about Telegram and about the last bar.

Support

Message me through the site with a screenshot, 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.