Skip to content
All library documents

A k-Nearest Neighbors Price Smoother and Next-Bar Direction Signal

Article TradingView scripts

Summary

This indicator adapts a simple k-nearest-neighbors idea to a price series. It compares adjacent observations across a configurable window using absolute price differences, selects values according to a distance-based rule, and averages the resulting neighbors to produce a smoothed curve. The curve’s relationship to a current or prior price is used to infer a possible next-bar direction. Optional coloring can use ordinary direction, recent pivot highs and lows, or a z-score condition; users can also select a chart resolution and a non-repainting setting.

The author says a modified version can resemble a simple moving average and provide a directional hint, but the document gives no measured forecast accuracy or trading performance. Its input is raw prices rather than a richer feature set, and selecting the neighbor count is difficult. The implementation’s neighbor selection is modified for smoothing, so it should be understood as an indicator experiment rather than evidence that kNN predicts future prices reliably.

Key ideas

  • The indicator uses absolute differences between neighboring prices to construct a distance-based selection.
  • It averages selected price values to form a smoothed curve and compares that estimate with price for a directional hint.
  • Color options add direction filters based on pivots or standardized price readings.
  • The author reports that a modified configuration can resemble a simple moving average, without presenting performance evidence.
  • The method uses a narrow raw-price input and depends on a difficult-to-choose neighbor parameter.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.