Hey guys, I am struggling to figure out the bug in this pretty vanilla algorithm and was wondering if someone could lend some insight. Thank you for your help.
Hey guys, I am struggling to figure out the bug in this pretty vanilla algorithm and was wondering if someone could lend some insight. Thank you for your help.
Try this:
def initialize(context):
schedule_function(trade, date_rules.month_start(), time_rules.market_close(minutes = 30))
def trade(context,data):
assets = symbols('SPY', 'MDY', 'QQQ', 'SLV', 'TLT'); lev = 2.0
if get_open_orders(): return
for sec in assets:
if data.can_trade(sec):
if data.current(sec, 'price') > data.history(sec, 'price', 200, '1d').mean():
order_target_percent(sec, lev/len(assets))
else:
order_target_percent(sec, 0)
record(leverage = context.account.leverage)