Overall Statistics
Total Trades
126
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
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$120000.00
Lowest Capacity Asset
BTCUSD 2MN
# Rolling Window

# --------------------------
CRYPTO = "BTCUSD"; BARS = 2; 
# --------------------------

class CryptoConsolidator(QCAlgorithm):
     
    def Initialize(self):
        self.SetStartDate(2022, 5, 2)
        self.SetEndDate(2022, 5, 3)
        self.SetCash(1000) 
        self.crypto = self.AddCrypto(CRYPTO, Resolution.Minute, Market.FTX).Symbol
        self.window = RollingWindow[TradeBar](BARS)  
        self.Consolidate(self.crypto, Resolution.Minute, self.CustomBarHandler)
        

    def CustomBarHandler(self, bar):
        self.window.Add(bar)  
        
        
    def OnData(self, data):
        if not self.window.IsReady: return

        curr_close = np.array([self.window[i].Close for i in range(BARS)])[0]                     
        past_close = np.array([self.window[i].Close for i in range(BARS)])[1]  

        self.Plot(self.crypto, "curr_close", curr_close)
        self.Plot(self.crypto, "past_close", past_close)
        
        if not self.Portfolio[self.crypto].Invested:
            if curr_close <= past_close*0.999:
                self.SetHoldings(self.crypto, 1.00 )

        elif self.Portfolio[self.crypto].Invested:
            if curr_close >= past_close*1.001:
                self.Liquidate(self.crypto,"sell")