-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathADX Script.txt
More file actions
executable file
·67 lines (44 loc) · 1.52 KB
/
ADX Script.txt
File metadata and controls
executable file
·67 lines (44 loc) · 1.52 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
//@version=4
strategy("D2 Test", shorttitle="D2T", overlay=true)
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
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 > 19
// END OF ADX CODE
length = input(20, title="BB Length")
multQ = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
useTrueRange = true
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
ma = sma(source, lengthKC)
rangeQ = useTrueRange ? tr : (high - low)
rangema = sma(rangeQ, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
avg1 = avg(highest(high, lengthKC), lowest(low, lengthKC))
avg2 = avg(avg1, sma(close,lengthKC))
val = linreg(close - avg2, lengthKC, 0)
colorGreen = (val > nz(val[1]))
colorRed = (val < nz(val[1]))
// END OF SQUEEZE CODE
sqzSig = (sqzOn == false) and (sigabove19 == true) and (val > 2)
plotshape(sqzSig, title="test", style=shape.diamond)