# indie:lang_version = 5
from indie import indicator, plot, color, param
from indie.algorithms import Sma
@indicator('SMA Crossing', overlay_main_pane=True)
@plot.line(id='sma_slow', color=color.AQUA)
@plot.line(id='sma_fast', color=color.OLIVE)
@plot.fill('sma_slow', 'sma_fast', color=color.NAVY(0.3))
@plot.marker(style=plot.marker_style.CIRCLE,
position=plot.marker_position.CENTER, size=7,
display_options=plot.MarkerDisplayOptions(
pane=True, status_line=False, price_label=False,
),
)
@param.int('sma_len_slow', default=200)
@param.int('sma_len_fast', default=50)
def Main(self, sma_len_slow, sma_len_fast):
sma_slow = Sma.new(self.close, sma_len_slow)
sma_fast = Sma.new(self.close, sma_len_fast)
fill_color = color.GREEN(0.3)
if sma_fast[0] > sma_slow[0]:
fill_color = color.RED(0.3)
marker_color = color.rgba(0, 0, 0, 0)
if sma_fast[0] >= sma_slow[0] and sma_fast[1] < sma_slow[1]:
marker_color = color.RED
if sma_fast[0] <= sma_slow[0] and sma_fast[1] > sma_slow[1]:
marker_color = color.GREEN
return (sma_slow[0], sma_fast[0],
plot.Fill(color=fill_color),
plot.Marker(value=sma_slow[0], color=marker_color))