Quick backtest of $SPY, 200MA as buy/sell signal
Quick backtest of $SPY, 200MA as buy/sell signal
I want to change this backtest do:
- buy amount $x when the monthly candle closes above the 200 SMA
- sell everything when it closes under the SMA 200
I put in "initiate" the line
schedule_function(month_end, date_rules.month_end())
and changed "handle_data" to "month_end".
Now there are some changes because of this old version I'm a little bit confused with:
This change works:
price = data.current(context.spy, 'price')
This one, too:
price_hist = data.history(context.spy, 'price', 200, '1d')
SMA200 = price_hist.mean()
But this doesn't work:
shortSig = data.current(context.spy, SMA200)
Can anyone help me to get this simple example run?
Thanks a lot!