Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
calculate moving average of past days

Hi,

Newbie here.
I have read the pipeline tutorial but I don't see how I can get the history in order to add a filter for: the 200-day moving average line is trending up for at least 1 month.

I know how I would get the 200-day moving average for the day (ma_200 = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=200) but how can I calculate the moving average of the last 20 days?

Thanks

2 responses

I was able to get the moving average of n days ago but now I am trying to create a filter to check if the moving average has been trending up for x days by checking the value of one day is greater than the value of the past day.
However, when I sum the boolean value, it does not work. Any advice?
See notebook attached. Thanks

I wonder the same question. I would like to compare moving average of this day with that of 1 or 2 days ago. Have your figure out how to do it?