 TMA crossover
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Lirshah

//@version=3

study(" TMA crossover", shorttitle="TMA crossover(Lirshah)", overlay=true)

length = input(title="Length1", type=integer, minval=1, defval=30)
shift=  -15
tma = sma(sma(close, ceil(length / 2)), floor(length / 2) + 1)
cl = green
plot(tma, title="TMA", linewidth=2, color=cl, transp=0, offset=shift)


//////////////////extrapolate
func (i) =>
    x = sma(sma(close, ceil((length-i) / 2)), floor((length-i) / 2) + 1)[0]
    out = (x * (length-i) + close[0]*i)/length
ld=2
trs=0
plot(func(1),color=cl,linewidth=ld, style=circles ,transp=trs,  offset=1+shift, show_last=1)
plot(func(2),color=cl,linewidth=ld, style=circles ,transp=trs,   offset=2+shift,  show_last=1)
plot(func(3),color=cl,linewidth=ld, style=circles,transp=trs,    offset=3+shift, show_last=1)
plot(func(4),color=cl,linewidth=ld, style=circles,transp=trs,    offset=4+shift, show_last=1)
plot(func(5),color=cl,linewidth=ld, style=circles,transp=trs,    offset=5+shift, show_last=1)
plot(func(6),color=cl,linewidth=ld, style=circles,transp=trs,    offset=6+shift, show_last=1)
plot(func(7),color=cl,linewidth=ld, style=circles,transp=trs,    offset=7+shift, show_last=1)
plot(func(8),color=cl,linewidth=ld, style=circles,transp=trs,    offset=8+shift, show_last=1)
plot(func(9),color=cl,linewidth=ld, style=circles,transp=trs,    offset=9+shift, show_last=1)
plot(func(10),color=cl,linewidth=ld, style=circles,transp=trs,    offset=10+shift, show_last=1)
plot(func(11),color=cl,linewidth=ld, style=circles,transp=trs,    offset=11+shift, show_last=1)
plot(func(12),color=cl,linewidth=ld, style=circles,transp=trs,    offset=12+shift, show_last=1)
plot(func(13),color=cl,linewidth=ld, style=circles,transp=trs,    offset=13+shift, show_last=1)
plot(func(14),color=cl,linewidth=ld, style=circles,transp=trs,    offset=14+shift, show_last=1)
plot(func(15),color=cl,linewidth=ld, style=circles,transp=trs,    offset=15+shift, show_last=1)
plot(func(16),color=cl,linewidth=ld, style=circles,transp=trs,    offset=16+shift, show_last=1)
plot(func(17),color=cl,linewidth=ld, style=circles,transp=trs,    offset=17+shift, show_last=1)


length2 = input(title="Length1", type=integer, minval=1, defval=30)
shift2=  -10
tma2 = sma(sma(close, ceil(length2 / 2)), floor(length2 / 2) + 1)
cl2 = red
plot(tma2, title="TMA", linewidth=2, color=cl2, transp=0, offset=shift2)


//////////////////extrapolate
func2 (i2) =>
    x2 = sma(sma(close, ceil((length2-i2) / 2)), floor((length2-i2) / 2) + 1)[0]
    out2 = (x2 * (length2-i2) + close[0]*i2)/length2

plot(func2(1),color=cl2,linewidth=ld, style=circles ,transp=trs,  offset=1+shift2, show_last=1)
plot(func2(2),color=cl2,linewidth=ld, style=circles ,transp=trs,   offset=2+shift2,  show_last=1)
plot(func2(3),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=3+shift2, show_last=1)
plot(func2(4),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=4+shift2, show_last=1)
plot(func2(5),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=5+shift2, show_last=1)
plot(func2(6),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=6+shift2, show_last=1)
plot(func2(7),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=7+shift2, show_last=1)
plot(func2(8),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=8+shift2, show_last=1)
plot(func2(9),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=9+shift2, show_last=1)
plot(func2(10),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=10+shift2, show_last=1)
plot(func2(11),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=11+shift2, show_last=1)
plot(func2(12),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=12+shift2, show_last=1)
plot(func2(13),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=13+shift2, show_last=1)
plot(func2(14),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=14+shift2, show_last=1)
plot(func2(15),color=cl2,linewidth=ld, style=circles,transp=trs,    offset=15+shift2, show_last=1)


