Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study(title="Quadruple Kaufman Adaptive Moving Average", shorttitle="QKAMA4", overlay=true)
- length1 = input(14, minval=1)
- fastMA1 = input(2, minval=1)
- slowMA1 = input(20, minval=1)
- src1 = input(title="Source 1", type=input.source, defval=close)
- tf1 = input(title="Resolution 1", type=input.resolution, defval = "")
- length2 = input(14, minval=1)
- fastMA2 = input(3, minval=1)
- slowMA2 = input(30, minval=1)
- tf2 = input(title="Resolution 2", type=input.resolution, defval = "")
- src2 = input(title="Source 2", type=input.source, defval=close)
- length3 = input(14, minval=1)
- fastMA3 = input(4, minval=1)
- slowMA3 = input(40, minval=1)
- src3 = input(title="Source 3", type=input.source, defval=close)
- tf3 = input(title="Resolution 3", type=input.resolution, defval = "")
- length4 = input(14, minval=1)
- fastMA4 = input(5, minval=1)
- slowMA4 = input(50, minval=1)
- src4 = input(title="Source 4", type=input.source, defval=close)
- tf4 = input(title="Resolution 4", type=input.resolution, defval = "")
- volatility1 = sum(abs(src1-src1[1]), length1)
- volatility2 = sum(abs(src2-src2[1]), length2)
- volatility3 = sum(abs(src3-src3[1]), length3)
- volatility4 = sum(abs(src4-src4[1]), length4)
- change1 = abs(src1-src1[length1-1])
- change2 = abs(src2-src2[length2-1])
- change3 = abs(src3-src3[length3-1])
- change4 = abs(src4-src4[length4-1])
- er1 = iff(volatility1 != 0, change1/volatility1, 0)
- er2 = iff(volatility2 != 0, change2/volatility2, 0)
- er3 = iff(volatility3 != 0, change3/volatility3, 0)
- er4 = iff(volatility4 != 0, change4/volatility4, 0)
- fastSC1 = 2/(fastMA1+1)
- fastSC2 = 2/(fastMA2+1)
- fastSC3 = 2/(fastMA3+1)
- fastSC4 = 2/(fastMA4+1)
- slowSC1 = 2/(slowMA1+1)
- slowSC2 = 2/(slowMA2+1)
- slowSC3 = 2/(slowMA3+1)
- slowSC4 = 2/(slowMA4+1)
- sc1 = pow((er1*(fastSC1-slowSC1))+slowSC1, 2)
- sc2 = pow((er2*(fastSC2-slowSC2))+slowSC2, 2)
- sc3 = pow((er3*(fastSC3-slowSC3))+slowSC3, 2)
- sc4 = pow((er4*(fastSC4-slowSC4))+slowSC4, 2)
- f_k(_sc) =>
- var _k = 0.
- _k := _k + _sc * (hl2-_k)
- kamaR1 = security(syminfo.tickerid, tf1, f_k(sc1))
- kamaR2 = security(syminfo.tickerid, tf2, f_k(sc2))
- kamaR3 = security(syminfo.tickerid, tf3, f_k(sc3))
- kamaR4 = security(syminfo.tickerid, tf4, f_k(sc4))
- plot(kamaR1, color=color.yellow, title="KAMA1")
- plot(kamaR2, color=#2cfffe, title="KAMA2")
- plot(kamaR3, color=color.fuchsia, title="KAMA3")
- plot(kamaR4, color=color.red, title="KAMA4")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement