Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
class main(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 7, 23) 
        self.SetEndDate(2019, 7 ,30)
        self.SetCash(100000) 
        self.priceTarget = [1,10]
        self.outstandingShares = 10e06
        self.UniverseSettings.Resolution= Resolution.Minute
        self.SetUniverseSelection(FineFundamentalUniverseSelectionModel(self.CoarseSelectionFunction, self.FineSelectionFunction, None, None))
        
        # create a dictionary to store universe selected securities and the corresponding data consolidator
        self.symbolData = {}
        
        
    def CoarseSelectionFunction(self, coarse):
        result = [x.Symbol for x in coarse if (x.HasFundamentalData and x.AdjustedPrice > self.priceTarget[0] and x.AdjustedPrice < self.priceTarget[1])]
        return [x for x in result]
    
    def FineSelectionFunction(self, fine):
        result = [x for x in fine if x.EarningReports.BasicAverageShares.OneMonth < self.outstandingShares]
        
        # Limited fine selection to 2 securities to avoid reaching the maximum of log data, and also to show security changes from day to day
        sortedresult = sorted(result, key = lambda x: x.EarningReports.BasicAverageShares.OneMonth)
        return [x.Symbol for x in sortedresult[:2]]
        
        
    def OnDataConsolidated(self, sender, bar):
        self.Log(f'Information for {sender.Consolidated.Symbol} - Open: {bar.Open}, Close: {bar.Close}, Period: {bar.Period}')   
        # access the new x minute bar here
        # write your strategy here
            
    def OnSecuritiesChanged(self, change):
        '''Event fired each time the we add/remove securities from the data feed.
        Args:
            changes: The security additions and removals from the algorithm'''
    
        for added in change.AddedSecurities:
            self.symbolData[added.Symbol] = SymbolData(added)
            
            self.symbolData[added.Symbol].xMinuteConsolidator.DataConsolidated += self.OnDataConsolidated
            self.SubscriptionManager.AddConsolidator(added.Symbol, self.symbolData[added.Symbol].xMinuteConsolidator)
        
        for removed in change.RemovedSecurities:
            data = self.symbolData.pop(removed.Symbol, None)
            
            if data is not None:
                #clean up the consolidator from previous universe selection
                self.SubscriptionManager.RemoveConsolidator(removed.Symbol, data.xMinuteConsolidator)
        
    
class SymbolData:
    def __init__(self, security):
        
        self.Security = security
        # The consolidator is set to 30 minute in order to show security changes from day to day, but you can simply change 'minute = 5' to get your desired 5 minute bars.
        self.xMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30))