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
Probabilistic 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.668
Tracking Error
0.137
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# Rolling Window Consolidated Bar Data

import numpy as np

class RollingWindowBarData(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2021, 5, 1) 
        self.SetEndDate(2021, 5, 28)
        self.SetCash(10000) 
        self.SetWarmUp(10)
        self.sym = self.AddEquity('AMD', Resolution.Minute, Market.USA, True, 1, False).Symbol
        self.rollingWindow = RollingWindow[TradeBar](2)
        self.consolidator = TradeBarConsolidator(timedelta(1))
        self.Consolidate(self.sym, Resolution.Daily, self.CustomBarHandler)
        self.SubscriptionManager.AddConsolidator(self.sym, self.consolidator)
        
        
    def CustomBarHandler(self, bar):
        self.rollingWindow.Add(bar)     
        
        
    def OnData(self, data):
        if self.IsWarmingUp : return
        if not self.rollingWindow.IsReady: return
        if not (self.Time.hour == 9 and self.Time.minute == 31): return

        O = np.array([self.rollingWindow[i].Open for i in range(2)])
        C = np.array([self.rollingWindow[i].Close for i in range(2)])
        
        yesterday_close = C[0]
        today_open = self.consolidator.WorkingBar.Open

        self.Plot("Gaps", "today_gap_pct", float(100*(self.consolidator.WorkingBar.Open / C[0] -1)))
        self.Plot("Gaps", "yest_gap_pct", float(100*(O[0] / C[1] -1)))
        self.Plot("Gaps", "zero", 0.0)
        
        self.Debug(f"at {data.Time}, yest close: {yesterday_close}; today open: {today_open}")