I want to look at an X day SMA and compare it to a Y day SMA on the same universe of equities. This is the code I am using;
context.bigSMA = 50
context.littleSMA = 15
historyPrice = history(context.bigSMA*2,'1d','price')
historyOpen = history(context.bigSMA,"1d","open_price",ffill=True)
historyClose = history(context.bigSMA,"1d","close_price",ffill=True)
priceBigMean = pd.rolling_mean(historyPrice, window=context.bigSMA, min_periods=1)[context.bigSMA:context.bigSMA*2]
priceLittleMean = pd.rolling_mean(historyPrice, window=context.littleSMA, min_periods=1)[context.bigSMA:context.bigSMA*2]
littleMeanMoreThanBigMean = (priceLittleMean >= priceBigMean)
I can then loop through littleMeanMoreThanBigMean to see closing prices where the shorter SMA is more than the Longer SMA.
Does this look reasonable?