def initialize(context):
schedule_function(myfunc, date_rules.every_day(), time_rules.market_open(minutes = 15))
def myfunc(context, data):
stk = symbol('AAPL')
Avg1 = data.history(stk, 'price', 10,'1d').mean()
Avg2 = data.history(stk, 'price', 30,'1d').mean()
current_positions = context.portfolio.positions[stk].amount
if (Avg1 > Avg2) and current_positions == 0:
order_target_percent(stk, 0.25)
elif (Avg1 < Avg2) and current_positions != 0:
order_target(stk, 0)