Machine Learning Momentum Oscillator (MLMO): A kNN Momentum Guide
How Sahi's ML Momentum Oscillator uses k-Nearest Neighbours to read momentum, and how to trade its candles and range extremes.
Quick Answer
The Machine Learning Momentum Oscillator (MLMO) uses a k-Nearest Neighbours (kNN) algorithm to read momentum. In a pane below price it draws green candles when the raw prediction is above its smoothed version (bullish) and red candles when it is at or below (bearish), inside a dynamic range bounded by a BIG ceiling and a small floor. Trade sustained runs of same-colour candles pressing toward BIG (long) or small (short) — not single candles. It is free on Sahi, with no subscription required.
Overview
Machine Learning Momentum Oscillator uses a k-Nearest Neighbours (kNN) algorithm to read momentum. At each bar it computes two momentum signals — a faster "bear" signal and a slower "bull" signal — and then finds the N most similar past bars from the entire chart history. It votes those neighbours' directions together into a single prediction value. The result is an oscillator that adapts its shape to the data it has seen rather than using a fixed formula, which means it smooths out random noise while staying responsive to real momentum shifts.
In the separate pane below the chart the indicator draws a column of candles made from its raw prediction and a smoothed version of that prediction. The background of the oscillator is a gradient that shifts from red near the top of the historical range to blue near the bottom. When the optional prediction lines are turned on, two additional line-and-band overlays (amber and cyan) appear inside the pane.
How to Read the Indicator
The Oscillator Candles (main visual)
The indicator draws candles in the oscillator pane rather than a plain line. Each candle's open and high are the raw ML prediction value; its close and low are the smoothed version of that prediction.
- Green candles appear when the raw prediction is above its smooth. This means the ML engine currently favours bullish momentum and is accelerating upward from its smoothed base.
- Red candles appear when the raw prediction is at or below its smooth. The ML engine is favouring bearish momentum or decelerating.
The gradient intensity tracks where the current prediction sits in the full historical range — a brighter shade means the reading is more extreme relative to everything seen before on that chart.
The Dynamic Floor and Ceiling (BIG / small lines)
Two faint white lines run across the pane: the upper one marks BIG (the all-time highest smoothed prediction on that chart) and the lower one marks small (the all-time lowest). These lines move outward over time as the chart history grows. Think of them as dynamic overbought and oversold boundaries — when candles press up near BIG the oscillator is at a historically stretched bullish extreme; when they press down near small, momentum is at a historically stretched bearish extreme.
The Background Gradient Fill
The entire space between the BIG and small lines is filled with a gradient that is red at the top and blue at the bottom. This background is purely visual context — it lets you see at a glance how high or low the current candle sits inside the historical range without reading numbers.
Faint white buffer fills appear just above BIG and just below small. These indicate the padding zone beyond the historical extremes and have no trading meaning.
The Amber Flat-Line Fill (prediction = smoothed marker)
When the raw prediction equals its smoothed value exactly — a momentary equilibrium — an amber/golden fill appears between the two. This is rare and brief; treat it as a "pause at decision point" signal rather than a directional cue on its own.
Prediction Lines (optional, off by default)
When Show prediction lines is turned on, two sets of line-and-band overlays appear inside the oscillator pane:
- Amber lines + amber band (colour #efb906): the Bull Period momentum signal (Prime1) with a channel showing how far price could move within its ATR-derived band. When this line is rising and the band is wide, the bullish momentum input to the kNN is strong.
- Cyan lines + teal band (colour #08d3ed): the Bear Period momentum signal (Prime2) with its own channel. When this line is falling and the band is expanding, the bearish input is dominant.
The relative position of the amber line above or below the cyan line is the clearest thing to watch when prediction lines are on — amber above cyan is the same condition that produces green candles.
Example Scenarios
Scenario 1 — Green candles pressing toward BIG, buy a CE (bullish)
Nifty is consolidating around 24,920 after a morning dip. The MLMO pane shows a sequence of three green candles that have climbed from mid-range to within touching distance of the BIG ceiling. Each candle's close (smoothed value) is higher than the previous bar's close, confirming the ML vote is building bullish momentum — not just spiking for one bar.
- What you do: buy 1 lot of Nifty 25,000 CE at a premium of about ₹105.
- Stop loss: if the next candle turns red and closes back below the midpoint between BIG and small, the bullish read is reversing — exit. The premium would be around ₹68 there.
- Target: Nifty moves toward 25,080 as the oscillator continues to print green; the CE premium would be roughly ₹160.
- Why it works: three consecutive green candles near the top of the ML range means the kNN engine has strong historical agreement that this momentum pattern is bullish, not just a one-bar blip.
Scenario 2 — Red candles pressing toward small, buy a PE (bearish)
Nifty is trading around 25,050 and rolling over from a morning high. The MLMO pane shows four red candles in a row that have dropped from above mid-range to near the small (floor) line. The candles are dark red (deep gradient), meaning the prediction is close to a historical bearish extreme relative to all prior data on the chart.
- What you do: buy 1 lot of Nifty 25,000 PE at a premium of about ₹95.
- Stop loss: if a candle turns green and closes back above the range midpoint, the bearish vote has flipped — exit. The premium would be about ₹60 there.
- Target: Nifty falls to 24,870; the PE premium would be roughly ₹150.
- Why it works: red candles pressing into the historical floor mean the kNN found the most bearish momentum cluster it has seen on this chart, giving the move statistical weight beyond a simple indicator crossover.
Scenario 3 — What to avoid
- Do not act on a single red or green candle. One candle is one vote. The kNN signal is meaningful when it sustains direction — two or more consecutive same-colour candles in the same zone. A lone candle switching colour and switching back is noise, not a signal.
- Do not trade when the candle is floating in the middle of the range. When the prediction sits between 40% and 60% of the BIG–small range (neither near the top nor near the bottom), the ML engine has no strong historical agreement in either direction. Wait for the candles to press convincingly toward BIG or small before committing.
- Be cautious right after the chart is opened or the timeframe is changed. The kNN needs a sufficient history of bars to build a meaningful neighbour pool. On a freshly loaded chart or a very high timeframe with few bars, the BIG and small lines will be close together and the gradient compressed — signals in this state can be unreliable until the historical pool grows.
- Do not rely on the amber flat-line fill alone. The golden equilibrium fill appears for only a bar or two and does not indicate direction. It tells you the engine is pausing, not that it is reversing.
Settings Panel Guide
ML Core Settings
- Bear Period: the EMA length used to compute the faster (short-period) momentum input. Default is 26. A larger number makes this input slower and smoother; a smaller number makes it more reactive. For Nifty intraday on 5-minute charts, the default of 26 works well. Lowering to 18–20 adds sensitivity but can generate noisier candle colour flips.
- Bull Period: the EMA length used to compute the slower (long-period) momentum input. Default is 14. Despite being labelled "bull," this controls the longer signal; the two periods are named for which directional outcome they primarily feed in the original algorithm. Keep the Bull Period lower than the Bear Period for the default relationship to hold.
- Smoothing Period: applied twice — once to smooth each raw momentum input and once to produce the smoothed prediction line that forms the candle close/low. Default is 13. Increasing it (e.g. to 20–21) produces a calmer, slower oscillator with fewer colour flips; decreasing it (e.g. to 8) makes the candles more reactive but noisier. For BankNifty intraday, try 8–10 to keep up with its faster swings.
- Neighbours Count: how many of the nearest historical bars the kNN algorithm uses to cast its vote. Default is 50. More neighbours (e.g. 80–100) produce a more conservative, consensus-driven prediction that changes direction slowly; fewer neighbours (e.g. 20–30) make the oscillator quicker but more susceptible to false flips. On volatile days, a higher count filters out single-session outliers better.
Display
- Show prediction lines: toggle on to reveal the amber (Bull Period) and cyan (Bear Period) momentum lines with their ATR-derived channel fills inside the oscillator pane. Default is off. Turn on when you want to see which of the two momentum inputs is dominant or how wide the current volatility band is. Turn off for a cleaner pane if you only need the candle direction.