Repaints Trendlines With Breaks [LUX] For ThinkOrSwim

Repaints
V2.0 alerts added to the Orginal thread. check it out.
This is fantastic, how real time is this ?

Does this repaint ?
how about the trendlines? I tried ondemand and they seem to be lagging a lot. on demand has its delays too. wondering if trendlines are also delayed.?
 
Last edited by a moderator:
This is fantastic, how real time is this ?

Does this repaint ?
how about the trendlines? I tried ondemand and they seem to be lagging a lot. on demand has its delays too. wondering if trendlines are also delayed.?
Yes, there is repainting lag with all calculations, including the trendlines.
This script employs the use of "future bars" to enhance its accuracy. The script gathers information from the future then retroactively repaints its calculations.
 
fY5xIMu.png


finally managed to convert it with additional options. pls check

CODE:

CSS:
#// 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));

#-------- Bubbles
AddChartBubble(Showubble and Labelup, Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(Showubble and Labeldn, Labeldn, "Break", CreateColor(239, 83, 80), yes);


#### END

V2.0
I added alerts, smoothing, HH/LL label and option to adjust the lookback period so you may get better results.

CSS:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022

input alerts   = yes;
input alertType = alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = yes;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {default ATR, Stdev, Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.0;
input AtrSmoothing = yes;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = If(SaourceCalcMethod == SaourceCalcMethod."Wicks", 1, 0);
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = If(AtrSmoothing, ExpAverage(ATR(Slopelength), 3), ATR(Slopelength));
def LinSlope = WMA(SlopeSaource * n, Slopelength) -
               WMA(SlopeSaource, Slopelength) *
               WMA(n, Slopelength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / Slopelength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, Slopelength) / Slopelength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, Slopelength)) / 2 * SlopeStep;
}
#//----
def wickHi = if wick then h else Max(c, o);
def wickLo = if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

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 (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else UpBreak[-1] else UpBreak[-1] else na;
def Labeldn = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else LoBreak[-1] else LoBreak[-1] else na;

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph[-1]) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl[-1]) then lower else na;

plot upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
               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 ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
                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(c) then na else if IsNaN(ph[-1]) then LastPH else na;
def LoLHline   = if IsNaN(c) then na else if IsNaN(pl[-1]) then LastPL else na;

plot upperPHline = if ShowTodayOnly then if today then UpPHline else na else UpPHline;
upperPHline.SetHiding(!horizontalLine);
upperPHline.SetStyle(Curve.POINTS);
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 = if UpPHline then if today then LoLHline else na else LoLHline ;
LowerLHline.SetHiding(!horizontalLine);
LowerLHline.SetStyle(Curve.POINTS);
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));

#-------- Breakout Bubbles
AddChartBubble(ShowSignal==1 and Labelup, Labelup, "Break", Color.CYAN, no);
AddChartBubble(ShowSignal==1 and Labeldn, Labeldn, "Break", Color.MAGENTA, yes);

