Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
SMA crossover w/ fundamental data issue

This is the code that I am running:

def initialize(context):
context.limit = 10

def before_trading_start(context, data):
context.fundamentals = get_fundamentals(
query(
fundamentals.valuation_ratios.pb_ratio,
fundamentals.asset_classification.morningstar_sector_code,
)
.filter(
fundamentals.valuation_ratios.pb_ratio < 2
)
.filter(fundamentals.asset_classification.morningstar_sector_code == 311

    .order_by(  
        fundamentals.valuation_ratios.pb_ratio.asc()  
    )  
    .limit(context.limit)  
)  

def handle_data(context, data):
price = data[context.fundamentals].price
sma50 = data[context.fundamentals].mavg(50)
sma200 = data[context.fundamentals].mavg(200)
current_positions = context.portfolio.positions

for stock in context.fundamentals:  
    if (sma50 > sma200) and current_positions == 0:  
        order_target_percent(stock, .11)  
    elif (sma50 < sma200) and current_positions > 0:  
        order_target_percent(stock, -.11)  

record(sma50 = sma50,  
       sma200 = sma200,  
       'Leverage' = context.portfolio.leverage)

I want it to trade the stocks fitting the fundamental data based off the SMA crossovers.
However, I get the following error: 21 Error SyntaxError: invalid syntax
*Btw line 21 is the def handle_data line. Thank you for the help!