Professional Documents
Culture Documents
Structure MXT
Structure MXT
0 at
https://mozilla.org/MPL/2.0/
// © Leviathan
// Swing point generation inspired by @BacktestRookies
//@version=5
indicator("Market Structure - By Leviathan", overlay=true, max_labels_count=500,
max_lines_count=500)
// Constants
color CLEAR = color.rgb(0,0,0,100)
// Inputs
swingSize = input.int(20, 'Swing Length', tooltip='The number of left and right
bars checked when searching for a swing point. Higher value = less swing points
plotted and lower value = more swing points plotted.' )
bosConfType = input.string('Candle Close', 'BOS Confirmation', ['Candle Close',
'Wicks'], tooltip='Choose whether candle close/wick above previous swing point
counts as a BOS.')
choch = input.bool(false, 'Show CHoCH', tooltip='Renames the first counter trend
BOS to CHoCH' )
showSwing = input.bool(true, 'Show Swing Points', tooltip='Show or hide HH, LH, HL,
LL')
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
// Calculations
bool hh = false
bool lh = false
bool hl = false
bool ll = false
//Variable to track the previous swing type, used later on to draw 0.5 Retracement
Levels (HH = 2, LH = 1, HL = -1, LL = -2)
var int prevSwing = 0
if not na(pivHi)
if pivHi >= prevHigh
hh := true
prevSwing := 2
else
lh := true
prevSwing := 1
prevHigh := pivHi
highActive := true
prevHighIndex := bar_index - swingSize
if not na(pivLo)
if pivLo >= prevLow
hl := true
prevSwing := -1
else
ll := true
prevSwing := -2
prevLow := pivLo
lowActive := true
prevLowIndex := bar_index - swingSize
// Visual Output