AddChartBubble(ShowSignal==2 and Labelup , Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(ShowSignal==2 and Labeldn , Labeldn, "Break", CreateColor(239, 83, 80), yes);
#-------- HHLL Bubbles

def ph_1 = if !isnan(ph) then ph else ph_1[1];
def pl_1 = if !isnan(pl) then pl else pl_1[1];

def hh = if !isnan(ph) and ph > ph_1[1] then ph else na;
def ll = if !isnan(pl) and pl < pl_1[1] then pl else na;
def hl = pl > pl_1[1];
def lh = ph < ph_1[1];
def llBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and ll else ll else na;
def hhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hh else hh else na;
def hlBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hl else hl else na;
def lhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and lh else lh else na;

AddChartBubble(llBubbles, ll, "LL", Color.RED, no);
AddChartBubble(hhBubbles, hh, "HH", Color.GREEN, yes);

AddChartBubble(hlBubbles, pl_1, "HL", Color.DARK_RED, no);
AddChartBubble(lhBubbles, ph_1, "LH", Color.DARK_GREEN, yes);

#---- Alerts
Alert(alerts and Labelup, "Break Up!", alertType, sound);
Alert(alerts and Labeldn, "Break Down!", alertType, sound);

#### END--------
Hi
How do i create a scan & watchlist column for above script?
Thank you !
Daniel.

Hi
and what about set it up on my watchlist column?
Thx
Daniel
 
Last edited by a moderator:
I just noticed something today. The horizontal lines can be used or almost be used as fractal pivots. Has anyone else noticed this and used as such?
 
Hi
i read it over , but still do not understand.
Can add it & fit it to my watchlist y column only or not?
Thank you.
Daniel.
 
Hi
i read it over , but still do not understand.
Can add it & fit it to my watchlist y column only or not?
Thank you.
Daniel.
I do not post scripts for repainting scans, watchlists, etc.

Members find them frustrating, make multiple posts, stating that they are "broken".
a. Signals will show up on the watchlist but not appear on the chart because it repainted. They think it is broken.
b. Signals will not show up on the watchlist but will show up on the chart, as it was repainted afterward. They will complain that it is broken.
 
I do not post scripts for repainting scans, watchlists, etc.

Members find them frustrating, make multiple posts, stating that they are "broken".
a. Signals will show up on the watchlist but not appear on the chart because it repainted. They think it is broken.
b. Signals will not show up on the watchlist but will show up on the chart, as it was repainted afterward. They will complain that it is broken.
I understand, Thank you for your detailed explanations
 
I have used many scripts from this site so I wanted to give something back. This is a scan for a trendline break. I don't guarantee it will catch everything. I have it set for confirmed breaks only. I use it on hourly+ charts so I don't know how well it works for smaller timeframes. I don't daytrade. My coding skills are...passable so it may be a bit messy. This code is for long breaks. To create a scan for short breaks, comment out the first plot line (bottom of the code) and uncomment the second plot line. Hope it works for you.

plot scan = close crosses below lowerLH; <-- For long breaks
#plot scan = close crosses below lowerLH; <-- For short breaks

Code:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022


#THIS IS JUST THE SCANNER FOR THIS INDICATOR.

#SELECT PLOT AT BOTTOM OF CODE FOR LONG OR SHORT, THEN SAVE.

input alerts   = yes;
input alertType = alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = no;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {ATR, Stdev, default Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.6;
input AtrSmoothing = yes;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = If(SaourceCalcMethod == SaourceCalcMethod."Wicks", 1, 0);
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = If(AtrSmoothing, ExpAverage(ATR(Slopelength), 3), ATR(Slopelength));
def LinSlope = WMA(SlopeSaource * n, Slopelength) -
               WMA(SlopeSaource, Slopelength) *
               WMA(n, Slopelength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / Slopelength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, Slopelength) / Slopelength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, Slopelength)) / 2 * SlopeStep;
}
#//----
def wickHi = if wick then h else Max(c, o);
def wickLo = if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

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 (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else UpBreak[-1] else UpBreak[-1] else na;
def Labeldn = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else LoBreak[-1] else LoBreak[-1] else na;

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph[-1]) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl[-1]) then lower else na;

def upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
               if UpPH == 0 then na else UpPH ;
#upperPH.SetStyle(Curve.FIRM);
#upperPH.SetDefaultColor(CreateColor(38, 166, 154));

def upperDash =  if IsNaN(UpPH) then upper else na;
;
#upperDash.SetStyle(Curve.MEDIUM_DASH);
#upperDash.SetDefaultColor(CreateColor(38, 166, 154));

def LowerLH = if ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
                if LoLH == 0 then na else LoLH ;
#LowerLH.SetStyle(Curve.FIRM);
#LowerLH.SetDefaultColor(CreateColor(239, 83, 80));

def LowerDash =  if IsNaN(LoLH) then lower else na;
#LowerDash.SetStyle(Curve.MEDIUM_DASH);
#LowerDash.SetDefaultColor(CreateColor(239, 83, 80));

plot scan =  close crosses below lowerLH;
#plot scan =  close crosses below lowerLH;
#### END--------
 
fY5xIMu.png


finally managed to convert it with additional options. pls check

CODE:

CSS:
#// 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));

