When the average closing price of previous 5 days is higher than that of 60 days, the stock price has a rise tendency, buy. Vice versa.
I try to write the code myself according to api instructions, but there's always mistake. So finally I cloned from the instruction, which works pretty fine.
Here's the algorithm unable to run backtest:
hist1 = data.history(context.security,field='price',bar_count=5,frequency='1d')
hist2 = data.history(context.security,field='price',bar_count=60,frequency='1d')
MA5 = hist1.mean()
MA60 = hist2.mean()
if MA5 > MA60:
elif MA5 < MA60: