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
Sortino 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
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
from AlgorithmImports import *

class UpgradedFluorescentOrangeCaterpillar(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2024, 1, 9)  # Set Start Date
        self.SetEndDate(2024, 1, 9)
        self.SetCash(100000)  # Set Strategy Cash
        
        self.symbol = self.AddIndex("SPX", Resolution.Minute).Symbol
        
        self.rolling_window = RollingWindow[TradeBar](2)
        
        self.consolidator = TradeBarConsolidator(5)
        self.consolidator.DataConsolidated += self.consolidation_handler
        # self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)

        self.Schedule.On(self.DateRules.EveryDay(self.symbol),
               self.TimeRules.AfterMarketOpen(self.symbol.Value, 0),
               self.GetHistory)

    def GetHistory(self):
        if not self.rolling_window.IsReady:
            barCount = 2
            history = self.History(self.symbol, barCount * 5, Resolution.Minute).loc[self.symbol]
            for time, row in history.iterrows():
                tradebar = TradeBar(time, self.symbol, row.open, row.high, row.low, row.close, 0)
                self.consolidator.Update(tradebar)

    def consolidation_handler(self, sender, bar):         
        self.rolling_window.Add(bar)
        self.Log(bar.EndTime.strftime("%m/%d/%Y, %H:%M:%S") + " " + bar.Time.strftime("%m/%d/%Y, %H:%M:%S") + " " + str(bar.EndTime - bar.Time) + " " + bar.ToString())
    
    def OnEndOfAlgorithm(self):
        df = self.PandasConverter.GetDataFrame[TradeBar](self.rolling_window)
        self.Log(df.to_string())