0% found this document useful (0 votes)
59 views2 pages

Pine Script v4 ADX Function Example

The document is a TradingView Pine Script strategy named 'D2 Test' that implements the Average Directional Index (ADX) and Bollinger Bands (BB) indicators. It calculates directional movement and identifies squeeze signals based on the relationship between BB and Keltner Channels (KC). The strategy plots a diamond shape when specific conditions for a squeeze signal are met.

Uploaded by

owais aslam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views2 pages

Pine Script v4 ADX Function Example

The document is a TradingView Pine Script strategy named 'D2 Test' that implements the Average Directional Index (ADX) and Bollinger Bands (BB) indicators. It calculates directional movement and identifies squeeze signals based on the relationship between BB and Keltner Channels (KC). The strategy plots a diamond shape when specific conditions for a squeeze signal are met.

Uploaded by

owais aslam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@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=[Link])

You might also like