-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSqueeze Relaxer v2.2.txt
More file actions
executable file
·100 lines (79 loc) · 3.85 KB
/
Squeeze Relaxer v2.2.txt
File metadata and controls
executable file
·100 lines (79 loc) · 3.85 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
//@version=4
// Squeeze Relaxer version 2.2
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(0, title="Squeeze Tolerance (lower = more sensitive)", group="Relaxing Settings", tooltip="How many bars to look back on the squeeze indicator")
adxValue = input(23, 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")
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")
// 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
// 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
bColor = iff(rsi < rsiUnder or rsi > rsiOver, color.red, color.yellow)
plotshape(buySignal1 ? pos : na, title="Buy Signal", style=shape.diamond, location=location.belowbar, color=bColor, size=size.tiny)
plotshape(sellSignal1 ? neg : na, title="Sell Signal", style=shape.diamond, location=location.abovebar, color=bColor, size=size.tiny)