0% found this document useful (0 votes)
87 views7 pages

SMC

This document contains a Pine Script™ code for a trading indicator called 'Structure mapping v2.0', which is designed to analyze market structure and identify key price levels. The script includes various customizable options for marking high and low pivots, structure confirmations, and drawing patterns on charts. It also implements exponential moving averages (EMAs) for additional trend analysis.

Uploaded by

Jitendra Kumar
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)
87 views7 pages

SMC

This document contains a Pine Script™ code for a trading indicator called 'Structure mapping v2.0', which is designed to analyze market structure and identify key price levels. The script includes various customizable options for marking high and low pivots, structure confirmations, and drawing patterns on charts. It also implements exponential moving averages (EMAs) for additional trend analysis.

Uploaded by

Jitendra Kumar
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/ 7

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © World_of_Indicators
//~~ Modified by World of indicators on 19/9/24

//@version=5
indicator("Structure mapping v2.0", "Structure v2.0", true,
max_bars_back = 5000, max_labels_count = 500, max_lines_count = 500)

//#region variable declaration


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
equalHL = input.bool(0,"Use equal H/L", "To calculate valid pullbacks and minor
structure", group = "Calculation method")

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


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

showMn = input.bool(0, "Mark out internal structure", group = "Internal structue")


puUpco = input.color(color.red , "High pivots", inline = "mnco", group = "Internal
structue")
puDnco = input.color(color.green, "Low pivots" , inline = "mnco", group = "Internal
structue")
showBC = input.bool(1, "Mark BoS/ChoCH", group = "BoS/Choch")
bull = input.color(color.green, "Bull color", inline = "BSclor" ,group =
"BoS/Choch")
bear = input.color(color.red , "Bear color", inline = "BSclor" ,group =
"BoS/Choch")

showbarcolor = input.bool(0,"Bar color", group = "Bar color")


showSCOB = input.bool(1, "Show SCOB pattern", group = "Bar color")
scobUp = input.color(color.aqua , "Bullish SCOB", inline = "scob" , group = "Bar
color")
scobDn = input.color(color.fuchsia, "Bearish SCOB", inline = "scob" , group = "Bar
color")

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


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

showSw = input.bool(1, "Show H/L sweeping lines", group = "H/L sweeps")


markX = input.bool(1, 'Mark "X"', group = "H/L sweeps")
swColor = input.color(color.gray, "Sweeping line color", group = "H/L sweeps")

//max line length


maxlen = bar_index - 500

//#endregion

//#region drawing functions


mnMark(bool UD) =>
if showMn
label.new(
x = UD ? puUpbar : puDnbar,
y = UD ? puUp : puDn,
yloc = UD ? yloc.abovebar : yloc.belowbar,
text = "",
color = UD ? puUpco : puDnco,
style = UD ? label.style_arrowdown : label.style_arrowup,
size = size.tiny
)

BoS_ChoCh(bool B_C, bool UpDn) =>


[HLbarid, BCprc, BCcolor, BCtxt, BCstyle] = switch
B_C == 1 and UpDn == 1 => [lastHHbar, lastHH, bull, "BoS" ,
label.style_label_down]
B_C == 0 and UpDn == 1 => [lastHbar , lastH , bull, "ChoCh",
label.style_label_down]
B_C == 0 and UpDn == 0 => [lastLbar , lastL , bear, "ChoCh",
label.style_label_up ]
B_C == 1 and UpDn == 0 => [lastLLbar, lastLL, bear, "BoS" ,
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
"🟢"
else
"🟢"
else
if L == lastLL
"🔴"
else
"🔴"
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, "🟢"]
swHL == 1 and swHrLr == 0 => [lastHbar , lastH , "🟢"]
swHL == 0 and swHrLr == 1 => [lastLbar , lastL , "🔴"]
swHL == 0 and swHrLr == 0 => [lastLLbar, lastLL, "🔴"]
swHLbarid := swHLbarid < maxlen ? maxlen : swHLbarid
//draw sweeping line
if showSw
line.new(swHLbarid,swprc,bar_index,swprc,color = swColor,style =
line.style_dotted)
if markX
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, "IDM", color = transp,
textcolor = idmColor, style = idmStyle,size = size.small)

//Bar color
ba_color = if showSCOB
if low[1] == puDn and low >= low[1] and close > high[1] and close[1] > low[2]
scobUp
else if high[1] == puUp and high <= high[1] and close < low[1] and close[1] <
high[2]
scobDn
else if showbarcolor
isCocUp?bull:bear
else
na
barcolor(ba_color,-1)
//#endregion

//#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 high > top
if low > bot
mnDn :=0
mnUp := 1
if low < bot
if high < top
mnUp := 0
mnDn := 1
if mnUp[1] and not mnUp
mnMark(1)
if mnDn[1] and not mnDn
mnMark(0)

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
H := high
Hbar := bar_index
if high > idmS
idmS := high
idmS_bar := bar_index
if high > lastH
lastH := high
lastHbar := bar_index
if high > lastHH
lastHH := high
lastHHbar := bar_index

if low < L
L := low
Lbar := bar_index
if low < idmB
idmB := low
idmB_bar := bar_index
if low < lastL
lastL := low
lastLbar := bar_index
if low < lastLL
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, "IDM", 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])

tb = table.new(position.top_right,1,1, transp, #1848cc, 1)


table.cell(tb,0,0, '',0,0, #1848cc)
//#endregion

//@version=5
// created by melihguler

len1 = input(8, title='EMA 1')


len2 = input(34, title='EMA 2')
len3 = input(89, title='EMA 3')

M1 = ta.ema(close, len1)
M2 = ta.ema(close, len2)
M3 = ta.ema(close, len3)

plot(M1, color=color.new(color.teal, 0), linewidth=2)


plot(M2, color=color.new(color.purple, 0), linewidth=2)
plot(M3, color=color.new(color.blue, 0), linewidth=4)

You might also like