0% found this document useful (0 votes)
58 views

Structure Maping

This document defines a structure mapping indicator for identifying bullish and bearish patterns in price data. It tracks highs, lows, pullbacks and breakouts to determine structure and mark areas of support/resistance on a chart. The indicator uses various inputs to customize its drawing of structure levels, confirmation zones and sweeping lines between levels.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Structure Maping

This document defines a structure mapping indicator for identifying bullish and bearish patterns in price data. It tracks highs, lows, pullbacks and breakouts to determine structure and mark areas of support/resistance on a chart. The indicator uses various inputs to customize its drawing of structure levels, confirmation zones and sweeping lines between levels.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

//@version=5

indicator("Structure Mapping", "Structure Mapping", true, max_bars_back = 5000,


max_labels_count = 500, max_lines_count = 500)
var bool mnUp = na
var bool mnDn = na
float mnStrc = na
var top = high
var bot = low
var puUp = high
var puDn = low
var L = low
var H = high
var idmB = low
var idmS = high
var lastH = high
var lastL = low
var lastHH = high
var lastLL = low
//bar indexes
var int puUpbar = na
var int puDnbar = na
var int idmB_bar = na
var int idmS_bar = na
var int Hbar = bar_index
var int Lbar = bar_index
var int lastHbar = bar_index
var int lastLbar = bar_index
var int lastHHbar = bar_index
var int lastLLbar = bar_index

//structure confirmaions
lastHL = math.max(Hbar, Lbar)
var bool isBosUp = 0
var bool isBosDn = 0
var bool isCocUp = 1
var bool isCocDn = 1

//color
color transp = color.new(color.gray,100)

