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
-11.387
Tracking Error
0.017
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
from datetime import time

class EMACrossover(QCAlgorithm):        
    def Initialize(self):    
        self.SetStartDate(2021, 5, 25)
        self.SetEndDate(2021, 6, 10)
        self.SetCash(10000)

        self.AddEquity("AMD", Resolution.Minute, Market.USA, True, 1, True)
        self.sym ="AMD"
        self.latest_consolidated_bar = None

        self.consolidator = TradeBarConsolidator(self.Customstart)
        self.consolidator.DataConsolidated += self.consolidation_handler
        
    def OnData(self, data):
        if self.latest_consolidated_bar is not None and data.Time.time() == time(9, 32):
            self.Log(f"Yesterday's close: {self.latest_consolidated_bar.Close}; Today's open: {self.consolidator.WorkingBar.Open}")
        
        
        if self.sym in data.Bars:
            bar = data.Bars[self.sym]
            time_of_day = bar.EndTime.time() 
            if time_of_day > time(9, 30) and time_of_day < time(16, 00):
                self.consolidator.Update(bar)
                
        
    def consolidation_handler(self, sender, bar):
        self.latest_consolidated_bar = bar
        self.Log(f"Consolidated bar received at {self.Time}. Consolidated start: {bar.Time}; Consolidated end: {bar.EndTime}; Bar: {bar}")
        
    def Customstart(self, dt):
        start = dt.replace(hour=9, minute=30)
        end = dt.replace(hour=16, minute=00)
        return CalendarInfo(start, end - start)