You are on page 1of 1

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// � quantgym
study(title="Linear Regression of ADX", shorttitle="TrendFilter")

len = input(12, title="DI Length", minval=1)

lensig = input(12, title="ADX Smoothing", minval=1, maxval=50)

lenslp = input(1, title="Slope Length", minval=1)

up = change(high)

down = -change(low)

trur = rma(tr, len)

plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / trur)

minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / trur)
sum = plus + minus

adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)

hline(0, color=gray, title="Zero")

linear_reg = linreg(adx, len, 0)


linear_reg_prev = linreg(adx, len, 1)
slope = ((linear_reg-linear_reg_prev))
plot(slope, color = blue, title = "Linear Regression of ADX", style = line,
linewidth = 2)
//plot(slope, color = blue, title = "Linear Regression of ADX", style = line,
linewidth = 2)
trend=slope>0
congestion=slope<0
plot(slope >0 and slope>slope[1], color=blue, style = columns, linewidth=6)
plot(slope > 0 and slope<slope[1], color=aqua, style=columns, linewidth=6)
plot(slope<0 and slope<slope[1], color= gray, style=columns, linewidth=6)
plot(slope<0 and slope>slope[1], color=silver, style=columns, linewidth=6)

You might also like