Overall Statistics
Total Trades
32
Average Win
33.02%
Average Loss
-3.21%
Compounding Annual Return
143.858%
Drawdown
21.500%
Expectancy
3.237
Net Profit
229.137%
Sharpe Ratio
2.961
Probabilistic Sharpe Ratio
95.675%
Loss Rate
62%
Win Rate
38%
Profit-Loss Ratio
10.30
Alpha
0.836
Beta
0.043
Annual Standard Deviation
0.319
Annual Variance
0.101
Information Ratio
-2.326
Tracking Error
0.661
Treynor Ratio
21.863
Total Fees
$11175.84
Estimated Strategy Capacity
$9400000.00
class CreativeBlueRat(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2021, 5, 1)
        self.SetCash(100000)
        self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Cash)
        
        self.AddCrypto("BTCUSD", Resolution.Daily)
        self.symbol = self.Securities["BTCUSD"].Symbol
        
        #Indicators
        self.twenty = self.EMA(self.symbol, 20, Resolution.Daily)
        self.fifty = self.EMA(self.symbol, 50, Resolution.Daily)
        self.hundred = self.EMA(self.symbol, 100, Resolution.Daily)
        #self.rsi = self.RSI(self.symbol, 14, Resolution.Daily)
        
        self.SetWarmUp(timedelta(100))
        
        self.SetBenchmark(self.symbol)
        
        self.entryTicket = None
        self.exitTicket = None
        self.entryRisk = 0
        self.entryShort = None
        self.shortRisk = 0
        self.highestPrice = 0
        
    
    def OnData(self, data):
        if self.IsWarmingUp or not (self.twenty.IsReady and self.fifty.IsReady and self.hundred.IsReady):
            return
        
        self.PlotChart()
        
        price = self.Securities[self.symbol].Price
        
        # Scan for exits
        if self.Portfolio.Invested:
            #Tailing Stopp Loss
            if price > self.highestPrice:
                self.highestPrice = price
        
            #Cut Losses
            if price <= self.fifty.Current.Value or (price < self.highestPrice * 0.95):
                    self.Liquidate(self.symbol)
                    self.Log("Sell @ " + str(price))
                    self.entryRisk = 0
                    self.highestPrice = 0
                    #self.Error("Cut Losses @ " + str(price))
        
        # Scan for entries
        else: 
            #Downtrend = Go Short not spported with this account type
            if self.twenty.Current.Value < self.fifty.Current.Value < self.hundred.Current.Value:
                return
            
            #Uptrend = Go Long
            if self.twenty.Current.Value > price > self.fifty.Current.Value > self.hundred.Current.Value:
                target_quantity = 0.9 * self.Portfolio.TotalPortfolioValue / price
                quantity = target_quantity - self.Portfolio.CashBook['BTC'].Amount
                
                self.entryTicket = self.MarketOrder(self.symbol, quantity)
                self.entryRisk = self.fifty.Current.Value
                self.highestPrice = price
                self.Log("Buy @ " + str(self.entryTicket.AverageFillPrice))
      

    def PlotChart(self):
        
        self.Plot("Benchmark", "Twenty", self.twenty.Current.Value)
        self.Plot("Benchmark", "Fifty", self.fifty.Current.Value)
        self.Plot("Benchmark", "Hundred", self.hundred.Current.Value)
        #self.Plot("RSI", "RSI",  self.rsi.Current.Value)
        #self.Plot("RSI" , "Upper-Border", 80)
        #self.Plot("RSI" , "Lower-Border", 20)