Code:
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);
def Middle_Band = val[-displace];
#Middle_Band.SetDefaultColor(GetColor(1));
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);
AddLabel (yes, "TEST " + (cross) );
AddLabel (yes, "Cross " + (highestall(x)) );
nice work SleepyZ, i battled that for like 30 mins going crazy trying to figure it out, i used double.nan too but was strange the label wouldnt record the number.
even with your code Cross wont return the bar number on a label as the example above. thats strange, thats what had me stumped, i still dont understand why it doesnt. but i guess if the code is properly coded and finished like you did it then the final code works. thats strange. im baffled as to why cross doesnt return barnumber value in
AddLabel (yes, "TEST " + (cross) );
yet it still works correctly for final code.
all my previous codings for getting barnumber always returns a value in the label when testing if i have it coded right....this is coded right but the bar number value doesnt show, super strange.