//drawing options
Gr_SM = "========= Structure Mapping ========="
equalHL = input.bool(0,"Use equal H/L to calculate", "To calculate valid pullbacks
and minor structure", group = Gr_SM)

showHL = input.bool(1, "Mark H/L", group = Gr_SM)


HLcolor = input.color(color.gray, "H/L color", group = Gr_SM)

showBC = input.bool(1, "Mark BoS/ChoCH", group = Gr_SM)


bull = input.color(color.gray, "Bull color", inline = "BSclor", group = Gr_SM)
bear = input.color(color.gray , "Bear color", inline = "BSclor", group = Gr_SM)

showIDM = input.bool(1,"Mark previous IDM", group = Gr_SM)


showliveIDM = input.bool(1,"Mark live IDM", group = Gr_SM)
idmColor = input.color(color.gray, "IDM color", group = Gr_SM)
var label lv_lbl = na
var line lv_line = na

showSw = input.bool(1, "Mark Sweeping lines", group = Gr_SM)


swColor = input.color(color.gray, "Sweeping line color", group = Gr_SM)

//max line length


maxlen = bar_index - 500

//#endregion

//#region drawing functions

BoS_ChoCh(bool B_C, bool UpDn) =>


[HLbarid, BCprc, BCcolor, BCtxt, BCstyle] = switch
B_C == 1 and UpDn == 1 => [lastHHbar, lastHH, bull, "↑↑↑" ,
label.style_label_down]
B_C == 0 and UpDn == 1 => [lastHbar , lastH , bull, "Ch ↑",
label.style_label_down]
B_C == 0 and UpDn == 0 => [lastLbar , lastL , bear, "Ch ↓",
label.style_label_up ]
B_C == 1 and UpDn == 0 => [lastLLbar, lastLL, bear, "↓↓↓" ,
label.style_label_up ]
HLbarid := HLbarid < maxlen ? maxlen : HLbarid
if showBC
line.new(HLbarid, BCprc, bar_index, BCprc, color = BCcolor, style =
line.style_dashed)
label.new(
int( math.avg(bar_index,HLbarid) ), BCprc
,BCtxt
,color = transp
,style = BCstyle
,textcolor = BCcolor
)

cfHL(bool ifHL) =>


[ifHLbarid, HLprc] = switch
ifHL =>
[Hbar, H]
=>
[Lbar, L]
ifHL_txt = if ifHL
if H == lastHH
"HH"
else
"LH"
else
if L == lastLL
"LL"
else
"HL"
cfHLStyle = ifHL ? label.style_label_down : label.style_label_up
if showHL
label.new(ifHLbarid,HLprc,ifHL_txt, color = transp, textcolor = HLcolor,
style = cfHLStyle)

sweep(bool swHL, bool swHrLr) =>


swStyle = swHL ? label.style_label_down : label.style_label_up
[swHLbarid, swprc, swHL_txt] = switch
swHL == 1 and swHrLr == 1 => [lastHHbar, lastHH, "HH"]
swHL == 1 and swHrLr == 0 => [lastHbar , lastH , "LH"]
swHL == 0 and swHrLr == 1 => [lastLbar , lastL , "HL"]
swHL == 0 and swHrLr == 0 => [lastLLbar, lastLL, "LL"]
swHLbarid := swHLbarid < maxlen ? maxlen : swHLbarid
//draw sweeping line
if showSw
line.new(swHLbarid,swprc,bar_index,swprc,color = swColor,style =
line.style_dotted)
label.new(int(math.avg(bar_index,swHLbarid)),swprc, "x", color = transp,
textcolor = swColor, style = swStyle, size = size.small)

IDM(bool BS) =>


IDMid = BS ? idmB_bar : idmS_bar
idmprc = BS ? idmB : idmS
idmStyle = BS ? label.style_label_up : label.style_label_down
IDMid := IDMid < maxlen ? maxlen : IDMid
//draw idm takeout line
if showIDM
line.new(IDMid,idmprc,bar_index,idmprc,color = idmColor,style =
line.style_dotted)
label.new(int(math.avg(bar_index,IDMid)),idmprc, "I D M", color = transp,
textcolor = idmColor, style = idmStyle,size = size.small)

//#region structure mapping


//update IDM
if high > lastH
if low < bot and close > open
if low < idmB and lastHL != Lbar
IDM(1)
cfHL(1)
isBosUp := 0
L := low
Lbar := bar_index
idmB := low
idmB_bar := bar_index
else
idmB := puDn
idmB_bar := puDnbar
if low < lastL
if high > top and close < open
if high > idmS and lastHL != Hbar
IDM(0)
cfHL(0)
isBosDn := 0
H := high
Hbar := bar_index
idmS := high
idmS_bar := bar_index
else
idmS := puUp
idmS_bar := puUpbar

//Check for IDM and ChoCh


if isCocUp and lastHL != Lbar
if low < idmB
if idmB != lastL
IDM(1)
isBosUp := 0
if high > lastH and close < open
H := high
Hbar := bar_index
lastH := H
lastHbar := Hbar
lastHH := H
lastHHbar := Hbar
cfHL(1)
L := low
Lbar := bar_index
else if lastH != lastHH and high > lastH
if close > lastH
BoS_ChoCh(0,1)
cfHL(0)
isCocDn := 0
isBosDn := 0
isCocUp := 1
else
sweep(1,0)

if isCocDn and lastHL != Hbar


if high > idmS
if idmS != lastH
IDM(0)
isBosDn := 0
if low < lastL and close > open
L := low
Lbar := bar_index
lastL := L
lastLbar := Lbar
lastLL := L
lastLLbar := Lbar
cfHL(0)
H := high
Hbar := bar_index
else if low < lastL and lastL != lastLL
if close < lastL
BoS_ChoCh(0,0)
cfHL(1)
isCocDn := 1
isCocUp := 0
isBosUp := 0
else
sweep(0,1)

//Check for BoS


if isBosUp == 0
if high > lastHH
if close > lastHH
BoS_ChoCh(1,1)
cfHL(0)
lastL := L
lastLbar := Lbar
isCocUp := 1
isBosUp := 1
isCocDn := 0
isBosDn := 0
else
sweep(1,1)
if isBosDn == 0
if low < lastLL
if close < lastLL
BoS_ChoCh(1,0)
cfHL(1)
lastH := H
lastHbar := Hbar
isCocUp := 0
isBosUp := 0
isCocDn := 1
isBosDn := 1
else
sweep(0,0)
//#endregion

//#region internal structure


if equalHL
if high >= top
if low > bot
mnDn :=0
mnUp := 1
if low <= bot
if high < top
mnUp := 0
mnDn := 1

else
if high > top
if low > bot
mnDn :=0
mnUp := 1
if low < bot
if high < top
mnUp := 0
mnDn := 1

if equalHL
if high >= top
puUp := high
puUpbar := bar_index
if low <= bot
puDn := low
puDnbar := bar_index
top := high
bot := low
if high >= top
top := high
bot := low
else
if high > top
puUp := high
puUpbar := bar_index
if low < bot
puDn := low
puDnbar := bar_index
top := high
bot := low
if high > top
top := high
bot := low
//#endregion
//#region auto update High and Low vars
if high > H or (high == H and equalHL)
H := high
Hbar := bar_index
if high > idmS
idmS := high
idmS_bar := bar_index
if high > lastH or (high == lastH and equalHL)
lastH := high
lastHbar := bar_index
if high > lastHH or (high == lastHH and equalHL)
lastHH := high
lastHHbar := bar_index

if low < L or (low == L and equalHL)


L := low
Lbar := bar_index
if low < idmB
idmB := low
idmB_bar := bar_index
if low < lastL or (low == lastL and equalHL)
lastL := low
lastLbar := bar_index
if low < lastLL or (low == lastLL and equalHL)
lastLL := low
lastLLbar := bar_index

//#endregion

//#region live IDM


if barstate.islast
if showliveIDM
[liveIDM, liveIDMbar] = if isCocUp and lastHL == Hbar
[idmB, idmB_bar]
else if isCocDn and lastHL == Lbar
[idmS, idmS_bar]
lv_line := line.new(liveIDMbar, liveIDM, bar_index + 20, liveIDM, color =
idmColor, style = line.style_dotted),
lv_lbl := label.new(bar_index + 20, liveIDM, "I D M", color = transp,
textcolor = idmColor, style = isCocUp ? label.style_label_down :
label.style_label_up, size = size.small)
else
lv_line := na
lv_lbl := na
line.delete(lv_line[1])
label.delete(lv_lbl[1])

//#endregion
// End Structure Mapping //

You might also like