Indicator · Pine Script v5 · Own pane

Chop and Explode

by techteam92· code credited to capissimo

This indicator identifies consolidation zones and potential breakout moves by processing price data through optional high-pass cleaning, minimax scaling, and RSI calculation.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code130
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago20 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

130 lines of Pine Script v5 from scripts/129-Chop-and-explode-(ps5).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

129-Chop-and-explode-(ps5).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capissimo

//@version=5
indicator('Chop and explode (ps5)', '', false)

// Description: 
// This is a renovated version of my previous mod that was based on the original script from fhenry0331.

// Added are:
// - a data cleaning function
// - a seasonal random index function
// - an updated scaler and 
// - a signalling procedure.

// The following description is moved here from the old script.

// The purpose of this script is to decipher chop zones from runs/movement/explosion spans. 
// The chop is RSI movement between 40 and 60. Tight chop is RSI movement between 45 and 55. 
// There should be an explosion after RSI breaks through 60 (long) or 40 (short). 
// Tight chop bars are colored gray, a series of gray bars indicates a tight consolidation and 
// should explode imminently. The longer the chop the longer the explosion will go for. 
// The tighter the better. Loose chop (jig saw/gray bars on the silver background) will range 
// between 40 and 60. The move begins with green and red bars. 
// Couple it with your trading system to help stay out of chop and enter when there is a movement. 

//-- Inputs

BASE = input.source(close, 'Dataset',  inline='data')
CLN  = input.bool  (false, 'Clean It', inline='data')
LAG  = input.int   (10,    'Lookback [2..n]', 2)
MMX  = input.int   (20,    'Minimax [2..n]',  2)

//-- Constants

var int BUY  = +1
var int SELL = -1
var int HOLD =  0

//-- Variables

var int signal = HOLD

//-- Functions

clean(data) =>  
    pi = 2 * math.asin(1)
    hpPeriod = .00001  
    alpha = (1 - math.sin(2 * pi / hpPeriod)) / math.cos(2 * pi / hpPeriod)
    hp = 0.0
    hp := bar_index <= 5 ? data : (0.5 * (1 + alpha) * (data - data[1])) + (alpha * hp[1])
    res = bar_index <= 5 ? data : (hp + (2 * hp[1]) + (3 * hp[2]) + (3 * hp[3]) + (2 * hp[4]) + hp[5]) / 12
    res

minimax(X, p, min, max) => 
    hi = ta.highest(X, p), lo = ta.lowest(X, p)
    (max - min) * (X - lo)/(hi - lo) + min

norm(x, p) => (x - ta.lowest(x, p)) / (ta.highest(x, p) - ta.lowest(x, p))

green(g) => g>9 ? #006400 : g>8 ? #1A741A : g>7 ? #338333 : g>6 ? #4D934D : g>5 ? #66A266 : g>4 ? #80B280 : g>3 ? #99C199 : g>2 ? #B3D1B3 : g>1?  #CCE0CC : #E6F0E6
red(g)   => g>9 ? #E00000 : g>8 ? #E31A1A : g>7 ? #E63333 : g>6 ? #E94D4D : g>5 ? #EC6666 : g>4 ? #F08080 : g>3 ? #F39999 : g>2 ? #F6B3B3 : g>1?  #F9CCCC : #FCE6E6

//-- Logic

float cleaned = CLN ? clean(BASE) : BASE
float data    = minimax(cleaned, MMX, 1, 100)  // In general, the best solution lies in scaling the price
float up      = ta.rma(+math.max(ta.change(data), 0), LAG)
float down    = ta.rma(-math.min(ta.change(data), 0), LAG)
float rsi     = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

bool long     = rsi > 60
bool short    = rsi < 40 

signal := long ? BUY : short ? SELL : nz(signal[1])

changed = ta.change(signal)

bool startedLong  = changed and signal==BUY
bool endedLong    = changed and signal==SELL
bool startedShort = changed and signal==SELL
bool endedShort   = changed and signal==BUY

color long_range  = long  ? green(8) : na
color short_range = short ? red(8)   : na

//== Dynamic Seasonal Random Index

SRI    = input.bool (false, 'SRI')
minlen = input.int  (5,     'Season',         1,      group='Seasonal Random Index')
maxlen = input.int  (50,    'Lookback',       1,      group='Seasonal Random Index')
pct    = input.float(10.,   'Adaptation (%)', 0, 100, group='Seasonal Random Index') / 100.0    

dlen = math.avg(minlen, maxlen)   //-- dynamic len
dlen := ta.atr(10) > ta.atr(40) ? math.max(minlen, dlen * (1 - pct)) : math.min(maxlen, dlen * (1 + pct))
d = int(dlen[0])

sri = cleaned * (cleaned / ( (cleaned + cleaned[minlen]) / 2 ))  //-- Seasonal random index

seasoned   = norm(sri, d) * 100
deseasoned = norm(cleaned - sri, d) * 100
avs        = math.avg(seasoned, deseasoned)
cross      = ta.cross(seasoned, deseasoned)

//-- Visuals

plot(0,   '', na), plot(100, '', na)  //-- dummies

hline(50, '', color.silver, hline.style_dotted)
l1 = hline(70, '', color.silver, hline.style_dotted)
l2 = hline(30, '', color.silver, hline.style_dotted)
l3 = hline(60, '', color.new(color.silver, 100), hline.style_dotted)
l4 = hline(40, '', color.new(color.silver, 100), hline.style_dotted)
l5 = hline(55, '', color.new(color.silver, 100), hline.style_dotted)
l6 = hline(45, '', color.new(color.silver, 100), hline.style_dotted)
fill(l1, l3, color.new(color.green,  60))
fill(l3, l4, color.new(color.silver, 95))
fill(l4, l2, color.new(color.red,    60))
fill(l5, l6, color.new(color.silver, 80))

fill(plot(SRI ? seasoned : na, '', color.new(color.blue,100)), 
     plot(SRI ? deseasoned : na, '', color.new(color.blue,100)), color.new(seasoned > deseasoned ? green(4) : red(4), 50))
plot(SRI ? avs : na, '', color.silver)
plot(SRI and cross ? avs : na, '', color.black, 1, plot.style_circles)

plot(rsi, '', color.black)
plot(rsi, '', long_range,  3, plot.style_linebr)
plot(rsi, '', short_range, 3, plot.style_linebr)
plotshape(startedLong,  'Long',  shape.labelup,   location.bottom, color.blue, 0, size=size.tiny)
plotshape(startedShort, 'Short', shape.labeldown, location.top,    color.red,  0, size=size.tiny)

Overview

Relative strength values between 40 and 60 represent ranging or chop zones, while crossings above 60 or below 40 signal bullish or bearish trend explosions. Drawn in a separate pane, the indicator displays visual color intensity based on move strength. Settings allow adjusting lookback lengths, data filtering, and scaling parameters.

Details

Published by

techteam92 on GitHub

Code credit

capissimo, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
DatasetsourcecloseBASE
Clean ItboolfalseCLN
Lookback [2..n]int10LAG
Minimax [2..n]int20MMX
SRIboolfalseSRI
Seasonint5minlen
Lookbackint50maxlen
Adaptation (%)float10.pct
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

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

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