Overall Statistics
Total Trades
154
Average Win
0.02%
Average Loss
-0.01%
Compounding Annual Return
-0.274%
Drawdown
0.400%
Expectancy
-0.415
Net Profit
-0.289%
Sharpe Ratio
-1.84
Probabilistic Sharpe Ratio
0.338%
Loss Rate
84%
Win Rate
16%
Profit-Loss Ratio
2.75
Alpha
-0.002
Beta
-0
Annual Standard Deviation
0.001
Annual Variance
0
Information Ratio
-0.729
Tracking Error
0.124
Treynor Ratio
16.028
Total Fees
$0.00
Estimated Strategy Capacity
$280000.00
Lowest Capacity Asset
USDTUSD 2MN
# region imports
from AlgorithmImports import *
# endregion

class CryptoConsolidator(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2021, 4, 1)
        self.SetEndDate(2022, 4, 20)
        self.SetCash(1000)

        self.crypto        = self.AddCrypto("USDTUSD", Resolution.Minute, Market.FTX).Symbol

        self.min           = self.MIN(self.crypto, 5)
        self.max           = self.MAX(self.crypto, 5)
        self.prev_price    = 0.0
        self.volume_sma    = SimpleMovingAverage(5)
        self.volume_std    = StandardDeviation(5)

        self.nextEntryTime = self.Time

        self.SetWarmup(6)

    def OnData(self, data):
        price  = self.Securities[self.crypto].Close
        volume = self.Securities[self.crypto].Volume
        self.volume_sma.Update(self.Time, volume)
        self.volume_std.Update(self.Time, volume)

        if not all([indie.IsReady for indie in [self.min, self.max, self.volume_sma, self.volume_std]]):
            self.prev_price = price
            return

        if self.Time < self.nextEntryTime:
            self.prev_price = price
            return

        self.nextEntryTime += timedelta(minutes=5)

        if not self.Portfolio[self.crypto].Invested and\
            (
                (price < self.min.Current.Value) or
                (
                    (volume > (self.volume_sma.Current.Value + (2 * self.volume_std.Current.Value))) and
                    (price < self.prev_price)
                )
            ):
                self.SetHoldings(self.crypto, 1)
        elif self.Portfolio[self.crypto].Invested and\
            (
                (price >= self.max.Current.Value) or
                (
                    (volume > (self.volume_sma.Current.Value + (2 * self.volume_std.Current.Value))) and
                    (price > self.prev_price)
                )
            ):
                self.Liquidate(self.crypto)