#Created 03/20/2021 by Christopher84 in colaboration with Xeonox and SleepZ
declare weak_volume_dependency;
input price = close;
input ATR_length = 15;
input SMA_length = 6;
input displace = 0;
input multiplier_factor = 1.5;
def val = Average(price, sma_length);
def average_true_range = Average(TrueRange(high, close, low), length = atr_length);
plot Upper_Band = val[-displace] + multiplier_factor * average_true_range[-displace];
Upper_Band.SetStyle(Curve.SHORT_DASH);
Upper_Band.SetLineWeight(2);
Upper_Band.SetDefaultColor(Color.Gray);
plot Middle_Band = val[-displace];
Middle_Band.SetStyle(Curve.SHORT_DASH);
Middle_Band.SetLineWeight(2);
Middle_Band.SetDefaultColor(Color.Gray);
plot Lower_Band = val[-displace] - multiplier_factor * average_true_range[-displace];
Lower_Band.SetStyle(Curve.SHORT_DASH);
Lower_Band.SetLineWeight(2);
Lower_Band.SetDefaultColor(Color.Gray);
#Plotting STARC slope into extension area
#input Extension_length = 20
input extension_length_limited_to = 50;
def lastbar = if isnan(close[-1]) and !isnan(close) then barnumber() else double.nan;
def inertline = inertiaall(Upper_Band,2);
def EXT_Upper_Band = if !IsNaN(close()) then inertline else EXT_Upper_Band[1] + ((EXT_Upper_Band[1] - EXT_Upper_Band[2]) / (2 - 1));
plot extension = if barnumber()<=highestall(lastbar)+ extension_length_limited_to then EXT_Upper_Band else double.nan;
extension.SetStyle(Curve.SHORT_DASH);
extension.SetLineWeight(2);
extension.SetDefaultColor(Color.white);
def inertline2 = inertiaall(Lower_Band,2);
def EXT_Lower_Band = if !IsNaN(close()) then inertline2 else EXT_Lower_Band[1] + ((EXT_Lower_Band[1] - EXT_Lower_Band[2]) / (2 - 1));
plot extension2 = if barnumber()<=highestall(lastbar)+ extension_length_limited_to then EXT_Lower_Band else double.nan;
extension2.SetStyle(Curve.SHORT_DASH);
extension2.SetLineWeight(2);
extension2.SetDefaultColor(Color.white);
def cross = if extension crosses extension2 then barnumber() else double.nan;
plot x = if barnumber()==highestall(cross) then extension else double.nan;
x.setpaintingStrategy(PaintingStrategy.ARROW_UP);
addchartbubble(barnumber()==highestall(cross), highestall(x), round(highestall(x)),color.white);