#-------- Bubbles
AddChartBubble(Showubble and Labelup, Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(Showubble and Labeldn, Labeldn, "Break", CreateColor(239, 83, 80), yes);


#### END

V2.0
I added alerts, smoothing, HH/LL label and option to adjust the lookback period so you may get better results.

CSS:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022

input alerts   = yes;
input alertType = alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = yes;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {default ATR, Stdev, Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.0;
input AtrSmoothing = yes;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = If(SaourceCalcMethod == SaourceCalcMethod."Wicks", 1, 0);
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = If(AtrSmoothing, ExpAverage(ATR(Slopelength), 3), ATR(Slopelength));
def LinSlope = WMA(SlopeSaource * n, Slopelength) -
               WMA(SlopeSaource, Slopelength) *
               WMA(n, Slopelength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / Slopelength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, Slopelength) / Slopelength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, Slopelength)) / 2 * SlopeStep;
}
#//----
def wickHi = if wick then h else Max(c, o);
def wickLo = if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

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 (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else UpBreak[-1] else UpBreak[-1] else na;
def Labeldn = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else LoBreak[-1] else LoBreak[-1] else na;

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph[-1]) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl[-1]) then lower else na;

plot upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
               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 ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
                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(c) then na else if IsNaN(ph[-1]) then LastPH else na;
def LoLHline   = if IsNaN(c) then na else if IsNaN(pl[-1]) then LastPL else na;

plot upperPHline = if ShowTodayOnly then if today then UpPHline else na else UpPHline;
upperPHline.SetHiding(!horizontalLine);
upperPHline.SetStyle(Curve.POINTS);
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 = if UpPHline then if today then LoLHline else na else LoLHline ;
LowerLHline.SetHiding(!horizontalLine);
LowerLHline.SetStyle(Curve.POINTS);
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));

#-------- Breakout Bubbles
AddChartBubble(ShowSignal==1 and Labelup, Labelup, "Break", Color.CYAN, no);
AddChartBubble(ShowSignal==1 and Labeldn, Labeldn, "Break", Color.MAGENTA, yes);

AddChartBubble(ShowSignal==2 and Labelup , Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(ShowSignal==2 and Labeldn , Labeldn, "Break", CreateColor(239, 83, 80), yes);
#-------- HHLL Bubbles

def ph_1 = if !isnan(ph) then ph else ph_1[1];
def pl_1 = if !isnan(pl) then pl else pl_1[1];

def hh = if !isnan(ph) and ph > ph_1[1] then ph else na;
def ll = if !isnan(pl) and pl < pl_1[1] then pl else na;
def hl = pl > pl_1[1];
def lh = ph < ph_1[1];
def llBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and ll else ll else na;
def hhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hh else hh else na;
def hlBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hl else hl else na;
def lhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and lh else lh else na;

AddChartBubble(llBubbles, ll, "LL", Color.RED, no);
AddChartBubble(hhBubbles, hh, "HH", Color.GREEN, yes);

AddChartBubble(hlBubbles, pl_1, "HL", Color.DARK_RED, no);
AddChartBubble(lhBubbles, ph_1, "LH", Color.DARK_GREEN, yes);

#---- Alerts
Alert(alerts and Labelup, "Break Up!", alertType, sound);
Alert(alerts and Labeldn, "Break Down!", alertType, sound);

#### END--------
Hi Samer800, first big thank you for the work you put here for all of us in the community. I wanted to ask if you can explain the algorithm or the logic behind this Algo, and what I truly mean is to understand what is the difference between "All breaks" vs "only confirmed breaks" what makes a "break" to become a "confirmed break"?

Many thanks.
 
@samer800 is there anyway to draw a channel that touches 2-3 candle wicks (with an option for a downward channel or an upward channel) and like in the below example, when the price action rises above the upper part of the channel, to have the first candle that closes above that channel be highlighted in yellow. If you look at the picture that i've illustrated you will see what I mean. Thanks

 
Last edited:
@samer800 thanks for the scripts.

However, the indicator doesn't "refresh" itself to find new trend lines and breakout.

Maybe you can kindly make an update that the indicator will automatically update and refresh new trendlines?

THANK YOU
 
@samer800 thanks for the scripts.

However, the indicator doesn't "refresh" itself to find new trend lines and breakout.

Maybe you can kindly make an update that the indicator will automatically update and refresh new trendlines?

THANK YOU
check this if resolve the issue

CSS:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022

input alerts   = yes;
input alertType = Alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = yes;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {default ATR, Stdev, Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.5;
#input AtrSmoothing = no;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = if SaourceCalcMethod == SaourceCalcMethod."Wicks" then 1 else
           if SaourceCalcMethod == SaourceCalcMethod."Candle Close" then 0 else wick[1];
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#                 if ShowBrakouts == ShowBrakouts."Don't Show Breakouts" then 0 else ShowSignal[1];
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = ATR(LENGTH=SlopeLength);
def LinSlope = Average(SlopeSaource * n, SlopeLength) -
               Average(SlopeSaource, SlopeLength) *
               Average(n, SlopeLength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / SlopeLength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, SlopeLength) / SlopeLength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, SlopeLength)) / 2 * SlopeStep;
}
#//----
def wickHi = h;#if wick then h else Max(c, o);
def wickLo = l;#if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

