Hello All,
I have a small inquiry. I know this is the way to add an indicator to a rolling window (Code 1 below):
Now, I am trying to add the indicator ADX to a 2 day rolling window (this day and the day before) for a list of stocks, say:
list = ["SPY", "TLT"] (can be longer ...)
This is what I wrote (code 2 below), gives no errors, but I still feel something might be wrong, it's not very clear how to do that in the documentation. I appreciate the help:
##############Code 1###############
# In Initialize, create the rolling windows
def Initialize(self):
# Creates an indicator and adds to a rolling window when it is updated
self.SMA("SPY", 5).Updated += self.SmaUpdated
self.smaWindow = RollingWindow[IndicatorDataPoint](5)
# Adds updated values to rolling window
def SmaUpdated(self, sender, updated):
self.smaWindow.Add(updated)
##############Code 2###############
def Initialize(self):
stocks_list = ["SPY","TLT"] for stock in stocks_list:
self.ADX(stock, 2).Updated += self.ADXUpdated
exec("self.ADXWindow_" + stock + "= RollingWindow[IndicatorDataPoint](2)")
def ADXUpdated(self, sender, updated):
stocks_list = ["SPY","TLT"]
for stock in stocks_list:
exec("self.ADXWindow_" + stock + ".Add(updated)")