EMA/SMA Cross with Levels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jjustingreyy

//@version=5

indicator(title='EMA/SMA Cross', overlay=true)

HTF = input.timeframe('', 'TimeFrame')
short_src = input.source(close, 'Short Source', inline='short')
short_len = input.int(120, 'Length', inline='short')
long_src = input.source(close, 'Long Source', inline='long')
long_len = input.int(200, 'Length', inline='long')
last = input(5, 'Display last X lines')

short = request.security(syminfo.tickerid, HTF, ta.ema(short_src, short_len))
long = request.security(syminfo.tickerid, HTF, ta.sma(long_src, long_len))

plot(short, color=color.rgb(85, 240, 131))
plot(long, color=color.rgb(240, 97, 97))

colordots = short >= long ? color.green : color.red
plot(ta.cross(short, long) ? short : na, style=plot.style_circles, linewidth=4, color=colordots, transp=0)

lineLevel = ta.cross(short, long) ? short : na

var mylines = array.new_line(0)

if ta.cross(short, long)
    array.push(mylines, line.new(x1=bar_index - 1, y1=long, x2=bar_index, y2=long, xloc=xloc.bar_index, style=line.style_dashed, extend=extend.right, color=color.white, width=1))
    if array.size(mylines) > last
        line.delete(array.get(mylines, 0))
        array.remove(mylines, 0)