Nearest Percentile Moving Average Bands

Jan 16, 2022

Static chart image
Dynamic Overlays
Signals
Channels
Volatility

The Nearest Percentile Moving Average Bands indicator provides a dynamic volatility range by calculating upper and lower price boundaries based on nearest-rank percentile calculations over a specified lookback period.

Usage

The Usage section describes how the script can be used to identify breakouts and trend strength. By mapping the price distribution over a set period, the indicator helps traders visualize when the market is entering extreme territory.

  • Trend Identification: The middle line represents the 50th percentile (median). When the price is above the median and the bands are sloping upward, the market is in a bullish regime. Conversely, price action below the median suggests a bearish regime.
  • Volatility Breakouts: The upper and lower bands highlight the "tails" of the price distribution. A price move above the upper band (e.g., the 99th percentile) indicates a significant bullish breakout, signaling that the market is leaving its normal trading range.
  • Mean Reversion: If the price remains at extreme percentile levels for an extended period, it may indicate an overextended market, suggesting a high probability of a correction toward the median.
  • Visual Cues: The bands change thickness or color intensity based on expansion. If the upper band is rising, it highlights expanding bullish momentum; if the lower band is falling, it highlights expanding bearish momentum.

Details

The script utilizes the ta.percentile_nearest_rank function to determine price levels at specific statistical ranks. Unlike a standard moving average which calculates an arithmetic mean, this method identifies the specific price point that satisfies the percentile requirement within the lookback window.

The indicator calculates a "Middle" line at the 50% rank. The "Up" and "Down" bands are calculated symmetrically based on the user-defined percentile input. For example, if the input is set to 80%, the upper band displays the 80th percentile, while the lower band automatically calculates the 20th percentile (50 - |80 - 50|). The displacement setting allows the entire array of bands to be shifted forward in time, which can help in reducing noise or aligning with specific cycle offsets.

Settings

  • NPMA Length: The number of bars used to calculate the price distribution and percentile ranks.
  • NPMA Percentile: Determines the sensitivity of the outer bands. Higher values move the bands further from the median, capturing only extreme price movements.
  • Displacement: Shifts the plots forward on the horizontal axis by a specified number of bars.

FAQ

How do I interpret the colored highlights on the bands?
The bands become highlighted when they are expanding away from the median. A highlighted green upper band indicates the upper price boundary is moving higher, while a highlighted red lower band indicates the lower price boundary is moving lower.

What is the benefit of using percentiles over standard Bollinger Bands?
Standard deviation-based bands (like Bollinger Bands) assume a normal distribution of price data. Percentile-based bands do not make this assumption and instead use the actual distribution of historical prices, making them more adaptive to non-linear market moves and "fat-tail" events.

How can I access this indicator?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free access on the following platforms
tradingviewSymbolTradingView
ninjatraderNinjaTrader
metatrader4MetaTrader 4/5
thinkorswimThinkorswim

Unlock Unlimited Access to the LuxAlgo Library

Upgrade your plan to get all indicators, strategies, charts, and full access to Quant, our AI agent.

Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.

Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.

As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.

Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.

Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.

This does not represent our full Disclaimer. Please read our full disclaimer.

© 2026 LuxAlgo Global, LLC.