I looked thru the postings and the last post I saw regarding this was 2016....and it stated there was not a simple way to reference the simple moving average 1 day back ?
has this changed ?
I looked thru the postings and the last post I saw regarding this was 2016....and it stated there was not a simple way to reference the simple moving average 1 day back ?
has this changed ?
Hi Blaine,
This may help:
# Displaced moving average
import talib
# ---------------------------------------
STK, ma, days_ago = symbol('SPY'), 10, 5
# ---------------------------------------
def initialize(context):
schedule_function(trade, date_rules.every_day(), time_rules.market_close())
def trade(context,data):
bars = ma + days_ago
prices = data.history(STK, 'close', bars, '1d')
mavg = talib.SMA(prices, ma)
mavg_today = round(mavg[-1], 2)
mavg_days_ago = round(mavg[-days_ago-1], 2)
record(mavg_today = mavg_today, mavg_days_ago = mavg_days_ago)