Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can you guys help me to migrate to Quantopian 2

def handle_data(context, data):
price_history = data.history(context.stock, 'high', 7, '1d')
seven_bar = price_history[context.stock][-7]
six_bar = price_history[context.stock][-6]
five_bar = price_history[context.stock][-5]
four_bar = price_history[context.stock][-4]
three_bar = price_history[context.stock][-3]
two_bar = price_history[context.stock][-2]
one_bar = price_history[context.stock][-1]
print one_bar
print five_bar
print seven_bar

price_history = data.history(context.stock, 'low', 7, '1d')  
sseven_bar = price_history[context.stock][-7]  
ssix_bar = price_history[context.stock][-6]  
ffive_bar = price_history[context.stock][-5]  
ffour_bar = price_history[context.stock][-4]  
tthree_bar = price_history[context.stock][-3]  
ttwo_bar = price_history[context.stock][-2]  
oone_bar = price_history[context.stock][-1]  

high = [seven_bar, six_bar, five_bar, four_bar, three_bar, two_bar, one_bar]  
low = [sseven_bar, ssix_bar, ffive_bar, ffour_bar, tthree_bar, ttwo_bar, oone_bar]  
mw = max(high)  
lw = min(low)  
c = data.current(context.stock, 'close_price')  
wr = [(mw - c) / (mw - lw)] * 100  
if wr > 0 and wr < 20:  
    order_target_percent(context.stock, -1)  
if wr >= 20 and wr < 80:  
    order_target_percent(context.stock, 0)  
if wr >= 80:  
    order_target_percent(context.stock, 1)