Indicator · Pine Script v5 · Own pane

Chop and Explode

by capissimo

This indicator measures market consolidation and breakout phases by computing a scaled Relative Strength Index (RSI) on normalized price data.

View on GitHub

GitHub stars114on the repository
Pine versionv5runs as is
Lines of code143
Settings9inputs
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

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

131-Chop-and-explode-(ps5-v.2).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 v.2)', 'ChopExp-2', 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)
LABELS = input.bool  (true,  'Labels',   inline='b')

SRI    = input.bool  (false, 'SRI',      inline='b')
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    

//-- Constants

var int BUY   = 1
var int SELL  =-1
var int CLEAR = 0

//-- Variables

var int signal = CLEAR

//-- 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 
bool clear    = not(long and short)  // ADDED!

signal := long ? BUY : short ? SELL : clear ? CLEAR : nz(signal[1])  // MODIFIED!

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

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(LABELS and startedLong,  'Long',  shape.labelup,   location.bottom, color.blue, 0, size=size.tiny)
plotshape(LABELS and startedShort, 'Short', shape.labeldown, location.top,    color.red,  0, size=size.tiny)

//-- Notification

if changed and signal==BUY 
    alert('Buy Alert', alert.freq_once_per_bar)  // alert.freq_once_per_bar_close
if changed and signal==SELL 
    alert('Sell Alert', alert.freq_once_per_bar)

alertcondition(startedLong,  'Buy',  'Go long!')
alertcondition(startedShort, 'Sell', 'Go short!') 
//alertcondition(startedLong or startedShort, 'Alert', 'Deal Time!')

Overview

Chop and Explode identifies chop zones when the RSI oscillates between 40 and 60, highlighting tight consolidation between 45 and 55. An upside explosion is signaled when the RSI crosses above 60, while a downward move triggers below 40. Users can enable a data-cleaning high-pass filter, adjust minimax scaling, and configure an optional Seasonal Random Index. The script plots in a separate pane with directional signals and color-coded bars.

Details

Published by

capissimo on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands, Breakout

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
LabelsbooltrueLABELS
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

Squeeze Momentum

by mihakralj
99 stars

This indicator plots Squeeze Momentum in a separate pane. It compares Bollinger Bands with a Keltner Channel to mark a squeeze when the bands sit inside the channel. Momentum is a linear regression of price relative to a Donchian midline and an SMA, shown as a

Indicator v6 Volatility & bandsOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Squeeze Momentum

Renko Acceleration

by f-cksociety
11 stars

Calculates the time elapsed between consecutive bars to measure market speed and volatility, designed primarily for Renko chart blocks where bar duration varies. In Momentum mode, it contrasts the current duration against a 100-period moving average baseline,

Indicator v4 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of Renko Acceleration

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

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

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