What am I doing wrong in this uber simple algo? My backtest doesnt produce any trades.
I understand that continuous futures cant be used for ordering, and you have to grab the current contract using data. current
I do this, and still no luck.
Any help would be appreciated.
Thanks in advance!
CODE:
def initialize(context):
context.crude_oil = continuous_future('CL', offset=0, roll='volume', adjustment='mul')
schedule_function(trade, date_rules.month_end(), time_rules.market_close(minutes=30))
def trade(context, data):
prices = data.history(context.crude_oil, 'price', 100, '1d')
short_MA = prices[-10:].mean()
long_MA = prices[-30:].mean()
current_contract = data.current(context.crude_oil, 'contract')
if short_MA > long_MA:
order_target_percent(current_contract, 1.0)
else:
order_target_percent(current_contract, 0.0)