slope_ph = if !IsNaN(ph) then slope else if(!slope_ph[1], slope, slope_ph[1]);
slope_pl = if !IsNaN(pl) then slope else if(!slope_pl[1], slope, slope_pl[1]);

upper = if (n < 1) then na else if !IsNaN(ph) then wickHi else if(!upper[1],wickHi,upper[1]) - slope_ph;
lower = if (n < 1) then na else if !IsNaN(pl) then wickLo else if(!lower[1],wickLo,lower[1]) + slope_pl;
#//----
def single_upper;
def single_lower;
single_upper = if (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if !ShowSignal then na else if !ShowTodayOnly then UpBreak[-1] else
              if !today then na else UpBreak[-1];
def Labeldn = if !ShowSignal then na else if !ShowTodayOnly then LoBreak[-1] else
              if !today then na else LoBreak[-1];

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl) then lower else na;

#plot upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
#               if UpPH == 0 then na else UpPH ;
plot upperPH = if !ShowTodayOnly then UpPH else
               if !today 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 ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
#                if LoLH == 0 then na else LoLH ;
plot LowerLH = if !ShowTodayOnly then LoLH else
               if !today 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(c) then na else if IsNaN(ph) then LastPH else na;
def LoLHline   = if IsNaN(c) then na else if IsNaN(pl) then LastPL else na;

plot upperPHline = if !ShowTodayOnly then UpPHline else if !today then na else UpPHline;
upperPHline.SetHiding(!horizontalLine);
upperPHline.SetStyle(Curve.POINTS);
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 = if !ShowTodayOnly then LoLHline else if !today then na else LoLHline;
LowerLHline.SetHiding(!horizontalLine);
LowerLHline.SetStyle(Curve.POINTS);
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));

#-------- Breakout Bubbles
AddChartBubble(ShowSignal == 1 and Labelup, Labelup, "Break", Color.CYAN, no);
AddChartBubble(ShowSignal == 1 and Labeldn, Labeldn, "Break", Color.MAGENTA, yes);

AddChartBubble(ShowSignal == 2 and Labelup , Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(ShowSignal == 2 and Labeldn , Labeldn, "Break", CreateColor(239, 83, 80), yes);
#-------- HHLL Bubbles

def ph_1 = if !IsNaN(ph) then ph else ph_1[1];
def pl_1 = if !IsNaN(pl) then pl else pl_1[1];

def hh = if !IsNaN(ph) and ph > ph_1[1] then ph else na;
def ll = if !IsNaN(pl) and pl < pl_1[1] then pl else na;
def hl = pl > pl_1[1];
def lh = ph < ph_1[1];
def llBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and ll else ll else na;
def hhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hh else hh else na;
def hlBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hl else hl else na;
def lhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and lh else lh else na;

AddChartBubble(llBubbles, ll, "LL", Color.RED, no);
AddChartBubble(hhBubbles, hh, "HH", Color.GREEN, yes);

AddChartBubble(hlBubbles, pl_1, "HL", Color.DARK_RED, no);
AddChartBubble(lhBubbles, ph_1, "LH", Color.DARK_GREEN, yes);

#---- Alerts
Alert(alerts and Labelup, "Break Up!", alertType, sound);
Alert(alerts and Labeldn, "Break Down!", alertType, sound);

#### END--------
 
Hi
SETTING RING FOR BREAK .png

i set it up the break alerts with a ring sound.
but i can not hear the ring sound at all.
What am i not doing here o.k ?

Thannk you
Daniel.
check this if resolve the issue

CSS:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022

input alerts   = yes;
input alertType = Alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = yes;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {default ATR, Stdev, Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.5;
#input AtrSmoothing = no;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = if SaourceCalcMethod == SaourceCalcMethod."Wicks" then 1 else
           if SaourceCalcMethod == SaourceCalcMethod."Candle Close" then 0 else wick[1];
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#                 if ShowBrakouts == ShowBrakouts."Don't Show Breakouts" then 0 else ShowSignal[1];
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = ATR(LENGTH=SlopeLength);
def LinSlope = Average(SlopeSaource * n, SlopeLength) -
               Average(SlopeSaource, SlopeLength) *
               Average(n, SlopeLength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / SlopeLength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, SlopeLength) / SlopeLength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, SlopeLength)) / 2 * SlopeStep;
}
#//----
def wickHi = h;#if wick then h else Max(c, o);
def wickLo = l;#if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

