-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBearish Cypher Harmonic Patterns
158 lines (131 loc) · 11.9 KB
/
Bearish 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
154
155
156
157
158
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%.
Measurement Tolerances
In general, tolerance in measurements refers to the allowable variation or deviation from a specific value or dimension. It is the range within which a particular measurement is considered to be acceptable or accurate. In this script I have applied this concept to the measurement of harmonic pattern ratios to increase to the frequency of pattern occurrences.
For example, the AB measurement of Gartley patterns is generally set at around 61.8%, but with such specificity in the measuring requirements the patterns are very rare. We can increase the frequency of pattern occurrences by setting a tolerance. A tolerance of 10% to both downside and upside, which is the default setting for all tolerances, means we would have a tolerable measurement range between 51.8-71.8%, thus increasing the frequency of occurrence.
#########################################################################################################################################################
//@version=5
indicator('Bearish 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) / (shPriceTwo - trough) * 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')
bearishCypher = shPrice and returnLineUptrend and downtrend[1] and returnLineDowntrend
and shRangeRatioOne >= 38.2 - abLowerTolerance and shRangeRatioOne <= 61.8 + abUpperTolerance
and slRangeRatioZero >= 113 - bcLowerTolerance and slRangeRatioZero <= 141.4 + bcUpperTolerance
and shRangeRatio >= 127.2 - cdLowerTolerance and shRangeRatio <= 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 bearishCypher
lineOne = line.new(shPriceBarIndexTwo, shPriceTwo, slPriceBarIndexOne, slPriceOne, color = patternColor, width = 2)
lineTwo = line.new(slPriceBarIndexOne, slPriceOne, shPriceBarIndexOne, shPriceOne, color = patternColor, width = 2)
lineThree = line.new(shPriceBarIndexOne, shPriceOne, troughBarIndex, trough, color = patternColor, width = 2)
lineFour = line.new(troughBarIndex, trough, shPriceBarIndex, shPrice, color = patternColor, width = 2)
lineFive = line.new(shPriceBarIndexTwo, shPriceTwo, shPriceBarIndexOne, shPriceOne, color = patternColor, style = line.style_dashed)
lineSix = line.new(shPriceBarIndexTwo, shPriceTwo, shPriceBarIndex, shPrice, color = patternColor, style = line.style_dashed)
lineSeven = line.new(shPriceBarIndexOne, shPriceOne, shPriceBarIndex, shPrice, color = patternColor, style = line.style_dashed)
lineEight = line.new(slPriceBarIndexOne, slPriceOne, troughBarIndex, trough, color = patternColor, style = line.style_dashed)
line.set_xy1(currentPatternPeak, showProjections ? troughBarIndex : na, showProjections ? peak : na)
line.set_xy2(currentPatternPeak, showProjections ? bar_index : na, showProjections ? peak : na)
line.set_xy1(currentPatternTrough, showProjections ? troughBarIndex : na, showProjections ? trough : na)
line.set_xy2(currentPatternTrough, showProjections ? bar_index : na, showProjections ? trough : na)
line.set_xy1(currentPatternUpperProjection, showProjections ? troughBarIndex : na, showProjections ? peak + (shPriceTwo - slPriceOne) : na)
line.set_xy2(currentPatternUpperProjection, showProjections ? bar_index : na, showProjections ? peak + (shPriceTwo - slPriceOne) : na)
line.set_xy1(currentPatternLowerProjection, showProjections ? troughBarIndex : na, showProjections ? trough - (shPriceTwo - slPriceOne) : na)
line.set_xy2(currentPatternLowerProjection, showProjections ? bar_index : na, showProjections ? trough - (shPriceTwo - slPriceOne) : na)
labelOne = label.new(shPriceBarIndexTwo, shPriceTwo, color = color.rgb(54, 58, 69, 100), style = label.style_label_down,
text = 'X', textcolor = labelColor)
labelTwo = label.new(slPriceBarIndexOne, slPriceOne, color = color.rgb(54, 58, 69, 100), style = label.style_label_up,
text = 'A', textcolor = labelColor)
labelThree = label.new(shPriceBarIndexOne, shPriceOne, color = color.rgb(54, 58, 69, 100), style = label.style_label_down,
text = 'B (' + str.tostring(math.round(shRangeRatioOne, 2)) + ')', textcolor = labelColor)
labelFour = label.new(troughBarIndex, trough, color = color.rgb(54, 58, 69, 100), style = label.style_label_up,
text = 'C (' + str.tostring(math.round(slRangeRatioZero, 2)) + ')', textcolor = labelColor)
labelFive = label.new(shPriceBarIndex, shPrice, color = color.rgb(54, 58, 69, 100), style = label.style_label_down,
text = 'D (' + str.tostring(math.round(shRangeRatio, 2)) + ')\n(' + str.tostring(math.round(xcRangeRatio, 2)) + ')', textcolor = labelColor)
patternPeak = line.new(showProjections ? troughBarIndex : na, showProjections ? peak : na, showProjections ? bar_index : na,
showProjections ? peak : na, color = color.green, style = line.style_dashed)
patternTrough = line.new(showProjections ? troughBarIndex : na, showProjections ? trough : na, showProjections ? bar_index : na,
showProjections ? trough : na, color = color.red, style = line.style_dashed)
patternUpperProjection = line.new(showProjections ? troughBarIndex : na, showProjections ? peak + (shPriceTwo - slPriceOne) : na, showProjections ? bar_index : na,
showProjections ? peak + (shPriceTwo - slPriceOne) : na, color = color.green, style = line.style_dashed)
patternLowerProjection = line.new(showProjections ? troughBarIndex : na, showProjections ? trough - (shPriceTwo - slPriceOne) : na, showProjections ? bar_index : na,
showProjections ? trough - (shPriceTwo - slPriceOne) : 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('Bearish Cypher')