FractalTrader

[FT] ADX-Multi-TF by FractalTrader

395 0 35
Average Directional Index is a way to determine trend strength (and whether there is a trend). One of the caveats is when you have trendless conditions on a higher timeframe. You can get whipsaw conditions on the current timeframe in that case.

The purpose of this script is to put ADX into the context of a higher degree trend on a single indicator.
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
//
// @author FractalTrader
// Show ADX for current timeframe and next "Degree" higher
// Daily shows Weekly, Weekly shows Monthly, Monthly shows Quarterly, and Intraday uses a 4x multiple
// if ADX is below 20, it could be sideways choppy conditions
study("[FT] ADX-Multi-TF by FractalTrader", shorttitle="[FT]ADX-MTF")
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
choplevel = input(20, title="Chop Level", minval=1)
// get current resolution
res = interval
upper_tf = isintraday ? res >= 240 ? '2D' : tostring(res * 4) : isdaily ? 'W' : isweekly ? 'M' : ismonthly ? '3M' : 'D'
//upper_tf = 'W'
multiple = isintraday ? 4 : isdaily ? 5 : isweekly ? 4 : ismonthly ? 3 : 1

get_tr(cur_high, cur_low, prior_close) =>
    range1 = abs(cur_high - cur_low)
    range2 = abs(cur_high - prior_close)
    range3 = abs(cur_low - prior_close)
    max1 = max(range1,range2)
    get_tr = max(max1,range3)

get_vals(tf) =>
    tf_high = tf == 0 ? high : security(ticker,upper_tf,high)
    tf_low = tf == 0 ? low : security(ticker,upper_tf,low)
    tf_close = tf == 0 ? close : security(ticker,upper_tf,close)
    tf_tr = tf == 0 ? tr : get_tr(tf_high,tf_low,tf_close[1])
    [tf_high,tf_low,tf_tr]
    
dirmov(len,tf) =>
    [tf_high, tf_low, tf_tr] = get_vals(tf)
	up = change(tf_high)
	down = -change(tf_low)
	truerange = rma(tf_tr, len)
	plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
	minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
	[plus, minus]

adx(dilen, adxlen,tf) => 
	[plus, minus] = dirmov(dilen,tf)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

sig = adx(dilen, adxlen,0)
upper_sig = adx(dilen * multiple,adxlen,1)

plot(sig, color=red, title="ADX")
plot(upper_sig,color=blue,linewidth=2,title="Upper ADX")
hline(choplevel,color=black)
Ideas Scripts Chart
United States
United Kingdom
India
España
France
Italia
Polska
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Account and Billing Sign Out