Overall Statistics
import datetime

class MorningBreakOut(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 8, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.SetTimeZone("Europe/Berlin")
        
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        
        symbols = [Symbol.Create("DE30EUR", SecurityType.Cfd, Market.Oanda)]
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
        
        #2. Set the resolution of the universe assets to daily resolution
        self.UniverseSettings.Resolution = Resolution.Minute
        
        # holds {"symbol": symbolData} instance for each symbol
        self.symbolDataBySymbol = {}
        
        self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel() )
        
        self.SetExecution( ImmediateExecutionModel() )
        
        
        
    def OnDataConsolidated(self, sender, quoteBar):
        self.Log("OnDataConsolidated called on " + str(self.Time))
        self.Log(str(quoteBar))

        
    def OnSecuritiesChanged(self, changes):
        self.Debug("SecuritiesChanged");
        # Initialize SymbolData for each symbol
        for added in changes.AddedSecurities:
            symbolData = self.symbolDataBySymbol.get(added.Symbol)
            if symbolData is None:
                symbolData = SymbolData(added, self)
                symbolData.RegisterConsolidator(self, minutes=60)
                self.symbolDataBySymbol[added.Symbol] = symbolData
                

class SymbolData:
    '''Contains data specific to a symbol required by this model'''
    def __init__(self, security, algorithm):
        self.Security = security
        self.algorithm = algorithm
        self.Symbol = security.Symbol
        self._openingBar = None
        self.oneR = None
    
    def OnDataConsolidated(self, quoteBar):
        if quoteBar.Time.hour == 9:
            self.openingBar = quoteBar
            self.algorithm.Plot("OpeningBar", "Open", self._openingBar.Open)
            self.oneR = abs(self.openingBar.High - self.openingBar.Low)
    
    def RegisterConsolidator(self, algorithm, minutes=60):
        openRangeCons = algorithm.Consolidate(self.Symbol, timedelta(minutes=minutes), self.OnDataConsolidated)
        algorithm.SubscriptionManager.AddConsolidator(self.Symbol, openRangeCons)
    
    @property
    def openingBar(self):
        return self._openingBar
        
    @openingBar.setter
    def openingBar(self, value):
        self._openingBar = value