Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. //@version=3
  2. study(title="VDI ADX", shorttitle="V-ADX")
  3.  
  4. adx_len = input(13, title="ADX Smoothing")
  5. di_len = input(13, title="DI Length")
  6. threshold = input(21, title="Trend Threshold")
  7. overextended = input(55, title="Overextension Threshold")
  8. adx_smooth = input(true)
  9. vdi_smooth = input(true)
  10. smooth_offset = input(0.9, step=0.05, minval=0.1)
  11. smooth_sigma = input(4, step=1, minval=1)
  12.  
  13. vwrma(_src, _len) =>
  14. rma(_src*volume,_len)/rma(volume,_len)
  15.  
  16. quicksmooth(x) =>
  17. qtrb1 = alma(x, 2, smooth_offset, smooth_sigma)
  18. qtrb2 = alma(x, 3, smooth_offset, smooth_sigma)
  19. qtrb3 = alma(x, 5, smooth_offset, smooth_sigma)
  20. qtrb4 = alma(x, 8, smooth_offset, smooth_sigma)
  21. output = (qtrb1+qtrb2+qtrb3+qtrb4)/4
  22.  
  23. dirmov(len) =>
  24. up = change(high)
  25. down = -change(low)
  26. plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  27. minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  28. truerange = vwrma(tr, len)
  29. plus = fixnan(100 * vwrma(plusDM, len) / truerange)
  30. minus = fixnan(100 * vwrma(minusDM, len) / truerange)
  31. [plus, minus]
  32.  
  33. [di_pos, di_neg] = dirmov(di_len)
  34.  
  35. adx(di_len, adx_len) =>
  36. sum = di_pos + di_neg
  37. output = 100 * vwrma(abs(di_pos - di_neg) / (sum == 0 ? 1 : sum), adx_len)
  38.  
  39. di_pos_line = vdi_smooth ? quicksmooth(di_pos) : di_pos
  40. di_neg_line = vdi_smooth ? quicksmooth(di_neg) : di_neg
  41.  
  42. adx_line= adx_smooth ? quicksmooth(adx(di_len, adx_len)) : adx(di_len, adx_len)
  43.  
  44. bear = #DB7093
  45. bull = #98FB98
  46. bearcloud = #DB7093
  47. bullcloud = #98FB98
  48.  
  49. forestgreen = #228B22
  50. crimson = #DC143C
  51. darkorange = #FF8C00
  52. xcolor = adx_line >= adx_line[1] ? darkorange : adx_line < adx_line[1] ? purple : black
  53.  
  54. maxLevel = highest(adx_line,200)
  55.  
  56.  
  57. //Plot Definitions
  58. plot(adx_line, color=xcolor, style=line, linewidth=3, title="ADX")
  59. p1 = plot(di_pos_line, title = 'VDI Positive Flow', color=bull, transp=60, linewidth=1, editable=false)
  60. p2 = plot(di_neg_line, title = 'VDI Negative Flow', color=bear, transp=60, linewidth=1, editable=false)
  61. fill(p1, p2, color = di_pos_line > di_neg_line ? bullcloud : bearcloud, transp=80, title="VDI fill", editable=false)
  62. plot(maxLevel, 'Maximum', linestyle=dotted, linewidth=4, color=#808080, editable=false)
  63.  
  64. hline(threshold,color=white, linewidth = 3, title="Trend Threshold")
  65. hline(overextended,color=white, linewidth = 3, title="Overextension Threshold")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement