-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullish Cypher Harmonic Patterns
153 lines (128 loc) · 11 KB
/
Bullish Cypher Harmonic Patterns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Bullish and Bearish Cypher Patterns
• Bullish cypher patterns are fundamentally composed of three troughs and two peaks, with the second peak being higher than the first peak and the second trough being higher than the first trough. The third trough must be lower than the second trough but higher than the first.
• Bearish cypher patterns are fundamentally composed of three peaks and two troughs, with the second trough being lower than the first trough and the second peak being lower than the first peak. The third peak must be higher than the second peak but lower than the first.
The most commonly recognised ratio measures used by traders today are as follows:
• Wave 1 of the pattern, referred to as XA, has no specific ratio requirements.
• Wave 2 of the pattern, referred to as AB, should retrace to at least 38.2%, but no further than 61.8% of the range set by wave 1.
• Wave 3 of the pattern, referred to as BC, should extend to at least 113%, but no further than 141.4% of the range set by wave 2.
• Wave 4 of the pattern, referred to as CD, should extend to at least 127.2%, but no further than 200% of the range set by wave 3.
• The last measure, that of wave 4 as a ratio of the range set between points X and C, referred to as XC, should retrace to 78.6%.
############################################################################################################################################
//@version=5
indicator('Bullish Cypher Harmonic Patterns', overlay = true, max_lines_count = 500, max_labels_count = 250)
shPrice = close[1] >= open[1] and close < open and high >= high[1] and barstate.isconfirmed ? high :
close[1] >= open[1] and close < open and high <= high[1] and barstate.isconfirmed ? high[1] : na
shPriceBarIndex = close[1] >= open[1] and close < open and high >= high[1] and barstate.isconfirmed ? bar_index :
close[1] >= open[1] and close < open and high <= high[1] and barstate.isconfirmed ? bar_index - 1 : na
peak = ta.valuewhen(shPrice, shPrice, 0)
peakBarIndex = ta.valuewhen(shPrice, shPriceBarIndex, 0)
shPriceOne = ta.valuewhen(shPrice, shPrice, 1)
shPriceBarIndexOne = ta.valuewhen(shPriceBarIndex, shPriceBarIndex, 1)
shPriceTwo = ta.valuewhen(shPrice, shPrice, 2)
shPriceBarIndexTwo = ta.valuewhen(shPriceBarIndex, shPriceBarIndex, 2)
slPrice = close[1] < open[1] and close >= open and low <= low[1] and barstate.isconfirmed ? low :
close[1] < open[1] and close >= open and low >= low[1] and barstate.isconfirmed ? low[1] : na
slPriceBarIndex = close[1] < open[1] and close >= open and low <= low[1] and barstate.isconfirmed ? bar_index :
close[1] < open[1] and close >= open and low >= low[1] and barstate.isconfirmed ? bar_index - 1 : na
trough = ta.valuewhen(slPrice, slPrice, 0)
troughBarIndex = ta.valuewhen(slPrice, slPriceBarIndex, 0)
slPriceOne = ta.valuewhen(slPrice, slPrice, 1)
slPriceBarIndexOne = ta.valuewhen(slPriceBarIndex, slPriceBarIndex, 1)
slPriceTwo = ta.valuewhen(slPrice, slPrice, 2)
slPriceBarIndexTwo = ta.valuewhen(slPriceBarIndex, slPriceBarIndex, 2)
returnLineUptrend = ta.valuewhen(shPrice, shPrice, 0) > ta.valuewhen(shPrice, shPrice, 1)
uptrend = ta.valuewhen(slPrice, slPrice, 0) > ta.valuewhen(slPrice, slPrice, 1)
downtrend = ta.valuewhen(shPrice, shPrice, 0) < ta.valuewhen(shPrice, shPrice, 1)
returnLineDowntrend = ta.valuewhen(slPrice, slPrice, 0) < ta.valuewhen(slPrice, slPrice, 1)
slRangeRatio = (peak - trough) / (peak - trough[1]) * 100
shRangeRatio = (peak - trough) / (peak[1] - trough) * 100
slRangeRatioZero = ta.valuewhen(slPrice, slRangeRatio, 0)
slRangeRatioOne = ta.valuewhen(slPrice, slRangeRatio, 1)
shRangeRatioZero = ta.valuewhen(shPrice, shRangeRatio, 0)
shRangeRatioOne = ta.valuewhen(shPrice, shRangeRatio, 1)
xcRangeRatio = (peak - trough) / (peak - slPriceTwo) * 100
abLowerTolerance = input(defval = 10, title = 'AB Lower Tolerance (%)', group = 'Tolerances')
abUpperTolerance = input(defval = 10, title = 'AB Upper Tolerance (%)', group = 'Tolerances')
bcLowerTolerance = input(defval = 10, title = 'BC Lower Tolerance (%)', group = 'Tolerances')
bcUpperTolerance = input(defval = 10, title = 'BC Upper Tolerance (%)', group = 'Tolerances')
cdLowerTolerance = input(defval = 10, title = 'CD Lower Tolerance (%)', group = 'Tolerances')
cdUpperTolerance = input(defval = 10, title = 'CD Upper Tolerance (%)', group = 'Tolerances')
xcLowerTolerance = input(defval = 10, title = 'XC Lower Tolerance (%)', group = 'Tolerances')
xcUpperTolerance = input(defval = 10, title = 'XC Upper Tolerance (%)', group = 'Tolerances')
bullishCypher = slPrice and returnLineDowntrend and uptrend[1] and returnLineUptrend
and slRangeRatioOne >= 38.2 - abLowerTolerance and slRangeRatioOne <= 61.8 + abUpperTolerance
and shRangeRatioZero >= 113 - bcLowerTolerance and shRangeRatioZero <= 141.4 + bcUpperTolerance
and slRangeRatio >= 127.2 - cdLowerTolerance and slRangeRatio <= 200 + cdUpperTolerance
and xcRangeRatio >= 78.6 - xcLowerTolerance and xcRangeRatio <= 78.6 + xcUpperTolerance
//////////// lines ////////////
patternColor = input(defval = color.blue, title = 'Pattern Color', group = 'Line Coloring')
labelColor = input(defval = color.blue, title = 'Label Color', group = 'Label Coloring')
showProjections = input(defval = true, title = 'Show Projections', group = 'Lines')
selectProjectionExtend = input.string(title = 'Extend Current Projection Lines', defval = 'None', options = ['None', 'Right', 'Left', 'Both'], group = "Line Extension")
extendProjectionLines = selectProjectionExtend == 'None' ? extend.none : selectProjectionExtend == 'Right' ? extend.right :
selectProjectionExtend == 'Left' ? extend.left : selectProjectionExtend == 'Both' ? extend.both : na
var currentPatternPeak = line.new(na, na, na, na, extend = extendProjectionLines, color = color.green, style = line.style_dashed)
var currentPatternTrough = line.new(na, na, na, na, extend = extendProjectionLines, color = color.red, style = line.style_dashed)
var currentPatternUpperProjection = line.new(na, na, na, na, extend = extendProjectionLines, color = color.green, style = line.style_dashed)
var currentPatternLowerProjection = line.new(na, na, na, na, extend = extendProjectionLines, color = color.red, style = line.style_dashed)
if bullishCypher
lineOne = line.new(slPriceBarIndexTwo, slPriceTwo, shPriceBarIndexOne, shPriceOne, color = patternColor, width = 2)
lineTwo = line.new(shPriceBarIndexOne, shPriceOne, slPriceBarIndexOne, slPriceOne, color = patternColor, width = 2)
lineThree = line.new(slPriceBarIndexOne, slPriceOne, peakBarIndex, peak, color = patternColor, width = 2)
lineFour = line.new(peakBarIndex, peak, slPriceBarIndex, slPrice, color = patternColor, width = 2)
lineFive = line.new(slPriceBarIndexTwo, slPriceTwo, slPriceBarIndexOne, slPriceOne, color = patternColor, style = line.style_dashed)
lineSix = line.new(slPriceBarIndexTwo, slPriceTwo, slPriceBarIndex, slPrice, color = patternColor, style = line.style_dashed)
lineSeven = line.new(slPriceBarIndexOne, slPriceOne, slPriceBarIndex, slPrice, color = patternColor, style = line.style_dashed)
lineEight = line.new(shPriceBarIndexOne, shPriceOne, peakBarIndex, peak, color = patternColor, style = line.style_dashed)
line.set_xy1(currentPatternPeak, showProjections ? peakBarIndex : na, showProjections ? peak : na)
line.set_xy2(currentPatternPeak, showProjections ? bar_index : na, showProjections ? peak : na)
line.set_xy1(currentPatternTrough, showProjections ? peakBarIndex : na, showProjections ? trough : na)
line.set_xy2(currentPatternTrough, showProjections ? bar_index : na, showProjections ? trough : na)
line.set_xy1(currentPatternUpperProjection, showProjections ? peakBarIndex : na, showProjections ? peak + (shPriceOne - slPriceTwo) : na)
line.set_xy2(currentPatternUpperProjection, showProjections ? bar_index : na, showProjections ? peak + (shPriceOne - slPriceTwo) : na)
line.set_xy1(currentPatternLowerProjection, showProjections ? peakBarIndex : na, showProjections ? trough - (shPriceOne - slPriceTwo) : na)
line.set_xy2(currentPatternLowerProjection, showProjections ? bar_index : na, showProjections ? trough - (shPriceOne - slPriceTwo) : na)
labelOne = label.new(slPriceBarIndexTwo, slPriceTwo, color = color.rgb(54, 58, 69, 100), style = label.style_label_up,
text = 'X', textcolor = labelColor)
labelTwo = label.new(shPriceBarIndexOne, shPriceOne, color = color.rgb(54, 58, 69, 100), style = label.style_label_down,
text = 'A', textcolor = labelColor)
labelThree = label.new(slPriceBarIndexOne, slPriceOne, color = color.rgb(54, 58, 69, 100), style = label.style_label_up,
text = 'B (' + str.tostring(math.round(slRangeRatioOne, 2)) + ')', textcolor = labelColor)
labelFour = label.new(peakBarIndex, peak, color = color.rgb(54, 58, 69, 100), style = label.style_label_down,
text = 'C (' + str.tostring(math.round(shRangeRatioZero, 2)) + ')', textcolor = labelColor)
labelFive = label.new(slPriceBarIndex, slPrice, color = color.rgb(54, 58, 69, 100), style = label.style_label_up,
text = 'D (' + str.tostring(math.round(slRangeRatio, 2)) + ')\n(' + str.tostring(math.round(xcRangeRatio, 2)) + ')', textcolor = labelColor)
patternPeak = line.new(showProjections ? peakBarIndex : na, showProjections ? peak : na, showProjections ? bar_index : na,
showProjections ? peak : na, color = color.green, style = line.style_dashed)
patternTrough = line.new(showProjections ? peakBarIndex : na, showProjections ? trough : na, showProjections ? bar_index : na,
showProjections ? trough : na, color = color.red, style = line.style_dashed)
patternUpperProjection = line.new(showProjections ? peakBarIndex : na, showProjections ? peak + (shPriceOne - slPriceTwo) : na, showProjections ? bar_index : na,
showProjections ? peak + (shPriceOne - slPriceTwo) : na, color = color.green, style = line.style_dashed)
patternLowerProjection = line.new(showProjections ? peakBarIndex : na, showProjections ? trough - (shPriceOne - slPriceTwo) : na, showProjections ? bar_index : na,
showProjections ? trough - (shPriceOne - slPriceTwo) : na, color = color.red, style = line.style_dashed)
var myLineArray = array.new_line()
array.push(myLineArray, lineOne)
array.push(myLineArray, lineTwo)
array.push(myLineArray, lineThree)
array.push(myLineArray, lineFour)
array.push(myLineArray, lineFive)
array.push(myLineArray, lineSix)
array.push(myLineArray, lineSeven)
array.push(myLineArray, lineEight)
array.push(myLineArray, patternPeak)
array.push(myLineArray, patternTrough)
array.push(myLineArray, patternUpperProjection)
array.push(myLineArray, patternLowerProjection)
if array.size(myLineArray) >= 500
firstLine = array.remove(myLineArray, 0)
line.delete(firstLine)
var myLabelArray = array.new_label()
array.push(myLabelArray, labelOne)
array.push(myLabelArray, labelTwo)
array.push(myLabelArray, labelThree)
array.push(myLabelArray, labelFour)
array.push(myLabelArray, labelFive)
if array.size(myLabelArray) >= 250
firstLabel = array.remove(myLabelArray, 0)
label.delete(firstLabel)
alert('Bullish Cypher')