Advertisement
Guest User

Untitled

a guest
Aug 14th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. //@version = 2
  2. // @author LazyBear
  3. //
  4. // List of my public indicators: http://bit.ly/1LQaPK8
  5. // List of my app-store indicators: http://blog.tradingview.com/?p=970
  6. //
  7.  
  8. study("Ehlers MESA Adaptive Moving Average [LazyBear]", shorttitle="EMAMA_LB", overlay = true)
  9.  
  10. src=input(hl2, title="Source")
  11. fl=input(.01, title="Fast Limit")
  12. sl=input(.001, title="Slow Limit")
  13. sp = (4*src + 3*src[1] + 2*src[2] + src[3]) / 10.0
  14. dt = (.0962*sp + .5769*nz(sp[2]) - .5769*nz(sp[4])- .0962*nz(sp[6]))*(.075*nz(p[1]) + .54)
  15. q1 = (.0962*dt + .5769*nz(dt[2]) - .5769*nz(dt[4])- .0962*nz(dt[6]))*(.075*nz(p[1]) + .54)
  16. i1 = nz(dt[3])
  17. jI = (.0962*i1 + .5769*nz(i1[2]) - .5769*nz(i1[4])- .0962*nz(i1[6]))*(.075*nz(p[1]) + .54)
  18. jq = (.0962*q1 + .5769*nz(q1[2]) - .5769*nz(q1[4])- .0962*nz(q1[6]))*(.075*nz(p[1]) + .54)
  19. i2_ = i1 - jq
  20. q2_ = q1 + jI
  21. i2 = .2*i2_ + .8*nz(i2[1])
  22. q2 = .2*q2_ + .8*nz(q2[1])
  23. re_ = i2*nz(i2[1]) + q2*nz(q2[1])
  24. im_ = i2*nz(q2[1]) - q2*nz(i2[1])
  25. re = .2*re_ + .8*nz(re[1])
  26. im = .2*im_ + .8*nz(im[1])
  27. p1 = iff(im!=0 and re!=0, 360/atan(im/re), nz(p[1]))
  28. p2 = iff(p1 > 1.5*nz(p1[1]), 1.5*nz(p1[1]), iff(p1 < 0.67*nz(p1[1]), 0.67*nz(p1[1]), p1))
  29. p3 = iff(p2<6, 6, iff (p2 > 50, 50, p2))
  30. p = .2*p3 + .8*nz(p3[1])
  31. spp = .33*p + .67*nz(spp[1])
  32. phase = atan(q1 / i1)
  33. dphase_ = nz(phase[1]) - phase
  34. dphase = iff(dphase_< 1, 1, dphase_)
  35. alpha_ = fl / dphase
  36. alpha = iff(alpha_ < sl, sl, iff(alpha_ > fl, fl, alpha_))
  37. mama = alpha*src + (1 - alpha)*nz(mama[1])
  38. fama = .5*alpha*mama + (1 - .5*alpha)*nz(fama[1])
  39. pa=input(false, title="Mark crossover points")
  40. plotarrow(pa?(cross(mama, fama)?mama<fama?-1:1:na):na, title="Crossover Markers")
  41. fr=input(false, title="Fill MAMA/FAMA Region")
  42. duml=plot(fr?(mama>fama?mama:fama):na, style=circles, color=gray, linewidth=0, title="DummyL")
  43. mamal=plot(mama, title="MAMA", color=red, linewidth=2)
  44. famal=plot(fama, title="FAMA", color=green, linewidth=2)
  45. fill(duml, mamal, red, transp=70, title="NegativeFill")
  46. fill(duml, famal, green, transp=70, title="PositiveFill")
  47. ebc=input(false, title="Enable Bar colors")
  48. bc=mama>fama?lime:red
  49. barcolor(ebc?bc:na)
  50.  
  51. longcondition = mama>fama
  52. shortcondition = mama<fama
  53.  
  54. condition = 0
  55. condition := condition[1] != 1 and longcondition ? 1 :
  56. condition[1] != -1 and shortcondition ? -1 :
  57. nz(condition[1])
  58.  
  59. enterlong = condition[1] != 1 and condition == 1
  60. entershort = condition[1] != -1 and condition == -1
  61.  
  62.  
  63.  
  64. plotshape(enterlong ? high : na, title = "LONG", text = "LONG", textcolor = white, color = green, transp = 0, style = shape.labeldown, size = size.normal,location = location.abovebar)
  65. plotshape(entershort ? low : na, title = "CLOSE", text = "CLOSE", textcolor = white, color = red, transp = 0, style = shape.labelup, size = size.normal, location = location.belowbar)
  66.  
  67. alertcondition(enterlong, title = "LONG", message = "LONG")
  68. alertcondition(entershort, title = "CLOSE", message = "CLOSE")
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement