Luxalgo
Luxalgo
//@version=5
indicator("Market Structure with Inducements & Sweeps & Liquidity Levels
[LuxAlgo]", "LuxAlgo - Market Structure with Inducements & Sweeps & Liquidity
Levels", overlay = true, max_lines_count = 500, max_labels_count = 500)
//---------------------------------------------------------------------------------
------------------------------------}
//Settings
//---------------------------------------------------------------------------------
------------------------------------{
len = input(50, 'CHoCH Detection Period')
shortLen = input(3, 'IDM Detection Period')
//Styling
bullCss = input(#089981, 'Bullish Elements', group = 'Style')
bearCss = input(#ff5252, 'Bearish Elements', group = 'Style')
//---------------------------------------------------------------------------------
------------------------------------}
//Functions
//---------------------------------------------------------------------------------
------------------------------------{
//Swings detection/measurements
n = bar_index
swings(len)=>
var os = 0
var int topx = na
var int btmx = na
upper = ta.highest(len)
lower = ta.lowest(len)
//---------------------------------------------------------------------------------
------------------------------------}
//Swings
//---------------------------------------------------------------------------------
------------------------------------{
[top, topx, btm, btmx] = swings(len)
[stop, stopx, sbtm, sbtmx] = swings(shortLen)
var os = 0
var top_crossed = false
var btm_crossed = false
//---------------------------------------------------------------------------------
------------------------------------}
//CHoCH Detection
//---------------------------------------------------------------------------------
------------------------------------{
if top
topy := top
top_crossed := false
if btm
btmy := btm
btm_crossed := false
//Display CHoCH
if os != os[1]
max := high
min := low
max_x1 := n
min_x1 := n
stop_crossed := false
sbtm_crossed := false
if os == 1 and showChoch
line.new(topx, topy, n, topy, color = bullCss, style = line.style_dashed)
label.new(int(math.avg(n, topx)), topy, 'CHoCH', color = color(na), style =
label.style_label_down, textcolor = bullCss, size = size.tiny)
else if showChoch
line.new(btmx, btmy, n, btmy, color = bearCss, style = line.style_dashed)
label.new(int(math.avg(n, btmx)), btmy, 'CHoCH', color = color(na), style =
label.style_label_up, textcolor = bearCss, size = size.tiny)
stopy = fixnan(stop)
sbtmy = fixnan(sbtm)
//---------------------------------------------------------------------------------
------------------------------------}
//Bullish BOS
//---------------------------------------------------------------------------------
------------------------------------{
//IDM
if low < sbtmy and not sbtm_crossed and os == 1 and sbtmy != btmy
if showIdm
line.new(sbtmx, sbtmy, n, sbtmy, color = idmCss, style = line.style_dotted)
label.new(int(math.avg(n, sbtmx)), sbtmy, 'IDM', color = color(na), style =
label.style_label_up, textcolor = idmCss, size = size.tiny)
sbtm_crossed := true
//BOS
if close > max and sbtm_crossed and os == 1
if showBos
line.new(max_x1, max, n, max, color = bullCss)
label.new(int(math.avg(n, max_x1)), max, 'BOS', color = color(na), style =
label.style_label_down, textcolor = bullCss, size = size.tiny)
sbtm_crossed := false
//---------------------------------------------------------------------------------
------------------------------------}
//Bearish BOS
//---------------------------------------------------------------------------------
------------------------------------{
//IDM
if high > stopy and not stop_crossed and os == 0 and stopy != topy
if showIdm
line.new(stopx, stopy, n, stopy, color = color.gray, style = line.style_dotted)
label.new(int(math.avg(n, stopx)), stopy, 'IDM', color = color(na), style =
label.style_label_down, textcolor = color.gray, size = size.tiny)
stop_crossed := true
//BOS
if close < min and stop_crossed and os == 0
if showBos
line.new(min_x1, min, n, min, color = bearCss)
label.new(int(math.avg(n, min_x1)), min, 'BOS', color = color(na), style =
label.style_label_up, textcolor = bearCss, size = size.tiny)
stop_crossed := false
//---------------------------------------------------------------------------------
------------------------------------}
//Sweeps
//---------------------------------------------------------------------------------
------------------------------------{
if high > max and close < max and os == 1 and n - max_x1 > 1 and showSweeps
line.new(max_x1, max, n, max, color = sweepsCss, style = line.style_dotted)
label.new(int(math.avg(n, max_x1)), max, 'x', color = color(na), style =
label.style_label_down, textcolor = sweepsCss)
if low < min and close > min and os == 0 and n - min_x1 > 1 and showSweeps
line.new(min_x1, min, n, min, color = sweepsCss, style = line.style_dotted)
label.new(int(math.avg(n, min_x1)), min, 'x', color = color(na), style =
label.style_label_up, textcolor = sweepsCss)
//Trailing max/min
max := math.max(high, max)
min := math.min(low, min)
//---------------------------------------------------------------------------------
------------------------------------}
//Extensions
//---------------------------------------------------------------------------------
------------------------------------{