Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=3
  2. study(title="ADX+DMI MTF byPeterO", shorttitle="ADX+DMI MTF byPeterO")
  3. //The goal of this study was to use ADX from Higher Timeframe - to determine trend direction
  4. //Why? Because ADX is very sensitive, able to show trend ending without any delay, but not in the middle of it.
  5. //Being able to see such immediate trend change on higher timeframe, is a great indicator of trend direction.
  6. //Adding just security() calls to 'highest', 'lowest' and 'close' didn't seem right, because it produced some ugly ADX, D+ and D- plotlines.
  7. //I wanted to see plotlines, which look exactly like those on actual higher timeframe.
  8. //Therefore I modified the calculations.
  9. //
  10. //On top of all that, I added interpretation of DMI readings, because it is not as simple as plus>minus + ADXrising = uptrend.
  11. //So GREEN background means higher timeframe uptrend and RED background means downtrend.
  12.  
  13.  
  14. lenadx = input(14, minval=1, title="DI Length")
  15. lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
  16.  
  17. //mtf=input(15, title='MTF for ADX trend')
  18.  
  19. adx_mtf_dir(mtf)=>
  20.     up_mtf=highest(high,mtf)-highest(high,mtf)[mtf]
  21.     down_mtf=-(lowest(low,mtf)-lowest(low,mtf)[mtf])
  22.     plusDM_mtf = na(up_mtf) ? na : (up_mtf > down_mtf and up_mtf > 0 ? up_mtf : 0)
  23.     minusDM_mtf = na(down_mtf) ? na : (down_mtf > up_mtf and down_mtf > 0 ? down_mtf : 0)
  24.     tr_mtf = max(max(high-low, abs(high-nz(close[mtf]))), abs(low-nz(close[mtf])))
  25.     trur_mtf = rma(tr_mtf, lenadx*mtf)
  26.     plus_mtf = fixnan(100 * rma(plusDM_mtf, lenadx*mtf) / trur_mtf)
  27.     minus_mtf = fixnan(100 * rma(minusDM_mtf, lenadx*mtf) / trur_mtf)
  28.     sum_mtf = plus_mtf + minus_mtf
  29.     adx_mtf = 100 * rma(abs(plus_mtf - minus_mtf) / (sum_mtf == 0 ? 1 : sum_mtf), lensig*mtf)
  30.  
  31.     adx_mtf_direction=50, adx_mtf_direction:=nz(adx_mtf_direction[1])
  32.     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)
  33.     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)
  34.     adx_mtf_bottom_enduptrend=not rising(adx_mtf,1)[1] and rising(adx_mtf,1) and minus_mtf>plus_mtf
  35.     adx_mtf_bottom_enddowntrend=not rising(adx_mtf,1)[1] and rising(adx_mtf,1) and plus_mtf>minus_mtf
  36.     adx_mtf_switch_endofuptrend=rising(adx_mtf,1) and crossover(minus_mtf,plus_mtf)
  37.     adx_mtf_switch_endofdowntrend=rising(adx_mtf,1) and crossover(plus_mtf,minus_mtf)
  38.  
  39.     if adx_mtf_top_enduptrend
  40.         adx_mtf_direction:=20
  41.     if adx_mtf_top_enddowntrend
  42.         adx_mtf_direction:=80
  43.     if adx_mtf_bottom_enduptrend
  44.         adx_mtf_direction:=20
  45.     if adx_mtf_bottom_enddowntrend
  46.         adx_mtf_direction:=80
  47.     if adx_mtf_switch_endofuptrend
  48.         adx_mtf_direction:=20
  49.     if adx_mtf_switch_endofdowntrend
  50.         adx_mtf_direction:=80
  51.     adx_mtf_direction
  52.  
  53. adx_1=adx_mtf_dir(1)
  54. adx_3=adx_mtf_dir(3)
  55. adx_5=adx_mtf_dir(5)
  56. adx_10=adx_mtf_dir(10)
  57. adx_15=adx_mtf_dir(15)
  58.  
  59. bgcolor(adx_1==20 ? red : adx_1==80 ? lime : na, title='ADX Trend 1 min')
  60. bgcolor(adx_3==20 ? red : adx_3==80 ? lime : na, title='ADX Trend 3 min')
  61. bgcolor(adx_5==20 ? red : adx_5==80 ? lime : na, title='ADX Trend 5 min')
  62. bgcolor(adx_10==20 ? red : adx_10==80 ? lime : na, title='ADX Trend 10 min')
  63. 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