Tradarr
New member
Hello, I downloaded and installed the free LuxAlgo Smart Money Concepts ,it has labels for Change of Character and Break Of Structure but I wish to do scans for bullish Change of Character and bearish Change of Character and can't figure out how to, so hoping someone can add scans for those?
https://www.luxalgo.com/library/indicator/Smart-Money-Concepts/
##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 https://www.luxalgo.com/
#hint: This all-in-one indicator displays real-time market structure (internal & swing BOS / CHoCH), premium & discount zones, equal highs & lows, and much more...allowing traders to automatically mark up their charts with widely used price action methodologies. "Smart Money Concepts" ( SMC ) is a fairly new yet widely used term amongst price action traders looking to more accurately navigate liquidity & find more optimal points of interest in the market. Trying to determine where institutional market participants have orders placed (buy or sell side liquidity) can be a very reasonable approach to finding more practical entries & exits based on price action.
#Structures
input showInternals = yes;
#input InternalBullStruct = {default All, BOS, CHoCH};
#input InternalBearStruct = {default All, BOS, CHoCH};
input showSwings = yes;
#input SwingBullStruct = {default All, BOS, CHoCH};
#input SwingBearStruct = {default All, BOS, CHoCH};
input length = 50;
input ifilter_confluence = no;
input show_hl_swings = yes;
DefineGlobalColor("Internal Bullish",CreateColor(8, 153, 129));
DefineGlobalColor("Internal Bearish",CreateColor(242, 54, 69));
DefineGlobalColor("Swing Bullish",CreateColor(8, 153, 129));
DefineGlobalColor("Swing Bearish",CreateColor(242, 54, 69));
script swings {
input len = 5;
def os = if (high[len] > Highest(high, len)) then 0 else if (low[len] < Lowest(low, len)) then 1 else os[1];
plot top = if os == 0 and os[1] != 0 then high[len] else 0;
plot btm = if os == 1 and os[1] != 1 then low[len] else 0;
}
def lastbarbn = HighestAll(If(IsNaN(close), 0, BarNumber()));
def n = BarNumber();
def top = swings(length).top;
def btm = swings(length).btm;
def itop = swings(5).top;
def ibtm = swings(5).btm;
#High Pivots Setup
def top_cross; def top_y; def top_x; def trail_up; def trail_up_x;
if (top != 0) then {
top_y = top;
top_x = n - length;
trail_up = top;
trail_up_x = n - length;
} else {
top_y = top_y[1];
top_x = top_x[1];
trail_up = Max(high, trail_up[1]);
trail_up_x = if trail_up == high then n else trail_up_x[1];
}
def itop_cross; def itop_y; def itop_x;
if (itop != 0) then {
itop_y = itop;
itop_x = n - 5;
} else {
itop_y = itop_y[1];
itop_x = itop_x[1];
}
#Low Pivots Setdn
def btm_cross; def btm_y; def btm_x; def trail_dn; def trail_dn_x;
if (btm != 0) then {
btm_y = btm;
btm_x = n - length;
trail_dn = btm;
trail_dn_x = n - length;
} else {
btm_y = btm_y[1];
btm_x = btm_x[1];
trail_dn = Min(low, trail_dn[1]);
trail_dn_x = if trail_dn == low then n else trail_dn_x[1];
}
def ibtm_cross; def ibtm_y; def ibtm_x;
if (ibtm != 0) then {
ibtm_y = ibtm;
ibtm_x = n - 5;
} else {
ibtm_y = ibtm_y[1];
ibtm_x = ibtm_x[1];
}
######################################################################################################################
#Internal Structures
def bull_concordant = if !ifilter_confluence then yes else high - Max(close, open) > Min(close, open - low);
def bear_concordant = if !ifilter_confluence then yes else high - Max(close, open) < Min(close, open - low);
def itrend;
if (Crosses(close, itop_y, CrossingDirection.ABOVE) and itop_cross[1] < itop_x and top_y != itop_y and bull_concordant) then {
itop_cross = itop_x;
itrend = 1;
ibtm_cross = ibtm_cross[1];
}
else if(Crosses(close, ibtm_y, CrossingDirection.BELOW) and ibtm_cross[1] < ibtm_x and btm_y != ibtm_y and bear_concordant)then {
ibtm_cross = ibtm_x;
itrend = -1;
itop_cross = itop_cross[1];
}
else {
ibtm_cross = ibtm_cross[1];
itop_cross = itop_cross[1];
itrend = itrend[1];
}
#Plot Internal Structure
#Bullish
def plotBullInternal = fold i1 = 0 to 1000 with p1 = 0 while GetValue(itop_cross,-(i1-1)) < GetValue(itop_x,-(i1-1)) and itop_x == GetValue(itop_x,-(i1-1)) do if GetValue(itop_cross,-(i1)) == GetValue(itop_x,-(i1)) then GetValue(itop_y,-i1) else 0;
def InternalBullStructureVal = if highest(plotBullInternal,6) != 0 then highest(plotBullInternal,6) else double.nan;
plot InternalBullStructure = if showInternals then Displacer(-6,InternalBullStructureVal) else double.nan;
InternalBullStructure.SetDefaultColor(GlobalColor("Internal Bullish"));
InternalBullStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.DASHES);
#Bearish
def plotBearInternal = fold i2 = 0 to 1000 with p2 = 0 while GetValue(ibtm_cross,-(i2-1)) < GetValue(ibtm_x,-(i2-1)) and ibtm_x == GetValue(ibtm_x,-(i2-1)) do if GetValue(ibtm_cross,-(i2)) == GetValue(ibtm_x,-(i2)) then GetValue(ibtm_y,-i2) else 0;
def InternalBearStructureVal = if highest(plotBearInternal,6) != 0 then highest(plotBearInternal,6) else double.nan;
plot InternalBearStructure = if showInternals then Displacer(-6,InternalBearStructureVal) else double.nan;
InternalBearStructure.SetDefaultColor(GlobalColor("Internal Bearish"));
InternalBearStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.DASHES);
#Labels
AddChartBubble(showInternals and itop_x != itop_x[1] and !IsNan(InternalBullStructure[4]), InternalBullStructure,
if(itrend == -1 or !IsNan(InternalBearStructure[4])) then "CHoCH" else "BOS", GlobalColor("Internal Bullish"), yes);
AddChartBubble(showInternals and ibtm_x != ibtm_x[1] and !IsNan(InternalBearStructure[4]), InternalBearStructure,
if(itrend == 1 or !IsNan(InternalBullStructure[4])) then "CHoCH" else "BOS", GlobalColor("Internal Bearish"), no);
######################################################################################################################
#Swing Structures
def trend;
if(Crosses(close, top_y, CrossingDirection.ABOVE) and top_cross[1] < top_x) then {
top_cross = top_x;
trend = 1;
btm_cross = btm_cross[1];
}
else if(Crosses(close, btm_y, CrossingDirection.BELOW) and btm_cross[1] < btm_x) then {
btm_cross = btm_x;
trend = -1;
top_cross = top_cross[1];
}
else {
btm_cross = btm_cross[1];
top_cross = top_cross[1];
trend = trend[1];
}
#Plot Swing Structure
#Bullish
def plotBullSwing = fold i3 = 0 to 1000 with p3 = 0 while GetValue(top_cross,-(i3-1)) < GetValue(top_x,-(i3-1)) and top_x == GetValue(top_x,-(i3-1)) do if GetValue(top_cross,-(i3)) == GetValue(top_x,-(i3)) then GetValue(top_y,-i3) else 0;
def SwingBullStructureVal = if highest(plotBullSwing,(length+1)) != 0 then highest(plotBullSwing,(length+1)) else double.nan;
plot SwingBullStructure = if showSwings then Displacer(-(length+1),SwingBullStructureVal) else double.nan;
SwingBullStructure.SetDefaultColor(GlobalColor("Swing Bullish"));
SwingBullStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HORIZONTAL);
SwingBullStructure.SetLineWeight(2);
#Bearish
def plotBearSwing = fold i4 = 0 to 1000 with p4 = 0 while GetValue(btm_cross,-(i4-1)) < GetValue(btm_x,-(i4-1)) and btm_x == GetValue(btm_x,-(i4-1)) do if GetValue(btm_cross,-(i4)) == GetValue(btm_x,-(i4)) then GetValue(btm_y,-i4) else 0;
def SwingBearStructureVal = if highest(plotBearSwing,(length+1)) != 0 then highest(plotBearSwing,(length+1)) else double.nan;
plot SwingBearStructure = if showSwings then Displacer(-(length+1),SwingBearStructureVal) else double.nan;
SwingBearStructure.SetDefaultColor(GlobalColor("Swing Bearish"));
SwingBearStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HORIZONTAL);
SwingBearStructure.SetLineWeight(2);
#Labels
AddChartBubble(showSwings and top_x != top_x[1] and !IsNan(SwingBullStructure[length]), SwingBullStructure,
if(trend == -1 or !IsNan(SwingBearStructure[length])) then "CHoCH" else "BOS", GlobalColor("Swing Bullish"), yes);
AddChartBubble(showSwings and btm_x != btm_x[1] and !IsNan(SwingBearStructure[length]), SwingBearStructure,
if(trend == 1 or !IsNan(SwingBullStructure[length])) then "CHoCH" else "BOS", GlobalColor("Swing Bearish"), no);
#Plot Strong/Weak High/Low
plot StrongWeakHigh = if (show_hl_swings and trail_up == GetValue(trail_up,-(lastbarbn-BarNumber())) or IsNan(close)) then GetValue(trail_up,-(lastbarbn-BarNumber())) else double.nan;
StrongWeakHigh.SetDefaultColor(color.red);
StrongWeakHigh.SetLineWeight(2);
AddChartBubble(show_hl_swings and BarNumber() == lastbarbn, trail_up, if trend < 0 then "Strong High" else "Weak High", color.red,yes);
plot StrongWeakLow = if (show_hl_swings and trail_dn == GetValue(trail_dn,-(lastbarbn-BarNumber())) or IsNan(close)) then GetValue(trail_dn,-(lastbarbn-BarNumber())) else double.nan;
StrongWeakLow.SetDefaultColor(color.green);
StrongWeakLow.SetLineWeight(2);
AddChartBubble(show_hl_swings and BarNumber() == lastbarbn, trail_dn, if trend > 0 then "Strong Low" else "Weak Low", color.green,no);
######################################################################################################################
#Inputs
input showDaily = no;
input showWeekly = no;
input showMonthly = no;
input showBubbles = no;
DefineGlobalColor("Daily",color.cyan);
DefineGlobalColor("Weekly",color.orange);
DefineGlobalColor("Monthly",color.violet);
def dHigh = if high(period = "day") != high(period = "day")[1] then high(period = "day")[1] else dHigh[1];
def dLow = if low(period = "day") != low(period = "day")[1] then low(period = "day")[1] else dLow[1];
def dBarN = if low(period = "day") != low(period = "day")[1] then BarNumber()[1] else dBarN[1];
def dBarNo = if dBarN != dBarN[1] then dBarN[1] else dBarNo[1];
def wHigh = if high(period = "week") != high(period = "week")[1] then high(period = "week")[1] else wHigh[1];
def wLow = if low(period = "week") != low(period = "week")[1] then low(period = "week")[1] else wLow[1];
def wBarN = if low(period = "week") != low(period = "week")[1] then BarNumber()[1] else wBarN[1];
def wBarNo = if wBarN != wBarN[1] then wBarN[1] else wBarNo[1];
def mHigh = if high(period = "month") != high(period = "month")[1] then high(period = "month")[1] else mHigh[1];
def mLow = if low(period = "month") != low(period = "month")[1] then low(period = "month")[1] else mLow[1];
def mBarN = if low(period = "month") != low(period = "month")[1] then BarNumber()[1] else mBarN[1];
def mBarNo = if mBarN != mBarN[1] then mBarN[1] else mBarNo[1];
#Daily
def DailyHigh = if BarNumber() > HighestAll(dBarNo) and GetValue(dHigh,-(lastbarbn-BarNumber())) == high then
GetValue(dHigh,-(lastbarbn-BarNumber())) else DailyHigh[1];
plot DailyHighPlot = if !showDaily or DailyHigh == 0 then double.nan else DailyHigh;
def DailyLow = if BarNumber() > HighestAll(dBarNo) and GetValue(dLow,-(lastbarbn-BarNumber())) == low then
GetValue(dLow,-(lastbarbn-BarNumber())) else DailyLow[1];
plot DailyLowPlot = if !showDaily or DailyLow == 0 then double.nan else DailyLow;
DailyHighPlot.SetDefaultColor(GlobalColor("Daily"));
DailyLowPlot.SetDefaultColor(GlobalColor("Daily"));
#Weekly
def WeeklyHigh = if BarNumber() > HighestAll(wBarNo) and GetValue(wHigh,-(lastbarbn-BarNumber())) == high then
GetValue(wHigh,-(lastbarbn-BarNumber())) else WeeklyHigh[1];
plot WeeklyHighPlot = if !showWeekly or WeeklyHigh == 0 then double.nan else WeeklyHigh;
def WeeklyLow = if BarNumber() > HighestAll(wBarNo) and GetValue(wLow,-(lastbarbn-BarNumber())) == low then
GetValue(wLow,-(lastbarbn-BarNumber())) else WeeklyLow[1];
plot WeeklyLowPlot = if !showWeekly or WeeklyLow == 0 then double.nan else WeeklyLow;
WeeklyHighPlot.SetDefaultColor(GlobalColor("Weekly"));
WeeklyLowPlot.SetDefaultColor(GlobalColor("Weekly"));
#Monthly
def MonthlyHigh = if BarNumber() > HighestAll(mBarNo) and GetValue(mHigh,-(lastbarbn-BarNumber())) == high then
GetValue(mHigh,-(lastbarbn-BarNumber())) else MonthlyHigh[1];
plot MonthlyHighPlot = if !showMonthly or MonthlyHigh == 0 then double.nan else MonthlyHigh;
def MonthlyLow = if BarNumber() > HighestAll(mBarNo) and GetValue(mLow,-(lastbarbn-BarNumber())) == low then
GetValue(mLow,-(lastbarbn-BarNumber())) else MonthlyLow[1];
plot MonthlyLowPlot = if !showMonthly or MonthlyLow == 0 then double.nan else MonthlyLow;
MonthlyHighPlot.SetDefaultColor(GlobalColor("Monthly"));
MonthlyLowPlot.SetDefaultColor(GlobalColor("Monthly"));
#Bubbles
AddChartBubble(showBubbles and showDaily and barNumber() == lastbarbn, DailyHighPlot, "PDH", GlobalColor("Daily"), yes);
AddChartBubble(showBubbles and showDaily and barNumber() == lastbarbn, DailyLowPlot, "PDL", GlobalColor("Daily"), no);
AddChartBubble(showBubbles and showWeekly and barNumber() == lastbarbn, WeeklyHighPlot, "PWH", GlobalColor("Weekly"), yes);
AddChartBubble(showBubbles and showWeekly and barNumber() == lastbarbn, WeeklyLowPlot, "PWL", GlobalColor("Weekly"), no);
AddChartBubble(showBubbles and showMonthly and barNumber() == lastbarbn, MonthlyHighPlot, "PMH", GlobalColor("Monthly"), yes);
AddChartBubble(showBubbles and showMonthly and barNumber() == lastbarbn, MonthlyLowPlot, "PML", GlobalColor("Monthly"), no);
######################################################################################################################
######################################################################################################################
input eq_length = 3;
input threshold = 0.1;
input showLabels = no;
#Pivots
def ph_idx = fold i5 = 1 to eq_length with p5 = 0 do if GetValue(high, i5) < high and high >= GetValue(high, -i5) then p5 + 1 else p5;
def pl_idx = fold i6 = 1 to eq_length with p6 = 0 do if GetValue(low, i6) > low and low <= GetValue(low, -i6) then p6 + 1 else p6;
def ph_condition = if IsNaN(ph_idx == eq_length - 1) then no else ph_idx == eq_length - 1;
def pl_condition = if IsNaN(pl_idx == eq_length - 1) then no else pl_idx == eq_length - 1;
def ph;
def pl;
def isEQH;
def isEQL;
def atr = ATR(200);
if (ph_condition)
then {
ph = high;
pl = Double.NaN;
isEQH = fold i7 = 2 to 500 while (IsNaN(GetValue(ph, -(i7 - 1))) and !IsNaN(GetValue(low, -i7))) do
if Max(ph, GetValue(ph, -i7)) < Min(ph, GetValue(ph, -i7)) + atr * threshold then yes else no;
isEQL = isEQL[1];
}
else if(pl_condition) then {
ph = double.nan;
pl = low;
isEQH = isEQH[1];
isEQL = fold i8 = 2 to 500 while (IsNaN(GetValue(pl, -(i8 - 1))) and !IsNaN(GetValue(low, -i8))) do
if Min(pl, GetValue(pl, -i8)) > Max(pl, GetValue(pl, -i8)) - atr * threshold then yes else no;
}
else {
ph = double.nan;
pl = Double.NaN;
isEQH = isEQH[1];
isEQL = isEQL[1];
}
#Labels
AddChartBubble(showLabels and isEQH and !isEQH[1], ph, "EQH", CreateColor(242, 54, 69), yes);
AddChartBubble(showLabels and isEQL and !isEQL[1], pl, "EQL", CreateColor(8, 153, 129), no);
#Plots
def EQH = if isEQH and !isEQH[1] then ph else if isEQH[1] then EQH[1] else double.nan;
def EQL = if isEQL and !isEQL[1] then pl else if isEQL[1] then EQL[1] else double.nan;
plot EQHLine = EQH;
EQHLine.SetDefaultColor(CreateColor(242, 54, 69));
plot EQLLine = EQL;
EQLLine.SetDefaultColor(CreateColor(8, 153, 129));
https://www.luxalgo.com/library/indicator/Smart-Money-Concepts/
##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 https://www.luxalgo.com/
#hint: This all-in-one indicator displays real-time market structure (internal & swing BOS / CHoCH), premium & discount zones, equal highs & lows, and much more...allowing traders to automatically mark up their charts with widely used price action methodologies. "Smart Money Concepts" ( SMC ) is a fairly new yet widely used term amongst price action traders looking to more accurately navigate liquidity & find more optimal points of interest in the market. Trying to determine where institutional market participants have orders placed (buy or sell side liquidity) can be a very reasonable approach to finding more practical entries & exits based on price action.
#Structures
input showInternals = yes;
#input InternalBullStruct = {default All, BOS, CHoCH};
#input InternalBearStruct = {default All, BOS, CHoCH};
input showSwings = yes;
#input SwingBullStruct = {default All, BOS, CHoCH};
#input SwingBearStruct = {default All, BOS, CHoCH};
input length = 50;
input ifilter_confluence = no;
input show_hl_swings = yes;
DefineGlobalColor("Internal Bullish",CreateColor(8, 153, 129));
DefineGlobalColor("Internal Bearish",CreateColor(242, 54, 69));
DefineGlobalColor("Swing Bullish",CreateColor(8, 153, 129));
DefineGlobalColor("Swing Bearish",CreateColor(242, 54, 69));
script swings {
input len = 5;
def os = if (high[len] > Highest(high, len)) then 0 else if (low[len] < Lowest(low, len)) then 1 else os[1];
plot top = if os == 0 and os[1] != 0 then high[len] else 0;
plot btm = if os == 1 and os[1] != 1 then low[len] else 0;
}
def lastbarbn = HighestAll(If(IsNaN(close), 0, BarNumber()));
def n = BarNumber();
def top = swings(length).top;
def btm = swings(length).btm;
def itop = swings(5).top;
def ibtm = swings(5).btm;
#High Pivots Setup
def top_cross; def top_y; def top_x; def trail_up; def trail_up_x;
if (top != 0) then {
top_y = top;
top_x = n - length;
trail_up = top;
trail_up_x = n - length;
} else {
top_y = top_y[1];
top_x = top_x[1];
trail_up = Max(high, trail_up[1]);
trail_up_x = if trail_up == high then n else trail_up_x[1];
}
def itop_cross; def itop_y; def itop_x;
if (itop != 0) then {
itop_y = itop;
itop_x = n - 5;
} else {
itop_y = itop_y[1];
itop_x = itop_x[1];
}
#Low Pivots Setdn
def btm_cross; def btm_y; def btm_x; def trail_dn; def trail_dn_x;
if (btm != 0) then {
btm_y = btm;
btm_x = n - length;
trail_dn = btm;
trail_dn_x = n - length;
} else {
btm_y = btm_y[1];
btm_x = btm_x[1];
trail_dn = Min(low, trail_dn[1]);
trail_dn_x = if trail_dn == low then n else trail_dn_x[1];
}
def ibtm_cross; def ibtm_y; def ibtm_x;
if (ibtm != 0) then {
ibtm_y = ibtm;
ibtm_x = n - 5;
} else {
ibtm_y = ibtm_y[1];
ibtm_x = ibtm_x[1];
}
######################################################################################################################
#Internal Structures
def bull_concordant = if !ifilter_confluence then yes else high - Max(close, open) > Min(close, open - low);
def bear_concordant = if !ifilter_confluence then yes else high - Max(close, open) < Min(close, open - low);
def itrend;
if (Crosses(close, itop_y, CrossingDirection.ABOVE) and itop_cross[1] < itop_x and top_y != itop_y and bull_concordant) then {
itop_cross = itop_x;
itrend = 1;
ibtm_cross = ibtm_cross[1];
}
else if(Crosses(close, ibtm_y, CrossingDirection.BELOW) and ibtm_cross[1] < ibtm_x and btm_y != ibtm_y and bear_concordant)then {
ibtm_cross = ibtm_x;
itrend = -1;
itop_cross = itop_cross[1];
}
else {
ibtm_cross = ibtm_cross[1];
itop_cross = itop_cross[1];
itrend = itrend[1];
}
#Plot Internal Structure
#Bullish
def plotBullInternal = fold i1 = 0 to 1000 with p1 = 0 while GetValue(itop_cross,-(i1-1)) < GetValue(itop_x,-(i1-1)) and itop_x == GetValue(itop_x,-(i1-1)) do if GetValue(itop_cross,-(i1)) == GetValue(itop_x,-(i1)) then GetValue(itop_y,-i1) else 0;
def InternalBullStructureVal = if highest(plotBullInternal,6) != 0 then highest(plotBullInternal,6) else double.nan;
plot InternalBullStructure = if showInternals then Displacer(-6,InternalBullStructureVal) else double.nan;
InternalBullStructure.SetDefaultColor(GlobalColor("Internal Bullish"));
InternalBullStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.DASHES);
#Bearish
def plotBearInternal = fold i2 = 0 to 1000 with p2 = 0 while GetValue(ibtm_cross,-(i2-1)) < GetValue(ibtm_x,-(i2-1)) and ibtm_x == GetValue(ibtm_x,-(i2-1)) do if GetValue(ibtm_cross,-(i2)) == GetValue(ibtm_x,-(i2)) then GetValue(ibtm_y,-i2) else 0;
def InternalBearStructureVal = if highest(plotBearInternal,6) != 0 then highest(plotBearInternal,6) else double.nan;
plot InternalBearStructure = if showInternals then Displacer(-6,InternalBearStructureVal) else double.nan;
InternalBearStructure.SetDefaultColor(GlobalColor("Internal Bearish"));
InternalBearStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.DASHES);
#Labels
AddChartBubble(showInternals and itop_x != itop_x[1] and !IsNan(InternalBullStructure[4]), InternalBullStructure,
if(itrend == -1 or !IsNan(InternalBearStructure[4])) then "CHoCH" else "BOS", GlobalColor("Internal Bullish"), yes);
AddChartBubble(showInternals and ibtm_x != ibtm_x[1] and !IsNan(InternalBearStructure[4]), InternalBearStructure,
if(itrend == 1 or !IsNan(InternalBullStructure[4])) then "CHoCH" else "BOS", GlobalColor("Internal Bearish"), no);
######################################################################################################################
#Swing Structures
def trend;
if(Crosses(close, top_y, CrossingDirection.ABOVE) and top_cross[1] < top_x) then {
top_cross = top_x;
trend = 1;
btm_cross = btm_cross[1];
}
else if(Crosses(close, btm_y, CrossingDirection.BELOW) and btm_cross[1] < btm_x) then {
btm_cross = btm_x;
trend = -1;
top_cross = top_cross[1];
}
else {
btm_cross = btm_cross[1];
top_cross = top_cross[1];
trend = trend[1];
}
#Plot Swing Structure
#Bullish
def plotBullSwing = fold i3 = 0 to 1000 with p3 = 0 while GetValue(top_cross,-(i3-1)) < GetValue(top_x,-(i3-1)) and top_x == GetValue(top_x,-(i3-1)) do if GetValue(top_cross,-(i3)) == GetValue(top_x,-(i3)) then GetValue(top_y,-i3) else 0;
def SwingBullStructureVal = if highest(plotBullSwing,(length+1)) != 0 then highest(plotBullSwing,(length+1)) else double.nan;
plot SwingBullStructure = if showSwings then Displacer(-(length+1),SwingBullStructureVal) else double.nan;
SwingBullStructure.SetDefaultColor(GlobalColor("Swing Bullish"));
SwingBullStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HORIZONTAL);
SwingBullStructure.SetLineWeight(2);
#Bearish
def plotBearSwing = fold i4 = 0 to 1000 with p4 = 0 while GetValue(btm_cross,-(i4-1)) < GetValue(btm_x,-(i4-1)) and btm_x == GetValue(btm_x,-(i4-1)) do if GetValue(btm_cross,-(i4)) == GetValue(btm_x,-(i4)) then GetValue(btm_y,-i4) else 0;
def SwingBearStructureVal = if highest(plotBearSwing,(length+1)) != 0 then highest(plotBearSwing,(length+1)) else double.nan;
plot SwingBearStructure = if showSwings then Displacer(-(length+1),SwingBearStructureVal) else double.nan;
SwingBearStructure.SetDefaultColor(GlobalColor("Swing Bearish"));
SwingBearStructure.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HORIZONTAL);
SwingBearStructure.SetLineWeight(2);
#Labels
AddChartBubble(showSwings and top_x != top_x[1] and !IsNan(SwingBullStructure[length]), SwingBullStructure,
if(trend == -1 or !IsNan(SwingBearStructure[length])) then "CHoCH" else "BOS", GlobalColor("Swing Bullish"), yes);
AddChartBubble(showSwings and btm_x != btm_x[1] and !IsNan(SwingBearStructure[length]), SwingBearStructure,
if(trend == 1 or !IsNan(SwingBullStructure[length])) then "CHoCH" else "BOS", GlobalColor("Swing Bearish"), no);
#Plot Strong/Weak High/Low
plot StrongWeakHigh = if (show_hl_swings and trail_up == GetValue(trail_up,-(lastbarbn-BarNumber())) or IsNan(close)) then GetValue(trail_up,-(lastbarbn-BarNumber())) else double.nan;
StrongWeakHigh.SetDefaultColor(color.red);
StrongWeakHigh.SetLineWeight(2);
AddChartBubble(show_hl_swings and BarNumber() == lastbarbn, trail_up, if trend < 0 then "Strong High" else "Weak High", color.red,yes);
plot StrongWeakLow = if (show_hl_swings and trail_dn == GetValue(trail_dn,-(lastbarbn-BarNumber())) or IsNan(close)) then GetValue(trail_dn,-(lastbarbn-BarNumber())) else double.nan;
StrongWeakLow.SetDefaultColor(color.green);
StrongWeakLow.SetLineWeight(2);
AddChartBubble(show_hl_swings and BarNumber() == lastbarbn, trail_dn, if trend > 0 then "Strong Low" else "Weak Low", color.green,no);
######################################################################################################################
#Inputs
input showDaily = no;
input showWeekly = no;
input showMonthly = no;
input showBubbles = no;
DefineGlobalColor("Daily",color.cyan);
DefineGlobalColor("Weekly",color.orange);
DefineGlobalColor("Monthly",color.violet);
def dHigh = if high(period = "day") != high(period = "day")[1] then high(period = "day")[1] else dHigh[1];
def dLow = if low(period = "day") != low(period = "day")[1] then low(period = "day")[1] else dLow[1];
def dBarN = if low(period = "day") != low(period = "day")[1] then BarNumber()[1] else dBarN[1];
def dBarNo = if dBarN != dBarN[1] then dBarN[1] else dBarNo[1];
def wHigh = if high(period = "week") != high(period = "week")[1] then high(period = "week")[1] else wHigh[1];
def wLow = if low(period = "week") != low(period = "week")[1] then low(period = "week")[1] else wLow[1];
def wBarN = if low(period = "week") != low(period = "week")[1] then BarNumber()[1] else wBarN[1];
def wBarNo = if wBarN != wBarN[1] then wBarN[1] else wBarNo[1];
def mHigh = if high(period = "month") != high(period = "month")[1] then high(period = "month")[1] else mHigh[1];
def mLow = if low(period = "month") != low(period = "month")[1] then low(period = "month")[1] else mLow[1];
def mBarN = if low(period = "month") != low(period = "month")[1] then BarNumber()[1] else mBarN[1];
def mBarNo = if mBarN != mBarN[1] then mBarN[1] else mBarNo[1];
#Daily
def DailyHigh = if BarNumber() > HighestAll(dBarNo) and GetValue(dHigh,-(lastbarbn-BarNumber())) == high then
GetValue(dHigh,-(lastbarbn-BarNumber())) else DailyHigh[1];
plot DailyHighPlot = if !showDaily or DailyHigh == 0 then double.nan else DailyHigh;
def DailyLow = if BarNumber() > HighestAll(dBarNo) and GetValue(dLow,-(lastbarbn-BarNumber())) == low then
GetValue(dLow,-(lastbarbn-BarNumber())) else DailyLow[1];
plot DailyLowPlot = if !showDaily or DailyLow == 0 then double.nan else DailyLow;
DailyHighPlot.SetDefaultColor(GlobalColor("Daily"));
DailyLowPlot.SetDefaultColor(GlobalColor("Daily"));
#Weekly
def WeeklyHigh = if BarNumber() > HighestAll(wBarNo) and GetValue(wHigh,-(lastbarbn-BarNumber())) == high then
GetValue(wHigh,-(lastbarbn-BarNumber())) else WeeklyHigh[1];
plot WeeklyHighPlot = if !showWeekly or WeeklyHigh == 0 then double.nan else WeeklyHigh;
def WeeklyLow = if BarNumber() > HighestAll(wBarNo) and GetValue(wLow,-(lastbarbn-BarNumber())) == low then
GetValue(wLow,-(lastbarbn-BarNumber())) else WeeklyLow[1];
plot WeeklyLowPlot = if !showWeekly or WeeklyLow == 0 then double.nan else WeeklyLow;
WeeklyHighPlot.SetDefaultColor(GlobalColor("Weekly"));
WeeklyLowPlot.SetDefaultColor(GlobalColor("Weekly"));
#Monthly
def MonthlyHigh = if BarNumber() > HighestAll(mBarNo) and GetValue(mHigh,-(lastbarbn-BarNumber())) == high then
GetValue(mHigh,-(lastbarbn-BarNumber())) else MonthlyHigh[1];
plot MonthlyHighPlot = if !showMonthly or MonthlyHigh == 0 then double.nan else MonthlyHigh;
def MonthlyLow = if BarNumber() > HighestAll(mBarNo) and GetValue(mLow,-(lastbarbn-BarNumber())) == low then
GetValue(mLow,-(lastbarbn-BarNumber())) else MonthlyLow[1];
plot MonthlyLowPlot = if !showMonthly or MonthlyLow == 0 then double.nan else MonthlyLow;
MonthlyHighPlot.SetDefaultColor(GlobalColor("Monthly"));
MonthlyLowPlot.SetDefaultColor(GlobalColor("Monthly"));
#Bubbles
AddChartBubble(showBubbles and showDaily and barNumber() == lastbarbn, DailyHighPlot, "PDH", GlobalColor("Daily"), yes);
AddChartBubble(showBubbles and showDaily and barNumber() == lastbarbn, DailyLowPlot, "PDL", GlobalColor("Daily"), no);
AddChartBubble(showBubbles and showWeekly and barNumber() == lastbarbn, WeeklyHighPlot, "PWH", GlobalColor("Weekly"), yes);
AddChartBubble(showBubbles and showWeekly and barNumber() == lastbarbn, WeeklyLowPlot, "PWL", GlobalColor("Weekly"), no);
AddChartBubble(showBubbles and showMonthly and barNumber() == lastbarbn, MonthlyHighPlot, "PMH", GlobalColor("Monthly"), yes);
AddChartBubble(showBubbles and showMonthly and barNumber() == lastbarbn, MonthlyLowPlot, "PML", GlobalColor("Monthly"), no);
######################################################################################################################
######################################################################################################################
input eq_length = 3;
input threshold = 0.1;
input showLabels = no;
#Pivots
def ph_idx = fold i5 = 1 to eq_length with p5 = 0 do if GetValue(high, i5) < high and high >= GetValue(high, -i5) then p5 + 1 else p5;
def pl_idx = fold i6 = 1 to eq_length with p6 = 0 do if GetValue(low, i6) > low and low <= GetValue(low, -i6) then p6 + 1 else p6;
def ph_condition = if IsNaN(ph_idx == eq_length - 1) then no else ph_idx == eq_length - 1;
def pl_condition = if IsNaN(pl_idx == eq_length - 1) then no else pl_idx == eq_length - 1;
def ph;
def pl;
def isEQH;
def isEQL;
def atr = ATR(200);
if (ph_condition)
then {
ph = high;
pl = Double.NaN;
isEQH = fold i7 = 2 to 500 while (IsNaN(GetValue(ph, -(i7 - 1))) and !IsNaN(GetValue(low, -i7))) do
if Max(ph, GetValue(ph, -i7)) < Min(ph, GetValue(ph, -i7)) + atr * threshold then yes else no;
isEQL = isEQL[1];
}
else if(pl_condition) then {
ph = double.nan;
pl = low;
isEQH = isEQH[1];
isEQL = fold i8 = 2 to 500 while (IsNaN(GetValue(pl, -(i8 - 1))) and !IsNaN(GetValue(low, -i8))) do
if Min(pl, GetValue(pl, -i8)) > Max(pl, GetValue(pl, -i8)) - atr * threshold then yes else no;
}
else {
ph = double.nan;
pl = Double.NaN;
isEQH = isEQH[1];
isEQL = isEQL[1];
}
#Labels
AddChartBubble(showLabels and isEQH and !isEQH[1], ph, "EQH", CreateColor(242, 54, 69), yes);
AddChartBubble(showLabels and isEQL and !isEQL[1], pl, "EQL", CreateColor(8, 153, 129), no);
#Plots
def EQH = if isEQH and !isEQH[1] then ph else if isEQH[1] then EQH[1] else double.nan;
def EQL = if isEQL and !isEQL[1] then pl else if isEQL[1] then EQL[1] else double.nan;
plot EQHLine = EQH;
EQHLine.SetDefaultColor(CreateColor(242, 54, 69));
plot EQLLine = EQL;
EQLLine.SetDefaultColor(CreateColor(8, 153, 129));