Indicator · Pine Script v5 · On the chart

Consolidation Filter

by capissimo

Consolidation Filter identifies market indecision and sideways ranges characterized by low volatility.

View on GitHub

Repaints

GitHub stars114on the repository
Pine versionv5runs as is
Lines of code52
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago7 Nov 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

52 lines of Pine Script v5 from scripts/133-Consolidation-Filter.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

133-Consolidation-Filter.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capissimo

//@version=5
indicator("Consolidation Filter", '', true, format=format.price, precision=2, timeframe="", timeframe_gaps=true)

//-- Description

// This script offers a fairly straightforward but effective indicator/filter of 
// indecision (consolidation) periods. A period of consolidation is characterized 
// by low volatility and uncertainty as to which way the market will go next. 
// During such periods it is better to refrain from opening positions or be 
// especially careful if a position is already open.

// This script can be used either as an overlay to the signal generator script or 
// as a subprogram in the main script. Indecision periods are highlighted with a 
// yellow background. In the settings menu you can select one of three calculation 
// methods, but all of them are based on the forecast oscillator. 

// The indicator settings depend on the asset and on the timeframe. 
// For example in BTSUSD/2H = 10/2/0.2, and in BTSUSD/15M = 10/2/0.02 

//-- Inputs

Window         = input.int   (10,    "Period", 2,  inline='cons',           group="Indecision Periods")  
IndecisionBool = input.bool  (true,  "",           inline='cons',           group="Indecision Periods")  
Method         = input.int   (2,     "Method [1..3]", 1, 3,                 group="Indecision Periods")  
Threshold      = input.float (0.02,  "Threshold [0.0..10.0]", 0, 10, 0.001, group="Indecision Periods")  

//-- Methods

method max(float data) => ta.max(data)
method ema(float data, int p)           => ta.ema(data, p) 
method mg(float data, simple int p=5) =>
    float mg = 0.0
    mg := na(mg[1]) ? data.ema(p) : mg[1] + (data - mg[1]) / (p * math.pow(data/mg[1], 4))

//-- Logic

float dataset = close[barstate.isrealtime ? 1 : 0] 

float ma  = dataset.ema(Window)  
float out = switch Method  // selects a version of forecast oscilltor 
    1 => 100 * (dataset - ma) / dataset 
    2 => 100 * (dataset - ma) / dataset.max()  
    3 => 100 * (dataset - dataset.mg(Window)) / dataset

bool within = out <= Threshold and out >= -Threshold

//-- Visuals

plot(IndecisionBool ? ma : na, "Consolidtion", within ? color.new(color.yellow, 30) : na, 20)

Overview

Consolidation Filter computes a forecast oscillator variant comparing price against an exponential moving average or a McGinley dynamic across three selectable methods. When the oscillator value remains within a defined threshold band around zero, the script flags consolidation by plotting a thick yellow overlay on the price chart. Users can adjust the lookback window, formula method, and threshold. The calculation uses the previous bar on realtime ticks and current close on historical bars.

Details

Published by

capissimo on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Periodint10Window
IndecisionBoolbooltrueIndecisionBool
Method [1..3]int2Method
Threshold [0.0..10.0]float0.02Threshold
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Hampel Filter

by everget
948 stars

The Hampel Filter indicator identifies and filters out price outliers to smooth price data directly on the main chart. It calculates the rolling median and Median Absolute Deviation (MAD) of the chosen source series over a specified length. When a data point e

Indicator v4 Moving averagesVolatility & bands
Updated 10 days ago · GPL-3.0 GitHub repository of Hampel Filter

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

Algo AVT

by ricardosantos79
261 stars

This indicator calculates an outlier-filtered moving average based on statistical filtering concepts. It stores close prices in a rolling array over a user-defined length, calculates the mean and standard deviation, and excludes values falling within a specifi

Indicator v4 Moving averagesVolatility & bands
Updated 4 years ago · None stated GitHub repository of Algo AVT

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers