Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version = 2
- // @author LazyBear
- //
- // List of my public indicators: http://bit.ly/1LQaPK8
- // List of my app-store indicators: http://blog.tradingview.com/?p=970
- //
- study("Ehlers MESA Adaptive Moving Average [LazyBear]", shorttitle="EMAMA_LB", overlay = true)
- src=input(hl2, title="Source")
- fl=input(.01, title="Fast Limit")
- sl=input(.001, title="Slow Limit")
- sp = (4*src + 3*src[1] + 2*src[2] + src[3]) / 10.0
- dt = (.0962*sp + .5769*nz(sp[2]) - .5769*nz(sp[4])- .0962*nz(sp[6]))*(.075*nz(p[1]) + .54)
- q1 = (.0962*dt + .5769*nz(dt[2]) - .5769*nz(dt[4])- .0962*nz(dt[6]))*(.075*nz(p[1]) + .54)
- i1 = nz(dt[3])
- jI = (.0962*i1 + .5769*nz(i1[2]) - .5769*nz(i1[4])- .0962*nz(i1[6]))*(.075*nz(p[1]) + .54)
- jq = (.0962*q1 + .5769*nz(q1[2]) - .5769*nz(q1[4])- .0962*nz(q1[6]))*(.075*nz(p[1]) + .54)
- i2_ = i1 - jq
- q2_ = q1 + jI
- i2 = .2*i2_ + .8*nz(i2[1])
- q2 = .2*q2_ + .8*nz(q2[1])
- re_ = i2*nz(i2[1]) + q2*nz(q2[1])
- im_ = i2*nz(q2[1]) - q2*nz(i2[1])
- re = .2*re_ + .8*nz(re[1])
- im = .2*im_ + .8*nz(im[1])
- p1 = iff(im!=0 and re!=0, 360/atan(im/re), nz(p[1]))
- 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))
- p3 = iff(p2<6, 6, iff (p2 > 50, 50, p2))
- p = .2*p3 + .8*nz(p3[1])
- spp = .33*p + .67*nz(spp[1])
- phase = atan(q1 / i1)
- dphase_ = nz(phase[1]) - phase
- dphase = iff(dphase_< 1, 1, dphase_)
- alpha_ = fl / dphase
- alpha = iff(alpha_ < sl, sl, iff(alpha_ > fl, fl, alpha_))
- mama = alpha*src + (1 - alpha)*nz(mama[1])
- fama = .5*alpha*mama + (1 - .5*alpha)*nz(fama[1])
- pa=input(false, title="Mark crossover points")
- plotarrow(pa?(cross(mama, fama)?mama<fama?-1:1:na):na, title="Crossover Markers")
- fr=input(false, title="Fill MAMA/FAMA Region")
- duml=plot(fr?(mama>fama?mama:fama):na, style=circles, color=gray, linewidth=0, title="DummyL")
- mamal=plot(mama, title="MAMA", color=red, linewidth=2)
- famal=plot(fama, title="FAMA", color=green, linewidth=2)
- fill(duml, mamal, red, transp=70, title="NegativeFill")
- fill(duml, famal, green, transp=70, title="PositiveFill")
- ebc=input(false, title="Enable Bar colors")
- bc=mama>fama?lime:red
- barcolor(ebc?bc:na)
- longcondition = mama>fama
- shortcondition = mama<fama
- condition = 0
- condition := condition[1] != 1 and longcondition ? 1 :
- condition[1] != -1 and shortcondition ? -1 :
- nz(condition[1])
- enterlong = condition[1] != 1 and condition == 1
- entershort = condition[1] != -1 and condition == -1
- plotshape(enterlong ? high : na, title = "LONG", text = "LONG", textcolor = white, color = green, transp = 0, style = shape.labeldown, size = size.normal,location = location.abovebar)
- plotshape(entershort ? low : na, title = "CLOSE", text = "CLOSE", textcolor = white, color = red, transp = 0, style = shape.labelup, size = size.normal, location = location.belowbar)
- alertcondition(enterlong, title = "LONG", message = "LONG")
- alertcondition(entershort, title = "CLOSE", message = "CLOSE")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement