-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathReversal System v1.1.txt
More file actions
executable file
·150 lines (120 loc) · 6.28 KB
/
Reversal System v1.1.txt
File metadata and controls
executable file
·150 lines (120 loc) · 6.28 KB
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
//@version=4
// Future ideas:
// Declining stairs
// Version 1.2
// - Added Bollinger Band penetration
// - Changed default RSI to 80 and 30
// Version 1.1
// - Added an additional volume pattern
// - Adjusted RSI logic so it works better
// - Added candlestick detection
// - Added option to turn off certain patterns
var cColor = color.aqua
study(title="Reversal Volume Patterns v1.2", overlay=true, shorttitle="Reversal Vol Patterns 1.2")
show1Input = input(true, "Show Pattern #1", group="Basic Settings", tooltip = "small red bar, larger red bar, small green bar")
show2Input = input(true, "Show Pattern #2", group="Basic Settings", tooltip = "small red bar, larger red bar, even LARGER red bar, small green bar")
show3Input = input(true, "Show Pattern #3", group="Basic Settings", tooltip = "4 bars of the same color, then a different color bar that's larger than all 4 previous")
show4Input = input(true, "Show Pattern #4", group="Basic Settings", tooltip = "candlestick patterns")
rsiFilter = input(true, title="Filter using RSI", tooltip = "Only show if RSI is leaning towards overbought or oversold", group="Basic Settings")
BBTolerance = input(2.0, title="Bands Pentrate Distance", tooltip = "How much penetration through the bands before triggering an alert", group="Filtering")
rsiOS = input(30, title="Flag Color Oversold Value", group="Filtering", tooltip = "IMPORTANT: This does NOT affect when flags will display, only if they'll be colored differently")
rsiOB = input(80, title="Flag Color Overbought Value", group="Filtering", tooltip = "IMPORTANT: This does NOT affect when flags will display, only if they'll be colored differently")
rsiFilterOS = input(40, title="Flag Display Oversold Value", group="Filtering", tooltip = "THIS setting is used for flag filtering")
rsiFilterOB = input(60, title="Flag Display Overbought Value", group="Filtering", tooltip = "THIS setting is used for flag filtering")
// Bollinger Bands
length = input(30, minval=1, group="Bollinger Bands")
src = input(close, title="Source", group="Bollinger Bands")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev", group="Bollinger Bands")
offset = input(0, "Offset", minval = -500, maxval = 500, group="Bollinger Bands")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
// p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
// p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
// RSI
rsiLengthInput = input(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input(close, "Source", group="RSI Settings")
is0Green = close > open
is1Green = close[1] > open[1]
is2Green = close[2] > open[2]
is3Green = close[3] > open[3]
is4Green = close[4] > open[4]
is0Red = not is0Green
is1Red = not is1Green
is2Red = not is2Green
is3Red = not is3Green
is4Red = not is4Green
// Pattern #1 - small red bar, larger red bar, small green bar
up1 = (volume[1] > volume[2] and volume < volume[1] and is0Green and is1Red and is2Red)
down1 = (volume[1] > volume[2] and volume < volume[1] and is0Red and is1Green and is2Green)
// Pattern #2 - small red bar, larger red bar, even LARGER red bar, small green bar
up2 = (volume[2] > volume[3] and volume[3] > volume[4] and volume[1] < volume[2] and volume < volume[2] and is0Green and is1Red and is2Red and is3Red and is4Red)
down2 = (volume[2] > volume[3] and volume[3] > volume[4] and volume[1] < volume[2] and volume < volume[2] and is0Red and is1Green and is2Green and is3Green and is4Green)
// Pattern #3 - 4 bars of the same color, then a different color bar that's larger than all 4 previous
up3 = (is1Red and is2Red and is3Red and is4Red and is0Green and volume > volume[1] and volume > volume[2] and volume > volume[3] and volume > volume[4])
down3 = (is1Green and is2Green and is3Green and is4Green and is0Red and volume > volume[1] and volume > volume[2] and volume > volume[3] and volume > volume[4])
// snippet from Candlestick Reversal System by LonesomeTheDove
pivotlbar = 5
highleftempty = pivothigh(pivotlbar, 0)
lowleftempty = pivotlow(pivotlbar, 0)
wick_multiplier = 10
body_percentage = 1
O = open
C = close
H = high
L = low
Wlongsignal = (C > O) and (O - L) >= ((C - O) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
(C < O) and (C - L) >= ((O - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
(C == O and C != H) and (H - L) >= ((H - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
(O == H and C == H) and (H - L) >= sma((H - L), 50)
Wshortsignal = (C < O) and (H - O) >= ((O - C) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
(C > O) and (H - C) >= ((C - O) * wick_multiplier) and (C - L) <= ((H -L) * body_percentage) or
(C == O and C != L) and (H - L) >= ((C - L) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
(O == L and C == L) and (H - L) >= sma((H - L), 50)
// Candlestick pattern is technically Pattern #4
up4 = lowleftempty and Wlongsignal
down4 = highleftempty and Wshortsignal
upsie1 = rma(max(change(rsiSourceInput), 0), rsiLengthInput)
downsie1 = rma(-min(change(rsiSourceInput), 0), rsiLengthInput)
rsi = downsie1 == 0 ? 100 : upsie1 == 0 ? 0 : 100 - (100 / (1 + upsie1 / downsie1))
BollingerCross = false
// Debugging purposes
if (up1 or down1)
cColor := color.fuchsia
if (up2 or down2)
cColor := color.purple
if (up3 or down3)
cColor := color.blue
if (up4 or down4)
cColor := color.yellow
if (not show1Input)
up1 := false
down1 := false
if (not show2Input)
up2 := false
down2 := false
if (not show3Input)
up3 := false
down3 := false
if (not show4Input)
up4 := false
down4 := false
up = (up1 or up2 or up3 or up4)
down = (down1 or down2 or down3 or down4)
bColor = color.blue
if (close < (lower - BBTolerance) or (lower - BBTolerance) and rsi < rsiOS)
bColor := color.orange
if (close > (upper + BBTolerance) or open > (upper + BBTolerance) and rsi > rsiOB)
bColor := color.lime
// eliminate dupes
if (up[1])
up := false
if (down[1])
down := false
if (rsiFilter and rsi < rsiFilterOB)
down := false
if (rsiFilter and rsi > rsiFilterOS)
up := false
plotshape(down, title="Buy Signal", style=shape.flag, location=location.abovebar, color=bColor, size=size.tiny)
plotshape(up, title="Buy Signal", style=shape.flag, location=location.belowbar, color=bColor, size=size.tiny)