Professional Documents
Culture Documents
0 at
https://mozilla.org/MPL/2.0/
// � HeWhoMustNotBeNamed
//@version=5
indicator('Multi Level ZigZag Harmonic Patterns', shorttitle='ML - ZigZag - HP',
overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500)
showZigZag2 = input(true)
zigzag2Length = input.int(2, step=1, minval=2)
zigzag2Color = input(color.olive)
zigzag2Width = 1
zigzag2Style = line.style_solid
showZigZag3 = input(true)
zigzag3Length = input.int(3, step=1, minval=2)
zigzag3Color = input(color.lime)
zigzag3Width = 1
zigzag3Style = line.style_solid
showZigZag4 = input(true)
zigzag4Length = input.int(4, step=1, minval=2)
zigzag4Color = input(color.fuchsia)
zigzag4Width = 1
zigzag4Style = line.style_solid
abcdClassic = input(true)
abEQcd = input(true)
abcdExt = input(true)
gartley = input(true)
crab = input(true)
deepCrab = input(true)
bat = input(true)
butterfly = input(true)
shark = input(true)
cypher = input(true)
threeDrives = input(true)
fiveZero = input(true)
doubleBottomTop = input(true)
errorPercent = input.int(10, minval=5, step=5, maxval=20)
MaxRiskPerReward = input.int(30, title='Max Risk Per Reward (Double Top/Bottom)',
step=10, minval=0)
waitForConfirmation = input(true)
bullishColor = input(color.green)
bearishColor = input(color.red)
pivots(length) =>
float phigh = ta.highestbars(high, length) == 0 ? high : na
float plow = ta.lowestbars(low, length) == 0 ? low : na
dir = 0
iff_1 = plow and na(phigh) ? -1 : dir[1]
dir := phigh and na(plow) ? 1 : iff_1
[dir, phigh, plow, bar_index, bar_index]
if array.size(zigzagpivots) >= 2
LastPoint = array.get(zigzagpivots, 1)
newDir := dir * value > dir * LastPoint ? dir * 2 : dir
newDir
array.unshift(zigzagpivots, value=value)
array.unshift(zigzagpivotbars, bar)
array.unshift(zigzagpivotdirs, newDir)
newZG := true
if array.size(zigzagpivots) > max_array_size
array.pop(zigzagpivots)
array.pop(zigzagpivotbars)
array.pop(zigzagpivotdirs)
newZG
c = array.get(zigzagpivots, start + 1)
cBar = array.get(zigzagpivotbars, start + 1)
cDir = array.get(zigzagpivotdirs, start + 1)
b = array.get(zigzagpivots, start + 2)
bBar = array.get(zigzagpivotbars, start + 2)
bDir = array.get(zigzagpivotdirs, start + 2)
a = array.get(zigzagpivots, start + 3)
aBar = array.get(zigzagpivotbars, start + 3)
aDir = array.get(zigzagpivotdirs, start + 3)
x = array.get(zigzagpivots, start + 4)
xBar = array.get(zigzagpivotbars, start + 4)
xDir = array.get(zigzagpivotdirs, start + 4)
y = array.get(zigzagpivots, start + 5)
yBar = array.get(zigzagpivotbars, start + 5)
yDir = array.get(zigzagpivotdirs, start + 5)
highPoint = math.max(x, a, b, c, d)
lowPoint = math.min(x, a, b, c, d)
dir = c > d ? 1 : -1
risk = math.abs(b - d)
reward = math.abs(c - d)
riskPerReward = risk * 100 / (risk + reward)
cancelW = false
cancelA = false
cancelD = false
if wm_pattern[1] and x == x[1] and a == a[1] and b == b[1] and c == c[1]
line.delete(array.get(wmlines, 0))
line.delete(array.get(wmlines, 1))
line.delete(array.get(wmlines, 2))
line.delete(array.get(wmlines, 3))
line.delete(array.get(wmlines, 4))
line.delete(array.get(wmlines, 5))
line.delete(array.get(wmlines, 6))
line.delete(array.get(wmlines, 7))
label.delete(array.get(wmlabel, 0))
cancelW := true
cancelW
if wm_pattern
xa = line.new(y1=x, y2=a, x1=xBar, x2=aBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
ab = line.new(y1=a, y2=b, x1=aBar, x2=bBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
bc = line.new(y1=b, y2=c, x1=bBar, x2=cBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
cd = line.new(y1=c, y2=d, x1=cBar, x2=dBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
xb = line.new(y1=x, y2=b, x1=xBar, x2=bBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
bd = line.new(y1=b, y2=d, x1=bBar, x2=dBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
xd = line.new(y1=x, y2=d, x1=xBar, x2=dBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
ac = line.new(y1=a, y2=c, x1=aBar, x2=cBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
array.set(wmlines, 0, xa)
array.set(wmlines, 1, ab)
array.set(wmlines, 2, bc)
array.set(wmlines, 3, cd)
array.set(wmlines, 4, xb)
array.set(wmlines, 5, bd)
array.set(wmlines, 6, xd)
array.set(wmlines, 7, ac)
array.set(wmtype, 0, dir)
if abcd_pattern and not wm_pattern
ab = line.new(y1=a, y2=b, x1=aBar, x2=bBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
bc = line.new(y1=b, y2=c, x1=bBar, x2=cBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
cd = line.new(y1=c, y2=d, x1=cBar, x2=dBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
array.set(wmlines, 1, ab)
array.set(wmlines, 2, bc)
array.set(wmlines, 3, cd)
array.set(wmtype, 0, dir)
if double_pattern and not wm_pattern
bd = line.new(y1=b, y2=d, x1=bBar, x2=dBar, color=zigzagColor,
width=zigzagWidth, style=zigzagStyle)
array.set(wmlines, 5, bd)
array.set(wmtype, 0, dir)
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// � ZenAndTheArtOfTrading / Pine Script Mastery Course
// Dynamic Structure Indicator v2.0
// Last Updated: 8th January, 2021
//indicator('Dynamic Structure Indicator v2.0', shorttitle='DSI', overlay=true)
// Get highest body and lowest body for the current candle
highestBody = open > close ? open : close
lowestBody = open > close ? close : open
// Set up our persistent S&R variables (1 = the wick and 2 = the body)
var res1 = 0.0
var res2 = 0.0
var sup1 = 0.0
var sup2 = 0.0
var lookForNewResistance = true
var lookForNewSupport = true
// Set up our *previous* support & resistance variables (for drawing support-
turned-resistance etc)
var previousRes1 = 0.0
var previousRes2 = 0.0
var previousSup1 = 0.0
var previousSup2 = 0.0
// Check if potential resistance zone has already been violated. If it has, reset
our potential R1 & R2
if close > potentialR1 and barstate.isconfirmed
potentialR1 := na
potentialR2 := na
potentialR2
// Check if potential support zone has already been violated. If it has, reset our
potential S1 & S2
if close < potentialS1 and barstate.isconfirmed
potentialS1 := na
potentialS2 := na
potentialS2
// If the previous resistance high has been violated then begin searching for a new
resistance zone
if close >= res1 and barstate.isconfirmed
lookForNewResistance := true
lookForNewSupport := true
resCount += 1
resCount
// If the previous support low has been violated then begin searching for a new
support zone
if close <= sup1 and barstate.isconfirmed
lookForNewSupport := true
lookForNewResistance := true
supCount += 1
supCount
// If our current resistance zone has been violated, store its values to draw new
*potential* support zone
// The idea being that once a major resistance zone is violated it often becomes
future support
// But we only save previous S&R if we don't already have one saved (or our zone
update count exceeds newStructureReset)
if close > res1 and na(previousRes1) and barstate.isconfirmed or previousRes1 ==
0.0 or supCount >= newStructureReset
previousRes1 := res1
previousRes2 := res2
supCount := 0
supCount
// If our current support zone has been violated, store its values to draw new
*potential* resistance zone
// The idea being that once a major support zone is violated it often becomes
future resistance
// But we only save previous S&R if we don't already have one saved (or our zone
update count exceeds newStructureReset)
if close < sup1 and na(previousSup1) and barstate.isconfirmed or previousSup1 ==
0.0 or resCount >= newStructureReset
previousSup1 := sup1
previousSup2 := sup2
resCount := 0
resCount
// If our support-turned-resistance zone has been violated, reset our saved support
variables
if close > previousSup2 and barstate.isconfirmed
previousSup1 := na
previousSup2 := na
previousSup2
// Trigger alerts
alertcondition(alertResistance or alertSupport or alertResistanceBO or
alertSupportBO, title='[DSI] Alert!', message='DSI alert for {{ticker}}')
alertcondition(alertResistance, title='[DSI] Resistance Alert', message='Price has
entered current potential resistance zone for {{ticker}}')
alertcondition(alertSupport, title='[DSI] Support Alert', message='Price has
entered current potential support zone for {{ticker}}')
alertcondition(alertResistanceBO, title='[DSI] Resistance Breakout', message='Price
has broken past potential resistance zone for {{ticker}}')
alertcondition(alertSupportBO, title='[DSI] Support Breakout', message='Price has
broken past potential support zone for {{ticker}}')