Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
if statement error (please help)

I tried and tried but I can't figure out the issue. Need help, thanks.

def initialize(context):
context.csco = sid(1900)

schedule_function(when_to_sell, date_rules.every_day(), time_rules.market_open(minutes=1))  
schedule_function(buy_shares, date_rules.every_day(), time_rules.market_open(minutes=1))  
schedule_function(sell_shares, date_rules.every_day(), time_rules.market_open(minutes=1))  

def buy_shares(context, data):
order_target_percent(context.csco, 0.50)

def when_to_sell(context, data):
hist = data.history(context.csco, 'price', 15, '1m')
lego = hist.mean()
stop_price = lego + (lego*0.005)
stock_price = data.current(context.csco, 'price')
try:
if stock_price > stop_price
order_target_percent(context.csco, 0)

2 responses

Hmm.

Put a colon at the end of the if statement

if stock_price > stop_price:

Not sure why you want to use a 'try ... except' statement where you did, but you need to include the 'except' part if you do

try:  
    if stock_price > stop_price:  
        order_target_percent(context.csco, 0)  
except:  
    pass # or whatever code you want to do on an exception

Make sure all your indents are correct. Python is particular about that. See attached algorithm.

thanks