I have data from SPY I want to add a 200 simple moving average, the thing is that I want to plot only a specific timeframe but I want that the moving average took all data into consideration so I can see it. Like a regular chart on tradingview when you plot the data and you see the moving average from all data but you can see how it looks on a specific length of time. This code doesn't work since I subset the data and I don't have all the range of values to calculate the indicator.
library(quantmod)
getSymbols("SPY", from="2016-01-01", to="2020-01-01")
chartSeries(SPY, subset = "2017-11-18::2017-12-16")
addSMA(n=200, on=1, col = "blue")
I want to plot the data from 2017-11-18 to 201712-16 but I want the moving average takes the values of all the available data.