Hi all, was trying to use Automatic indicators in a SelectionData class, and was seeing some odd behavior, Treat this as just test code, as I was just trying to understand behavior. It is not meant to do anything particularly useful:

  1. # region imports
  2. from AlgorithmImports import *
  3. # endregion
  4. class MetricCheck(QCAlgorithm):
  5. def Initialize(self):
  6. self.EnableAutomaticIndicatorWarmUp = True
  7. self.ticker = "TWTR"
  8. self.SetStartDate(2022, 10, 1) # Set Start Date
  9. self.SetCash(100000) # Set Strategy Cash
  10. self.AddEquity("SPY", Resolution.Daily)
  11. self.AddEquity(self.ticker, Resolution.Daily)
  12. self.UniverseSettings.Resolution = Resolution.Daily
  13. self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Adjusted
  14. self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", -60), self.FillOpenPositions)
  15. symbol = self.Symbol(self.ticker)
  16. self.vsma20 = self.SMA(symbol=symbol, period=20, resolution=Resolution.Daily, selector=Field.Volume)
  17. self.sma20 = self.SMA(symbol=symbol, period=20, resolution=Resolution.Daily, selector=Field.Close)
  18. self.averages = {}
  19. def FillOpenPositions(self):
  20. symbol = self.Symbol("TWTR")
  21. self.averages[symbol] = SelectionData(self, symbol)
  22. class SelectionData():
  23. def __init__(self, algo, symbol):
  24. self.vsma20 = algo.SMA(symbol=symbol, period=20, resolution=Resolution.Daily, selector=Field.Volume)
  25. self.sma20 = algo.SMA(symbol=symbol, period=20, resolution=Resolution.Daily, selector=Field.Close)
+ Expand

Using the automatic indicators, self.vsma20 and self.sma20 in the Initialize method seem to compute correctly. The same self.vsma20 and self.sma20 in the SelectionData both give the same value (the Closing Price SMA). For some reason, the “Field.Volume” selector is being ignored in SelectionData. 

Again, the code above is just some scratchpad code that I wrote because I was seeing some strange behavior in my main algos, and wanted to isolate things.

Can anyone see what I'm doing incorrectly?

Thanks,

Chetan

Author

Chetan Prabhu

October 2022