I'm trying to create a Rolling window of Consolidated bars so that I can compare yesterday's close to today's open to see if there was a gap up during market closed hours. When I run it and debug the values the values are way off. I'm not sure what I'm doing wrong as it seems like it should be pretty simple. I've attached the relevant code.

 

  1. from System import *
  2. from QuantConnect import *
  3. from QuantConnect.Indicators import *
  4. from QuantConnect.Data import *
  5. from QuantConnect.Data.Market import *
  6. from QuantConnect.Data.Custom import *
  7. from QuantConnect.Algorithm import *
  8. from QuantConnect.Python import *
  9. from QuantConnect import Market
  10. import pandas as pd
  11. import numpy as np
  12. import talib
  13. from collections import deque
  14. class EMACrossover(QCAlgorithm):
  15. def Initialize(self):
  16. self.SetStartDate(2020, 4, 1) # Set Start Date
  17. self.SetEndDate(2020, 7, 27)
  18. self.SetCash(10000) # Set Strategy Cash
  19. self.SetWarmUp(150)
  20. self.AddEquity("AMD", Resolution.Minute, Market.USA, True, 1, False)
  21. self.sym ="AMD"
  22. self.consolidatedwindow = RollingWindow[TradeBar](10)
  23. self.Consolidate("AMD", Resolution.Daily, lambda x: self.consolidatedwindow.Add(x))
  24. def OnData(self, data):
  25. if not all([data.Bars.ContainsKey("AMD")]):
  26. return
  27. if not (self.consolidatedwindow.IsReady):
  28. return
  29. yesterdayclose = self.consolidatedwindow[1].Close
  30. todayopen = self.consolidatedwindow[0].Open
  31. self.Debug(yesterdayclose)
  32. self.Debug(todayopen)
+ Expand

 

 

Author

Luke Algo

May 2021