Moving Avareges Cross
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ShahramAbaei

//@version=5
indicator(title = "Moving Avareges Cross", shorttitle="Moving Avareges Cross", overlay=true)

len = input(10)
o = ta.ema(open,len)
c = ta.ema(close,len)
h = ta.ema(high,len)
l = ta.ema(low,len)

haclose = 0.0
haopen = 0.0
hahigh = 0.0
halow = 0.0

haclose := (o+h+l+c)/4
haopen := na(haopen[1]) ? (o + c)/2 : (haopen[1] + haclose[1]) / 2
hahigh := math.max(h, math.max(haopen,haclose))
halow := math.min(l, math.min(haopen,haclose))

len2=input(10)
o2 = ta.ema(haopen, len2)
c2 = ta.ema(haclose, len2)
h2 = ta.ema(hahigh, len2)
l2 = ta.ema(halow, len2)

col=o2>c2 ? #ff0000 : #00ff00
plotcandle(o2, h2, l2, c2, title="heikin smoothed", color=col,wickcolor=col)

conversionPeriods = input.int(9, minval=1, title="Conversion Line Length")
basePeriods = input.int(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length")
displacement = input.int(26, minval=1, title="Displacement")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(conversionLine, color=#2962FF, title="Conversion Line",display=display.none)
plot(baseLine, color=#B71C1C, title="Base Line",display=display.none)
plot(close, offset = -displacement + 1, color=color.white, title="Lagging Span",style=plot.style_cross)
p1 = plot(leadLine1, offset = displacement - 1, color=#A5D6A7,title="Leading Span A",display=display.none)
p2 = plot(leadLine2, offset = displacement - 1, color=#EF9A9A,title="Leading Span B",display=display.none)
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(255, 255, 255, 75) : color.rgb(255, 100, 100, 75))

lenma1 = input.int(21, minval=1, title="Length")
lenma2 = input.int(233, minval=1, title="Length")
lenma3 = input.int(55, minval=1, title="Length")
src1 = input(low, title="EMA1 Source")
src2 = input(close, title="EMA2 Source")
src3 = input(close, title="EMA3 Source")
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out1 = ta.ema(src1, lenma1)
out2 = ta.ema(src2, lenma2)
out3 = ta.ema(src3, lenma3)
plot(out1, title="EMA 1", color=color.orange, offset=offset)
plot(out2, title="EMA 2", color=color.blue, offset=offset)
plot(out3, title="EMA 3", color=color.green, offset=offset,display=display.none)
