Overall Statistics
Total Trades
3
Average Win
0%
Average Loss
-0.02%
Compounding Annual Return
-5.528%
Drawdown
0.200%
Expectancy
-1
Net Profit
-0.042%
Sharpe Ratio
-10.937
Probabilistic Sharpe Ratio
0%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.204
Beta
0.089
Annual Standard Deviation
0.005
Annual Variance
0
Information Ratio
-37.192
Tracking Error
0.048
Treynor Ratio
-0.575
Total Fees
$3.25
Estimated Strategy Capacity
$74000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
# sample algo to develop & test consolidated data + rolling windows
# on 1min timeframe: 

from QuantConnect.Data.Market import TradeBar
from datetime import timedelta
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
import decimal as d


class MyAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2021, 8, 4)
        self.SetEndDate(2021, 8, 6)
        self.SetCash(100000) 
        self.AddEquity("SPY", Resolution.Second)

        consolidator_daily = TradeBarConsolidator(timedelta(1))
        consolidator_daily.DataConsolidated += self.OnDailyData
        self.SubscriptionManager.AddConsolidator("SPY", consolidator_daily)

        consolidator_minute = TradeBarConsolidator(60)
        consolidator_minute.DataConsolidated += self.OnMinuteData
        self.SubscriptionManager.AddConsolidator("SPY", consolidator_minute)

        self.daily_rw = RollingWindow[TradeBar](2)
        self.minute_rw = RollingWindow[TradeBar](2)
        self.window = RollingWindow[TradeBar](2)

        self.Schedule.On(self.DateRules.EveryDay(),
                         self.TimeRules.At(9, 41),
                         Action(self.ten_minutes_after_open_market))

        self.Schedule.On(self.DateRules.EveryDay(),
                         self.TimeRules.At(15, 59, 56),
                         Action(self.before_close_market))

    def OnDailyData(self, sender, bar):
        self.daily_rw.Add(bar)

    def OnMinuteData(self, sender, bar):
        self.minute_rw.Add(bar)

    def ten_minutes_after_open_market(self):
 
        if not (self.window.IsReady and self.daily_rw.IsReady and self.minute_rw.IsReady): return
        last_close = self.window[0].Close
        last_low = self.window[0].Low
        last_high = self.window[0].High
        yesterday_daily_close = self.daily_rw[1].Close
        prev_minute_low = self.minute_rw[1].Low
        prev_minute_high = self.minute_rw[1].High
        
        if not self.Portfolio["SPY"].Invested:
            # If low is greater than previous low and high is greater than previous high, buy to open
            if prev_minute_low < last_low and prev_minute_high < last_high:
                self.SetHoldings("SPY", 1)
                self.Debug('GOING LONG')
                stopMarketTicket = self.StopMarketOrder("SPY", -1, prev_minute_low - 0.01)  # stop loss at previous bar low less 1ct

            # If low is less than previous low, sell to open
            elif prev_minute_low > last_low:
                self.SetHoldings("SPY", -1)
                self.Debug('GOING SHORT')

    def before_close_market(self):
        if self.Portfolio["SPY"].Invested:
            self.Liquidate("SPY")
            self.Debug('LIQUIDATE End of Day')

    def OnData(self, data):
        if data["SPY"] is None:
            return
        self.window.Add(data["SPY"])
        if not (self.window.IsReady):
            return
        factor = 1.5

        currBar = self.window[0].Close

        if self.Portfolio["SPY"].AveragePrice * factor < currBar:
            self.Liquidate("SPY")
            self.Debug('LIQUIDATE AT THRESHOLD REACHED.')