Use the ExponentialWeightedMovingAverage
built in factor (see the docs https://www.quantopian.com/help#built-in-factors and scroll down a bit)
You can use an 'if' statement in the algorithm but perhaps a cleaner approach is simply define a filter within the pipeline definition.
from quantopian.pipeline.factors import SimpleMovingAverage, ExponentialWeightedMovingAverage
sma_10 = SimpleMovingAverage(
inputs=[USEquityPricing.close],
window_length = 10)
ema_10 = ExponentialWeightedMovingAverage(
inputs=[USEquityPricing.close],
window_length=30,
decay_rate=(1 - (2.0 / (1 + 15.0))),
)
sma_greater_than_ema = sma_10 > ema_10