-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSqueeze Relaxer v2.1.txt
182 lines (144 loc) · 7.22 KB
/
Squeeze Relaxer v2.1.txt
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//@version=4
// Squeeze Relaxer version 2.1
// NOTES:
// This is basically LazyBear's Squeeze Momentum Indicator but I added ADX, Keltner, WAE dead zone and RSI to into it
// LOGIC:
// If there WAS a squeeze, and now it's relaxing, plus ADX is above 19 then show a yellow diamond
// If RSI is also OS/OB then make the diamond red
// If it crosses the Keltner channel, then color is aqua
// Obviously below the price means uptrend, and vice versa
// Version 2.1updates:
// - Added WAE deadzone filtering
// - Added 5 EMAs
// - Grouped the settings, so they're easier to find
// - Changed the default values
study("Squeeze Relaxer", shorttitle="SqueezeRelax", overlay=true)
var cGreen = 0
var cRed = 0
var pos = false
var neg = false
ignoreDots = input(false, title="Ignore dots on Squeeze Indicator", group="Relaxing Settings", tooltip="Any squeeze bar is counted, no matter if it has a white dot or not")
sqTolerance = input(1, title="Squeeze Tolerance (lower = more sensitive)", group="Relaxing Settings", tooltip="How many bars to look back on the squeeze indicator")
adxValue = input(11, title="ADX Threshold", group="Relaxing Settings", tooltip="Anything over 19 filters out low volume periods. Set to 11 as a default, feel free to increase to get less noise")
showEMA1 = input(false, "Show EMA 1", group="Exponential Moving Averages")
ema1Input = input(9, "First EMA", group="Exponential Moving Averages")
showEMA2 = input(false, "Show EMA 2", group="Exponential Moving Averages")
ema2Input = input(20, "Second EMA", group="Exponential Moving Averages")
showEMA3 = input(false, "Show EMA 3", group="Exponential Moving Averages")
ema3Input = input(50, "Third EMA", group="Exponential Moving Averages")
showEMA4 = input(false, "Show EMA 4", group="Exponential Moving Averages")
ema4Input = input(100, "Fourth EMA", group="Exponential Moving Averages")
showEMA5 = input(false, "Show EMA 5", group="Exponential Moving Averages")
ema5Input = input(200, "Fifth EMA", group="Exponential Moving Averages")
uno = ema(close, ema1Input)
dos = ema(close, ema2Input)
tres = ema(close, ema3Input)
cuatro = ema(close, ema4Input)
cinco = ema(close, ema5Input)
plot(showEMA1 ? uno : na, "First", color = color.aqua)
plot(showEMA2 ? dos : na, "Second", color = color.yellow)
plot(showEMA3 ? tres : na, "Third", color = color.lime)
plot(showEMA4 ? cuatro : na, "Fourth", color = color.green)
plot(showEMA5 ? cinco : na, "Fifth", color = color.purple)
adxlen = input(14, title="ADX Smoothing", group="ADX Settings")
dilen = input(14, title="DI Length", group="ADX Settings")
rsiOver = input(66, title="RSI Oversold Value", group="RSI Settings")
rsiUnder = input(34, title="RSI Overbought Value", group="RSI Settings")
rsiLengthInput = input(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input(close, "Source", group="RSI Settings")
// Keltner Channel
mult = input(2.0, "Multiplier", group="Keltner Channel Settings")
exp = input(true, "Use Exponential MA", group="Keltner Channel Settings")
BandsStyle = input("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style", group="Keltner Channel Settings")
esma(close, length)=>
s = sma(close, 20)
e = ema(close, 20)
exp ? e : s
ma1 = esma(close, 20)
rangema1 = BandsStyle == "True Range" ? tr(true) : BandsStyle == "Average True Range" ? atr(10) : rma(high - low, 20)
upper1 = ma1 + rangema1 * mult
lower1 = ma1 - rangema1 * mult
KeltnerCross = crossover(close, upper1) or crossover(close, lower1)
// ADX
up1 = rma(max(change(rsiSourceInput), 0), rsiLengthInput)
down1 = rma(-min(change(rsiSourceInput), 0), rsiLengthInput)
rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
sigabove19 = sig > adxValue
// WAE Dead Zone
sensitivity = input(150, title="Sensitivity", group="Dead Zone (WAE) Settings")
fastLength=input(20, title="FastEMA Length", group="Dead Zone (WAE) Settings")
slowLength=input(40, title="SlowEMA Length", group="Dead Zone (WAE) Settings")
calc_macd(source, fastLength, slowLength) =>
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)
fastMA - slowMA
t1 = (calc_macd(close, fastLength, slowLength) - calc_macd(close[1], fastLength, slowLength))*sensitivity
t2 = (calc_macd(close[2], fastLength, slowLength) - calc_macd(close[3], fastLength, slowLength))*sensitivity
trendUp = (t1 >= 0) ? t1 : 0
trendDown = (t1 < 0) ? (-1*t1) : 0
// Squeeze Momentum
length = input(20, title="BB Length", group="Squeeze Momentum Settings")
multQ = input(2.0,title="BB MultFactor", group="Squeeze Momentum Settings")
lengthKC=input(20, title="KC Length", group="Squeeze Momentum Settings")
multKC = input(1.5, title="KC MultFactor", group="Squeeze Momentum Settings")
useTrueRange = true
source = close
basis = sma(source, length)
dev1 = multKC * stdev(source, length)
upperBB = basis + dev1
lowerBB = basis - dev1
ma = sma(source, lengthKC)
rangeQ = useTrueRange ? tr : (high - low)
rangema = sma(rangeQ, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = iff(ignoreDots, false, (lowerBB > lowerKC) and (upperBB < upperKC))
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
// Had to change this from the original
avg1 = avg(highest(high, lengthKC), lowest(low, lengthKC))
avg2 = avg(avg1, sma(close,lengthKC))
val = linreg(close - avg2, lengthKC, 0)
pos := false
neg := false
// if squeeze is bright RED, increment by one
if (val < nz(val[1]) and val < 5 and not sqzOn)
cRed := cRed + 1
// if squeeze is bright GREEN, increment by one
if (val > nz(val[1]) and val > 5 and not sqzOn)
cGreen := cGreen + 1
// if bright RED squeeze is now dim, momentum has changed. Is ADX also above 19? - add a marker to chart
if (val > nz(val[1]) and cRed > sqTolerance and val < 5 and not pos[1] and sigabove19 == true)
cRed := 0
pos := true
// if bright GREEN squeeze is now dim, momentum has changed. Is ADX also above 19? - add a marker to chart
if (val < nz(val[1]) and cGreen > sqTolerance and val > 5 and not neg[1] and sigabove19 == true)
cGreen := 0
neg := true
buySignal1 = pos
sellSignal1 = neg
//if ((trendUp > 0 and trendUp < deadZone) or (trendDown > 0 and trendDown < deadZone))
/// pos := false
// neg := false
// plot(trendUp)
// label.new(bar_index, high, text=tostring(trendUp))
// Basic diamond color: Yellow as default, and Red is RSI is overbought or sold
bColor = iff(rsi < rsiUnder or rsi > rsiOver, color.red, color.yellow)
// If we crossed Keltner channel, then color is Aqua
cColor = iff(KeltnerCross, color.aqua, bColor)
plotshape(buySignal1 ? pos : na, title="Buy Signal", style=shape.diamond, location=location.belowbar, color=cColor, size=size.tiny)
plotshape(sellSignal1 ? neg : na, title="Sell Signal", style=shape.diamond, location=location.abovebar, color=cColor, size=size.tiny)