slope_ph = if !IsNaN(ph) then slope else if(!slope_ph[1], slope, slope_ph[1]);
slope_pl = if !IsNaN(pl) then slope else if(!slope_pl[1], slope, slope_pl[1]);

upper = if (n < 1) then na else if !IsNaN(ph) then wickHi else if(!upper[1],wickHi,upper[1]) - slope_ph;
lower = if (n < 1) then na else if !IsNaN(pl) then wickLo else if(!lower[1],wickLo,lower[1]) + slope_pl;
#//----
def single_upper;
def single_lower;
single_upper = if (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if !ShowSignal then na else if !ShowTodayOnly then UpBreak[-1] else
              if !today then na else UpBreak[-1];
def Labeldn = if !ShowSignal then na else if !ShowTodayOnly then LoBreak[-1] else
              if !today then na else LoBreak[-1];

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl) then lower else na;

#plot upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
#               if UpPH == 0 then na else UpPH ;
plot upperPH = if !ShowTodayOnly then UpPH else
               if !today 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 ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
#                if LoLH == 0 then na else LoLH ;
plot LowerLH = if !ShowTodayOnly then LoLH else
               if !today 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(c) then na else if IsNaN(ph) then LastPH else na;
def LoLHline   = if IsNaN(c) then na else if IsNaN(pl) then LastPL else na;

plot upperPHline = if !ShowTodayOnly then UpPHline else if !today then na else UpPHline;
upperPHline.SetHiding(!horizontalLine);
upperPHline.SetStyle(Curve.POINTS);
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 = if !ShowTodayOnly then LoLHline else if !today then na else LoLHline;
LowerLHline.SetHiding(!horizontalLine);
LowerLHline.SetStyle(Curve.POINTS);
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));

#-------- Breakout Bubbles
AddChartBubble(ShowSignal == 1 and Labelup, Labelup, "Break", Color.CYAN, no);
AddChartBubble(ShowSignal == 1 and Labeldn, Labeldn, "Break", Color.MAGENTA, yes);

AddChartBubble(ShowSignal == 2 and Labelup , Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(ShowSignal == 2 and Labeldn , Labeldn, "Break", CreateColor(239, 83, 80), yes);
#-------- HHLL Bubbles

def ph_1 = if !IsNaN(ph) then ph else ph_1[1];
def pl_1 = if !IsNaN(pl) then pl else pl_1[1];

def hh = if !IsNaN(ph) and ph > ph_1[1] then ph else na;
def ll = if !IsNaN(pl) and pl < pl_1[1] then pl else na;
def hl = pl > pl_1[1];
def lh = ph < ph_1[1];
def llBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and ll else ll else na;
def hhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hh else hh else na;
def hlBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hl else hl else na;
def lhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and lh else lh else na;

AddChartBubble(llBubbles, ll, "LL", Color.RED, no);
AddChartBubble(hhBubbles, hh, "HH", Color.GREEN, yes);

AddChartBubble(hlBubbles, pl_1, "HL", Color.DARK_RED, no);
AddChartBubble(lhBubbles, ph_1, "LH", Color.DARK_GREEN, yes);

#---- Alerts
Alert(alerts and Labelup, "Break Up!", alertType, sound);
Alert(alerts and Labeldn, "Break Down!", alertType, sound);

#### END----
[/QUOTE]

I have used many scripts from this site so I wanted to give something back. This is a scan for a trendline break. I don't guarantee it will catch everything. I have it set for confirmed breaks only. I use it on hourly+ charts so I don't know how well it works for smaller timeframes. I don't daytrade. My coding skills are...passable so it may be a bit messy. This code is for long breaks. To create a scan for short breaks, comment out the first plot line (bottom of the code) and uncomment the second plot line. Hope it works for you.

plot scan = close crosses below lowerLH; <-- For long breaks
#plot scan = close crosses below lowerLH; <-- For short breaks

Code:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022


#THIS IS JUST THE SCANNER FOR THIS INDICATOR.

#SELECT PLOT AT BOTTOM OF CODE FOR LONG OR SHORT, THEN SAVE.

input alerts   = yes;
input alertType = alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = no;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {ATR, Stdev, default Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.6;
input AtrSmoothing = yes;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = If(SaourceCalcMethod == SaourceCalcMethod."Wicks", 1, 0);
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = If(AtrSmoothing, ExpAverage(ATR(Slopelength), 3), ATR(Slopelength));
def LinSlope = WMA(SlopeSaource * n, Slopelength) -
               WMA(SlopeSaource, Slopelength) *
               WMA(n, Slopelength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / Slopelength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, Slopelength) / Slopelength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, Slopelength)) / 2 * SlopeStep;
}
#//----
def wickHi = if wick then h else Max(c, o);
def wickLo = if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

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 (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else UpBreak[-1] else UpBreak[-1] else na;
def Labeldn = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else LoBreak[-1] else LoBreak[-1] else na;

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph[-1]) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl[-1]) then lower else na;

def upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
               if UpPH == 0 then na else UpPH ;
#upperPH.SetStyle(Curve.FIRM);
#upperPH.SetDefaultColor(CreateColor(38, 166, 154));

def upperDash =  if IsNaN(UpPH) then upper else na;
;
#upperDash.SetStyle(Curve.MEDIUM_DASH);
#upperDash.SetDefaultColor(CreateColor(38, 166, 154));

def LowerLH = if ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
                if LoLH == 0 then na else LoLH ;
#LowerLH.SetStyle(Curve.FIRM);
#LowerLH.SetDefaultColor(CreateColor(239, 83, 80));

def LowerDash =  if IsNaN(LoLH) then lower else na;
#LowerDash.SetStyle(Curve.MEDIUM_DASH);
#LowerDash.SetDefaultColor(CreateColor(239, 83, 80));

plot scan =  close crosses below lowerLH;
#plot scan =  close crosses below lowerLH;
#### END--------[/
[/QUOTE]

Thank you..How do i add it to my watchlist column ?
 
Last edited by a moderator:
Hi
View attachment 19203
i set it up the break alerts with a ring sound.
but i can not hear the ring sound at all.
What am i not doing here o.k ?

Thannk you
Daniel.




Thank you..How do i add it to my watchlist column ?
see if this resolve the alert issue

CSS:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022

input alerts   = yes;
input alertType = Alert.BAR;
input sound    = Sound.NoSound;
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = yes;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {default ATR, Stdev, Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.5;
#input AtrSmoothing = no;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();


def wickHi;# = h;#if wick then h else Max(c, o);
def wickLo;# = l;#if wick then l else Min(c, o);
Switch (SaourceCalcMethod) {
Case "Wicks" :
    wickHi = h;
    wickLo = l;
Case "Candle Close" :
    wickHi = Max(c, o);
    wickLo = Min(c, o);
}
#def wick = if SaourceCalcMethod == SaourceCalcMethod."Wicks" then 1 else
#           if SaourceCalcMethod == SaourceCalcMethod."Candle Close" then 0 else wick[1];
def ShowSignal;
Switch (ShowBrakouts) {
Case "Show All Breakouts" : ShowSignal = 2;
Case "Only Confirmed Breakouts" : ShowSignal = 1;
Case "Don't Show Breakouts" : ShowSignal = 0;
}
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = ATR(LENGTH=SlopeLength);
def LinSlope = Average(SlopeSaource * n, SlopeLength) -
               Average(SlopeSaource, SlopeLength) *
               Average(n, SlopeLength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / SlopeLength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, SlopeLength) / SlopeLength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, SlopeLength)) / 2 * SlopeStep;
}
#//----

def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

slope_ph = if !IsNaN(ph) then slope else if(!slope_ph[1], slope, slope_ph[1]);
slope_pl = if !IsNaN(pl) then slope else if(!slope_pl[1], slope, slope_pl[1]);

upper = if (n < 1) then na else if !IsNaN(ph) then wickHi else if(!upper[1],wickHi,upper[1]) - slope_ph;
lower = if (n < 1) then na else if !IsNaN(pl) then wickLo else if(!lower[1],wickLo,lower[1]) + slope_pl;
#//----
def single_upper;
def single_lower;
single_upper = if (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if !ShowSignal then na else if !ShowTodayOnly then UpBreak[-1] else
              if !today then na else UpBreak[-1];
def Labeldn = if !ShowSignal then na else if !ShowTodayOnly then LoBreak[-1] else
              if !today then na else LoBreak[-1];

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl) then lower else na;

#plot upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
#               if UpPH == 0 then na else UpPH ;
plot upperPH = if !ShowTodayOnly then UpPH else
               if !today 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 ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
#                if LoLH == 0 then na else LoLH ;
plot LowerLH = if !ShowTodayOnly then LoLH else
               if !today 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(c) then na else if IsNaN(ph) then LastPH else na;
def LoLHline   = if IsNaN(c) then na else if IsNaN(pl) then LastPL else na;

plot upperPHline = if !ShowTodayOnly then UpPHline else if !today then na else UpPHline;
upperPHline.SetHiding(!horizontalLine);
upperPHline.SetStyle(Curve.POINTS);
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 = if !ShowTodayOnly then LoLHline else if !today then na else LoLHline;
LowerLHline.SetHiding(!horizontalLine);
LowerLHline.SetStyle(Curve.POINTS);
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));

#-------- Breakout Bubbles
AddChartBubble(ShowSignal == 1 and Labelup, Labelup, "Break", Color.CYAN, no);
AddChartBubble(ShowSignal == 1 and Labeldn, Labeldn, "Break", Color.MAGENTA, yes);

AddChartBubble(ShowSignal == 2 and Labelup , Labelup, "Break", CreateColor(38, 166, 154), no);
AddChartBubble(ShowSignal == 2 and Labeldn , Labeldn, "Break", CreateColor(239, 83, 80), yes);
#-------- HHLL Bubbles

def ph_1 = if !IsNaN(ph) then ph else ph_1[1];
def pl_1 = if !IsNaN(pl) then pl else pl_1[1];

def hh = if !IsNaN(ph) and ph > ph_1[1] then ph else na;
def ll = if !IsNaN(pl) and pl < pl_1[1] then pl else na;
def hl = pl > pl_1[1];
def lh = ph < ph_1[1];
def llBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and ll else ll else na;
def hhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hh else hh else na;
def hlBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and hl else hl else na;
def lhBubbles = if ShowHighLowBubbles then if ShowTodayOnly then today and lh else lh else na;

AddChartBubble(llBubbles, ll, "LL", Color.RED, no);
AddChartBubble(hhBubbles, hh, "HH", Color.GREEN, yes);

AddChartBubble(hlBubbles, pl_1, "HL", Color.DARK_RED, no);
AddChartBubble(lhBubbles, ph_1, "LH", Color.DARK_GREEN, yes);

#---- Alerts
Alert(alerts and Labelup, "Break Up!", alertType, sound);
Alert(alerts and Labeldn, "Break Down!", alertType, sound);

#### END--------
 
I have used many scripts from this site so I wanted to give something back. This is a scan for a trendline break. I don't guarantee it will catch everything. I have it set for confirmed breaks only. I use it on hourly+ charts so I don't know how well it works for smaller timeframes. I don't daytrade. My coding skills are...passable so it may be a bit messy. This code is for long breaks. To create a scan for short breaks, comment out the first plot line (bottom of the code) and uncomment the second plot line. Hope it works for you.

plot scan = close crosses below lowerLH; <-- For long breaks
#plot scan = close crosses below lowerLH; <-- For short breaks

Code:
#// 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
# added alerts, Loockback Period, Smoothing and HH/LL bubbles - Sam4Cok@Samer800 - 11/2022


#THIS IS JUST THE SCANNER FOR THIS INDICATOR.

#SELECT PLOT AT BOTTOM OF CODE FOR LONG OR SHORT, THEN SAVE.

input alerts   = yes;
input alertType = alert.BAR;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input LookbackPeriod = 14;
input SlopeSaource = close; # Saource for slope calculation
input ShowTodayOnly = no;
input ShowBrakouts = {"Don't Show Breakouts", default "Only Confirmed Breakouts", "Show All Breakouts"};
input ShowHighLowBubbles = no;
input horizontalLine = no;
input SaourceCalcMethod = {default "Wicks", "Candle Close"};
input SlopeCalcMethod = {ATR, Stdev, default Linreg}; #('Atr','Slope Calculation Method'
input SlopeLength = 14;
input SlopeStep = 1.6;
input AtrSmoothing = yes;

#----------------------------
def c = close;
def o = open;
def h = high;
def l = low;
def n = BarNumber();
def na = Double.NaN;
def today =  GetDay() == GetLastDay();
def wick = If(SaourceCalcMethod == SaourceCalcMethod."Wicks", 1, 0);
def ShowSignal = if ShowBrakouts == ShowBrakouts."Only Confirmed Breakouts" then 1 else
                 if ShowBrakouts == ShowBrakouts."Show All Breakouts" then 2 else 0;
#//----
def upper;
def lower;
def slope;
def slope_ph;
def slope_pl;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 1;    # default Pivot Lookback Right
    ##############
    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
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
def nATR = If(AtrSmoothing, ExpAverage(ATR(Slopelength), 3), ATR(Slopelength));
def LinSlope = WMA(SlopeSaource * n, Slopelength) -
               WMA(SlopeSaource, Slopelength) *
               WMA(n, Slopelength);
switch (SlopeCalcMethod) {
case ATR:
    slope = nATR / Slopelength * SlopeStep;
case Stdev:
    slope = StDev(SlopeSaource, Slopelength) / Slopelength * SlopeStep;
case Linreg:
    slope = AbsValue(LinSlope) / Sqr(StDev(n, Slopelength)) / 2 * SlopeStep;
}
#//----
def wickHi = if wick then h else Max(c, o);
def wickLo = if wick then l else Min(c, o);
def ph = findpivots(wickHi, 1, LookbackPeriod, LookbackPeriod);
def pl = findpivots(wickLo, -1, LookbackPeriod, LookbackPeriod);

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 (SlopeSaource[1] > upper) then 0 else
               if !IsNaN(ph) then 1 else single_upper[1];
single_lower = if (SlopeSaource[1] < lower) then 0 else
               if !IsNaN(pl) then 1 else single_lower[1];

def upper_breakout = single_upper[1] and SlopeSaource[1] > upper
                and (if ShowSignal == 1 then SlopeSaource > SlopeSaource[1] else 1);
def lower_breakout = single_lower[1] and SlopeSaource[1] < lower
                and (if ShowSignal == 1 then SlopeSaource < SlopeSaource[1] else 1);

def UpBreak = If(upper_breakout, l[1], na);
def LoBreak = If(lower_breakout, h[1], na);

def Labelup = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else UpBreak[-1] else UpBreak[-1] else na;
def Labeldn = if ShowSignal>0 then if ShowTodayOnly then
              if !today then na else LoBreak[-1] else LoBreak[-1] else na;

#//----

def UpPH   = if IsNaN(c) then na else if IsNaN(ph[-1]) then upper else na;
def LoLH   = if IsNaN(c) then na else if IsNaN(pl[-1]) then lower else na;

def upperPH = if ShowTodayOnly then if UpPH == 0 or !today then na else UpPH else
               if UpPH == 0 then na else UpPH ;
#upperPH.SetStyle(Curve.FIRM);
#upperPH.SetDefaultColor(CreateColor(38, 166, 154));

def upperDash =  if IsNaN(UpPH) then upper else na;
;
#upperDash.SetStyle(Curve.MEDIUM_DASH);
#upperDash.SetDefaultColor(CreateColor(38, 166, 154));

def LowerLH = if ShowTodayOnly then if LoLH == 0 or !today then na else LoLH else
                if LoLH == 0 then na else LoLH ;
#LowerLH.SetStyle(Curve.FIRM);
#LowerLH.SetDefaultColor(CreateColor(239, 83, 80));

def LowerDash =  if IsNaN(LoLH) then lower else na;
#LowerDash.SetStyle(Curve.MEDIUM_DASH);
#LowerDash.SetDefaultColor(CreateColor(239, 83, 80));

plot scan =  close crosses below lowerLH;
#plot scan =  close crosses below lowerLH;
#### END--------
Hi
ON short break i can not "OK" it
 

Attachments

  • ON SHORT BREAK DOES   IT NOT LET ME TO OK IT.png
    ON SHORT BREAK DOES IT NOT LET ME TO OK IT.png
    24.3 KB · Views: 217
Remove the hashtag that is in front of the last line plot scan
like this? for breaking short only?

#plot scan = close crosses below lowerLH;
#### END--------

and like this for breaking long only?


plot scan = close crosses below lowerLH;
#### END--------

Thank you!
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
269 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top