I added alert to be shows on the indicator.
Message from the author:
The RedK Chop & Breakout Scout (C&BS or just CBS) is a centered oscillator that helps traders identify when the price is in a chop zone, where it's recommended to avoid trading or exit existing trades - and helps identify (good & tradeable) price breakouts.
This concept is similar to a Stochastic Oscillator - with the main difference being that we're utilizing units of ATR (instead of a channel width) to calculate the main indicator line - which will then lead to a non-restricted oscillator (rather than a +/- 100%) - given that ATR changes with the underlying and the timeframe, among other variables.
https://www.tradingview.com/script/jnWK8gZg-RedK-Chop-Breakout-Scout-C-B-Scout/
CODE BELOW
CSS:
#// © RedKTrader
#// plots a centered oscillator based on how many ATR units the source price is from a price baseline (could be a Donchian midline or another slow MA)
#// the Chop Zone is detected when the price is within a customizable ATR-based distance above or below the baseline
#// a filter is then applied (using EMA - but can be other types of long-term MA) to indicate the preferred trade direction (long vs. short)
#// when the CBS line is inside the chop zone, trading is not recommended for the conservative trader
#// Breakouts are found when the CBS line exits the Chop zone (in agreement with the filter direction)
#// An aggressive swing trader can consider positions when the CBS line crosses the 0 line in the filter direction
#indicator('RedK Chop & Breakout Scout ', shorttitle='C&B_Scout v2.0'
#https://www.tradingview.com/script/jnWK8gZg-RedK-Chop-Breakout-Scout-C-B-Scout/
# Converted and mod by Sam4Cok@Samer800 - 08/2022
#// ATR Calclatioin Function
#// ==============================================================================================
script nz {
input data = 0;
input replacement = 0;
def ret_val = if IsNaN(data) then replacement else data;
plot return = ret_val;
}
# RMA(src, length)=>
script RMA {
input src = close;
input length = 14;
def alpha = 1 / length;
def sum;
sum = if IsNaN(sum[1]) then SimpleMovingAvg(src, length) else alpha * src + (1 - alpha) * nz(sum[1]);
plot Return = sum;
}
#ATR_Calc(_price, _length, _atrcalc) =>
script ATR_Calc {
input _price = close;
input _length = 0;
input _atrcalc = "RMA";
def ATR_Calc = if _atrcalc == "RMA" then RMA(_price, _length) else
if _atrcalc == "SMA" then SimpleMovingAvg(_price, _length) else
if _atrcalc == "EMA" then ExpAverage(_price, _length) else
WMA(_price, _length);
plot return = ATR_Calc;
}
#=================================================================================================
# Inputs
#=================================================================================================
input Src = close; # Price
input BaselineLength = 10; # Baseline Length
input AtrLength = 10; # ATR Avg Length
input MAType = {default "RMA", "SMA", "EMA", "WMA"}; # MA Calculation
input ChopLevel = 0.5; # Chop Level
input smooth = 3; # Smooth
input EMAFilter = 20; # EMA Filter
input ShowAlert = yes;
#=================================================================================================
# Calculations
#=================================================================================================
declare lower;
def na = Double.NaN;
#//calculate baseline price - added other slow MA's
def baseline = (Highest(high, BaselineLength) + Lowest(low, BaselineLength)) / 2;
#// Calculate ATR
def tr = if IsNaN(close[1]) then high - low else
Max(Max(high - low, AbsValue(high - close[1])), AbsValue(low - close[1]));
def ATR = ATR_Calc(tr, BaselineLength, MAType);
#// CBS value is basically how far is current price from the baseline in terms of "ATR units"
def cbs = (Src - baseline) / ATR;
def scbs1 = WMA(cbs, smooth);
def scbs = WMA(scbs1, smooth);
#// check where is price wrt the filter line to determine recommended trading direction
#// in v1, we use an EMA-based filter as it's most popular -- may add other MA types in future.
def f_modelong1 = Src > ExpAverage(Src, EMAFilter);
def f_modelong = f_modelong1;
# =================================================================================================
# Plots
# =================================================================================================
plot zeroLine = 0; # Zero Line
zeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
zeroLine.SetDefaultColor(Color.GRAY);
def h0 = ChopLevel; # "Chop Zone - Upper"
def h1 = -ChopLevel; # "Chop Zone - Lower"
AddChart(high = if f_modelong then h0 else na,
low = if f_modelong then h1 else na,
open = if f_modelong then h0 else na,
close = if f_modelong then h1 else na,
type = ChartType.CANDLE, growcolor = CreateColor(0,100,0));
AddChart(high = if !f_modelong then h0 else na,
low = if !f_modelong then h1 else na,
open = if !f_modelong then h0 else na,
close = if !f_modelong then h1 else na,
type = ChartType.CANDLE, growcolor =CreateColor(100,0,0));
plot CBSSmooth = scbs; # "CBS Smooth"
CBSSmooth.AssignValueColor(if f_modelong and cbs > ChopLevel then CreateColor(41,98,255) else
if !f_modelong and cbs < -ChopLevel then CreateColor(242,54,69) else Color.WHITE);
CBSSmooth.SetLineWeight(3);
#====================================================================================
# Alerts
#====================================================================================
plot up = if ShowAlert and f_modelong and (cbs crosses above ChopLevel) and scbs > scbs[1] then ChopLevel else na;
plot dn = if ShowAlert and !f_modelong and (cbs crosses below -ChopLevel) and scbs < scbs[1] then -ChopLevel else na;
up.SetPaintingStrategy(PaintingStrategy.SQUARES);
up.SetDefaultColor(Color.GREEN);
up.SetLineWeight(2);
dn.SetPaintingStrategy(PaintingStrategy.SQUARES);
dn.SetDefaultColor(Color.RED);
dn.SetLineWeight(2);
### END
Last edited by a moderator: