Overall Statistics
Total Trades
678
Average Win
0.07%
Average Loss
-0.06%
Compounding Annual Return
-5.436%
Drawdown
9.000%
Expectancy
-0.485
Net Profit
-8.903%
Sharpe Ratio
-3.033
Probabilistic Sharpe Ratio
0.000%
Loss Rate
77%
Win Rate
23%
Profit-Loss Ratio
1.21
Alpha
-0.037
Beta
-0.001
Annual Standard Deviation
0.012
Annual Variance
0
Information Ratio
-1.04
Tracking Error
0.22
Treynor Ratio
25.439
Total Fees
$11396.78
import numpy as np

class TransdimensionalCalibratedRadiator(QCAlgorithm):

    def Initialize(self):
        
        
        #approximate QC implementation of stragety from https://www.reddit.com/r/algotrading/comments/iznj50/intraday_mean_reversion/
        
        self.SetStartDate(2019, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 8, 31)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddCrypto("BTCUSD", Resolution.Hour,Market.Bitfinex)
        self.SetBrokerageModel(BrokerageName.Bitfinex)
        
        self.last_close = RollingWindow[float](744) #keep 31 days of hourly closes
        self.last_high = RollingWindow[float](24) #keep 2 days of hourly highs
        self.last_low = RollingWindow[float](24) #keep 2 days of hourly lows
        
        self.downtrend = False
        self.uptrend = False
        
        self.trend_thresh = 5/100 #3% in the post
        
        RangeChart = Chart("Range")
        RangeChart.AddSeries(Series("31DayClose",SeriesType.Line))
        RangeChart.AddSeries(Series("24hLow",SeriesType.Line))
        RangeChart.AddSeries(Series("24hHigh",SeriesType.Line))
        RangeChart.AddSeries(Series("LastClose",SeriesType.Line))
        
        TrendChart = Chart("Trend")
        TrendChart.AddSeries(Series("TrendDirection",SeriesType.Line))
        

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        
        if self.last_close.IsReady: #the longest array is populated, otherwise we just wait and collect values as above
            
            self.Liquidate()
            
            #self.Plot("Range","31DayClose",self.last_close[743])
            #self.Plot("Range","LastClose",data['BTCUSD'].Close)
            
            if (data['BTCUSD'].Close / self.last_close[743] - 1) > self.trend_thresh: #we're in an uptrend / last_close[0] means previous close
                self.uptrend = True
                self.downtrend = False
            if (data['BTCUSD'].Close / self.last_close[743] - 1) < -self.trend_thresh: #we're in a downtrend
                self.uptrend = False
                self.downtrend = True    
                
            if self.uptrend:
                #self.Log("Uptrend @ "+str(data['BTCUSD'].Time))
                #self.Plot("Trend","TrendDirection",1)
                #self.Plot("Range","24hLow",np.min(list(self.last_low)))
                if data['BTCUSD'].Close < np.min(list(self.last_low)):#last close lower than 24 hour low
                    self.MarketOrder("BTCUSD",1)
            
            if self.downtrend:
                #self.Log("Downtrend @ "+str(data['BTCUSD'].Time))
                #self.Plot("Trend","TrendDirection",-1)
                #self.Plot("Range","24hHigh",np.max(list(self.last_high)))
                if data['BTCUSD'].Close > np.max(list(self.last_high)):#last close higher than 24 hour high
                    self.MarketOrder("BTCUSD",-1)
            
            
        self.last_high.Add(data['BTCUSD'].High)
        self.last_low.Add(data['BTCUSD'].Low)
        self.last_close.Add(data['BTCUSD'].Close)