finallynitin

ADX

Nov 25th, 2020 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © finally nitin
  3. //@version=4
  4.  
  5. study(title="Directional Movement Index", shorttitle="ADX", format=format.price, precision=4, resolution="")
  6. lensig = input(8, title="ADX", minval=1, maxval=50)
  7. len = input(13, title="DMI length", minval=1, maxval=50)
  8.  
  9. th = input(25, title="threshold")
  10. hline(th, title="Zero", color=color.black, linestyle=hline.style_dotted)
  11.  
  12. up = change(high)
  13. down = -change(low)
  14. plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  15. minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  16. trur = rma(tr, len)
  17. plus = fixnan(100 * rma(plusDM, len) / trur)
  18. minus = fixnan(100 * rma(minusDM, len) / trur)
  19. sum = plus + minus
  20. adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  21.  
  22. plot(adx, color=#363A45, title="ADX")
  23. plot(plus, color=#00897B, title="+DI")
  24. plot(minus, color=#FF5252, title="-DI")
Advertisement
Add Comment
Please, Sign In to add comment