All indicators

Flat Detect By Bollinger Bands

Feb 23, 2022

Static chart image
Moving AveragesVolatility

The Flat Detect By Bollinger Bands indicator identifies periods of low market volatility, commonly referred to as "flat" zones, by monitoring the width of the Bollinger Bands. This tool helps traders avoid choppy price action by visually highlighting when the distance between bands falls below a user-defined threshold.

Usage

The tool is primarily used as a market state filter. When the Bollinger Bands appear in red with a red background fill, the market is identified as flat, suggesting a lack of significant trend or momentum. When the bands turn green, it indicates that volatility has expanded beyond the specified threshold, potentially signaling the start of a trend or a period suitable for standard trading strategies.

Traders can utilize this script to:

  • Filter out trend-following signals during consolidation phases.
  • Identify potential "squeeze" scenarios where low volatility often precedes a breakout.
  • Combine with the optional ATR filter to ensure market activity meets a minimum intensity before considering the market "active."

Details

The script calculates the standard Bollinger Bands (Basis, Upper, and Lower). The core logic determines the "flatness" of the market by comparing the Bollinger Band Width (BBW) against a threshold.

The indicator offers two methods for threshold calculation:

  1. Ticks: Uses the raw BBW value (Upper - Lower) divided by the Basis.
  2. Percentage: Calculates the width as a percentage of the Upper Band.

Additionally, an optional ATR (Average True Range) filter is included. If enabled, the market will only be considered "active" (green) if the ATR value is above the specified ATR threshold, providing an extra layer of confirmation against low-volatility price action.

Settings

Bollinger Bands Config

  • Length: The lookback period for the Bollinger Bands calculation (default is 20).
  • Source: The price data used for the calculation (default is close).
  • StdDev: The standard deviation multiplier for the bands.
  • Threshold Type: Choose between "Ticks" or "%" for the width detection logic.
  • Threshold Width in Ticks: The manual threshold used when "Ticks" is selected.
  • Threshold Width in %: The manual threshold used when "%" is selected.

ATR Config

  • Add ATR Filter: Toggles the secondary ATR-based volatility filter.
  • Length: The lookback period for the ATR calculation.
  • Smoothing: The moving average type used for ATR (RMA, SMA, EMA, or WMA).
  • ATR Threshold: The minimum ATR value required for the market to be considered non-flat.

FAQ

How do I use the Flat Detect By Bollinger Bands?

You can use it to color-code your chart to avoid trading during consolidation. Red bands suggest a flat market, while green bands suggest sufficient volatility for trending moves.

Can I adjust the sensitivity of the flat detection?

Yes, you can adjust the "Threshold Width" settings. Increasing the threshold will make the indicator more sensitive, marking more zones as "flat."

Where can I access this tool?

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

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.