Back to Community
How to add moving averages to pipeline?

Hello I want to put into context.long.sec a comparison between two moving averages. I want the algorithm to open long position when sma 10 > sma 30 and short positions in the opposite situations. The algorithm pasted under the post is an extract from the Sample Mean Reversion with my notes so you can understand what Im trying to do.

(I know I need to define the sma's above The algo)

Def make_pipeline(context):  
   longs = sma10 > sma30  
    Shorts= sma10 < sma30

def before_trading_start(context, data):  
 context.long_secs = context.output[context.output['longs']]

    # Sets the list of securities we want to short as the securities with a 'True'  
    # value in the high_returns column.  
    context.short_secs = context.output[context.output['shorts]]

    # A list of the securities that we want to order today.  
    context.security_list = context.long_secs.index.union(context.short_secs.index).tolist()