I really like this study as it fits my main trading style. How do i remove the bubble with Break in it? I don't need that aspect and think it would be cleaner for me to remove.
Any help is appreciated!
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
https://creativecommons.org/licenses/by-nc-sa/4.0/
#// © LuxAlgo
#indicator("Trendlines With Breaks [LUX]",overlay=true)
# Converted and mod by Sam4Cok@Samer800 - 09/2022
input src = close; # Saource for slope calculation
input Showubble = yes;
input showConfirmedOnly = no;#(false,'Show Only Confirmed Breakouts')
input horizontalLine = no;
input wick = yes;
input method = {default ATR, Stdev, Linreg}; #('Atr','Slope Calculation Method'
input length = 14;
input SlopeStep = 1.0;#(1.,'Slope',minval=0,step=.1)
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;
def n = BarNumber();
def na = Double.NaN;
#==========================
# PIVOT SCRIPT
#==========================
script FindPivots {
input dat = high; # default data or study being evaluated
input HL = 0; # default high or low pivot designation, -1 low, +1 high
input PF = 14; # default pivot forward period
input PB = 14; # default pivot backward period
##############
def _nan; # used for non-number returns
def _BN; # the current barnumber
def _VStop; # confirms that the lookforward period continues the pivot trend
def _V; # the Value at the actual pivot point
def _VBar; # the bar number at the pivot point
def _PV; # the previous pivot Value
def _PVBar; # the previous pivot bar number
def _VDiff; # the difference in values between last two pivot points
def _VDist; # the diffence in barnumbers between last two pivot points
def _VSlope; # the Slope calculated using value and distance changes
def _VPivot; # used for the pivot point connector line only
##############
_BN = BarNumber();
_nan = Double.NaN;
_VStop =
fold a = 1 to PF + 1
with b = 1 while b
do if HL > 0 then
dat > GetValue(dat, -a) else
dat < GetValue(dat, -a) ;
if (HL > 0) {
_V = if _BN > PB and dat == Highest(dat, PB) and _VStop
then dat else _nan;
} else {
_V = if _BN > PB and dat == Lowest(dat, PB) and _VStop
then dat else _nan;
}
_VBar = if !IsNaN(_V) then _BN else _VBar[1];
_PV = if !IsNaN(_V) then GetValue(dat, _BN - _VBar[1]) else _PV[1];
_PVBar = if _VBar != _VBar[1]
then _PVBar[1] else _VBar;
_VDiff = AbsValue(_V) - AbsValue(_PV);
_VDist = _BN - _PVBar;
_VSlope = if _V > _PV then 1 else
if _V < _PV then -1 else 0;
if (HL > 0) {
_VPivot = _BN >= HighestAll(_PVBar);
} else {
_VPivot = _BN >= LowestAll(_PVBar);
}
plot result = if !IsNaN(_V) and _VStop then _V else _nan; #return the final _dat value at the most
}
switch (method) {
case ATR:
slope = ATR(length) / length * SlopeStep;
case Stdev:
slope = StDev(src, length) / length * SlopeStep;
case Linreg:
slope = AbsValue(Average(src*n, length) - Average(src,length) * Average(n, length)) /
sqr(StDev(n,length)) / 2 * SlopeStep;
}
#//----
def wickHi = if wick then high else if open>=close then open else close;
def wickLo = if wick then low else if open>=close then close else open;
def ph = findpivots(wickHi, 1, length, length);
def pl = findpivots(wickLo, -1, length, length);
slope_ph = if !IsNaN(ph) then slope else slope_ph[1];
slope_pl = if !IsNaN(pl) then slope else slope_pl[1];
upper = if(n<0) then na else if !IsNaN(ph) then ph else upper[1] - slope_ph;
lower = if(n<0) then na else if !IsNaN(pl) then pl else lower[1] + slope_pl;
#//----
def single_upper;
def single_lower;
single_upper = if (src[1] > upper) then 0 else
if !isNaN(ph) then 1 else single_upper[1];
single_lower = if (src[1] < lower) then 0 else
if !isNaN(pl) then 1 else single_lower[1];
def upper_breakout = single_upper[1] and src[1] > upper
and (if showConfirmedOnly then src > src[1] else 1);
def lower_breakout = single_lower[1] and src[1] < lower
and (if showConfirmedOnly then src < src[1] else 1);
def UpBreak = If(upper_breakout, low[1], na);
def LoBreak = If(lower_breakout, high[1], na);
def Labelup = UpBreak[-1];
def Labeldn = LoBreak[-1];
#//----
def UpPH = if IsNaN(close) then na else if IsNaN(ph[-1]) then upper else na;
def LoLH = if IsNaN(close) then na else if IsNaN(pl[-1]) then lower else na;
plot upperPH = if UpPH == 0 then na else UpPH;
upperPH.SetStyle(Curve.FIRM);
upperPH.SetDefaultColor(CreateColor(38, 166, 154));
plot upperDash = if IsNaN(UpPH) then upper else na;;
upperDash.SetStyle(Curve.MEDIUM_DASH);
upperDash.SetDefaultColor(CreateColor(38, 166, 154));
plot LowerLH = if LoLH == 0 then na else LoLH;
LowerLH.SetStyle(Curve.FIRM);
LowerLH.SetDefaultColor(CreateColor(239, 83, 80));
plot LowerDash = if IsNaN(LoLH) then lower else na;
LowerDash.SetStyle(Curve.MEDIUM_DASH);
LowerDash.SetDefaultColor(CreateColor(239, 83, 80));
#----------Horizontal Line---------------------------------
def LastPH = CompoundValue(1, if isNaN(ph) then LastPH[1] else ph, ph);
def LastPL = CompoundValue(1, if isNan(pl) then LastPL[1] else pl, pl);
#----
def UpPHline = if IsNaN(close) then na else if IsNaN(ph[-1]) then LastPH else na;
def LoLHline = if IsNaN(close) then na else if IsNaN(pl[-1]) then LastPL else na;
plot upperPHline = UpPHline;
upperPhline.SetHiding(!horizontalLine);
upperPHline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
upperPHline.SetDefaultColor(CreateColor(38, 166, 154));
plot upperDashline = if IsNaN(UpPHline) then LastPH else na;
upperDashline.SetHiding(!horizontalLine);
upperDashline.SetStyle(Curve.MEDIUM_DASH);
upperDashline.SetDefaultColor(CreateColor(38, 166, 154));
plot LowerLHline = LoLHline;
LowerLHline.SetHiding(!horizontalLine);
LowerLHline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowerLHline.SetDefaultColor(CreateColor(239, 83, 80));
plot LowerDashline = if IsNaN(LoLHline) then LastPL else na;
LowerDashline.SetHiding(!horizontalLine);
LowerDashline.SetStyle(Curve.MEDIUM_DASH);
LowerDashline.SetDefaultColor(CreateColor(239, 83, 80));