Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study(title="ADX+DMI MTF byPeterO", shorttitle="ADX+DMI MTF byPeterO")
- //The goal of this study was to use ADX from Higher Timeframe - to determine trend direction
- //Why? Because ADX is very sensitive, able to show trend ending without any delay, but not in the middle of it.
- //Being able to see such immediate trend change on higher timeframe, is a great indicator of trend direction.
- //Adding just security() calls to 'highest', 'lowest' and 'close' didn't seem right, because it produced some ugly ADX, D+ and D- plotlines.
- //I wanted to see plotlines, which look exactly like those on actual higher timeframe.
- //Therefore I modified the calculations.
- //
- //On top of all that, I added interpretation of DMI readings, because it is not as simple as plus>minus + ADXrising = uptrend.
- //So GREEN background means higher timeframe uptrend and RED background means downtrend.
- lenadx = input(14, minval=1, title="DI Length")
- lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
- //mtf=input(15, title='MTF for ADX trend')
- adx_mtf_dir(mtf)=>
- up_mtf=highest(high,mtf)-highest(high,mtf)[mtf]
- down_mtf=-(lowest(low,mtf)-lowest(low,mtf)[mtf])
- plusDM_mtf = na(up_mtf) ? na : (up_mtf > down_mtf and up_mtf > 0 ? up_mtf : 0)
- minusDM_mtf = na(down_mtf) ? na : (down_mtf > up_mtf and down_mtf > 0 ? down_mtf : 0)
- tr_mtf = max(max(high-low, abs(high-nz(close[mtf]))), abs(low-nz(close[mtf])))
- trur_mtf = rma(tr_mtf, lenadx*mtf)
- plus_mtf = fixnan(100 * rma(plusDM_mtf, lenadx*mtf) / trur_mtf)
- minus_mtf = fixnan(100 * rma(minusDM_mtf, lenadx*mtf) / trur_mtf)
- sum_mtf = plus_mtf + minus_mtf
- adx_mtf = 100 * rma(abs(plus_mtf - minus_mtf) / (sum_mtf == 0 ? 1 : sum_mtf), lensig*mtf)
- adx_mtf_direction=50, adx_mtf_direction:=nz(adx_mtf_direction[1])
- adx_mtf_top_enduptrend=not falling(adx_mtf,1)[1] and falling(adx_mtf,1) and valuewhen(rising(adx_mtf,1),plus_mtf,0)>valuewhen(rising(adx_mtf,1),minus_mtf,0)
- adx_mtf_top_enddowntrend=not falling(adx_mtf,1)[1] and falling(adx_mtf,1) and valuewhen(rising(adx_mtf,1),minus_mtf,0)>valuewhen(rising(adx_mtf,1),plus_mtf,0)
- adx_mtf_bottom_enduptrend=not rising(adx_mtf,1)[1] and rising(adx_mtf,1) and minus_mtf>plus_mtf
- adx_mtf_bottom_enddowntrend=not rising(adx_mtf,1)[1] and rising(adx_mtf,1) and plus_mtf>minus_mtf
- adx_mtf_switch_endofuptrend=rising(adx_mtf,1) and crossover(minus_mtf,plus_mtf)
- adx_mtf_switch_endofdowntrend=rising(adx_mtf,1) and crossover(plus_mtf,minus_mtf)
- if adx_mtf_top_enduptrend
- adx_mtf_direction:=20
- if adx_mtf_top_enddowntrend
- adx_mtf_direction:=80
- if adx_mtf_bottom_enduptrend
- adx_mtf_direction:=20
- if adx_mtf_bottom_enddowntrend
- adx_mtf_direction:=80
- if adx_mtf_switch_endofuptrend
- adx_mtf_direction:=20
- if adx_mtf_switch_endofdowntrend
- adx_mtf_direction:=80
- adx_mtf_direction
- adx_1=adx_mtf_dir(1)
- adx_3=adx_mtf_dir(3)
- adx_5=adx_mtf_dir(5)
- adx_10=adx_mtf_dir(10)
- adx_15=adx_mtf_dir(15)
- bgcolor(adx_1==20 ? red : adx_1==80 ? lime : na, title='ADX Trend 1 min')
- bgcolor(adx_3==20 ? red : adx_3==80 ? lime : na, title='ADX Trend 3 min')
- bgcolor(adx_5==20 ? red : adx_5==80 ? lime : na, title='ADX Trend 5 min')
- bgcolor(adx_10==20 ? red : adx_10==80 ? lime : na, title='ADX Trend 10 min')
- bgcolor(adx_15==20 ? red : adx_15==80 ? lime : na, title='ADX Trend 15 min')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement