def handle(context, data):
sr = attribute_history(g.security, g.M)['close']
ma = sr.mean()
up = ma + g.k * sr.std()
down = ma - g.k * sr.std()
p = get_current_data()[g.security].day_open
cash = context.portfolio.available_cash
if p < down and g.security not in context.portfolio.positions:
order_value(g.security, cash)
elif p > up and g.security in context.portfolio.positions:
order_target(g.security, 0)