Overall Statistics
Total Trades
2239
Average Win
2.62%
Average Loss
-1.06%
Compounding Annual Return
588.874%
Drawdown
38.400%
Expectancy
0.197
Net Profit
718.176%
Sharpe Ratio
4.205
Probabilistic Sharpe Ratio
85.492%
Loss Rate
65%
Win Rate
35%
Profit-Loss Ratio
2.46
Alpha
4.78
Beta
1.02
Annual Standard Deviation
1.174
Annual Variance
1.378
Information Ratio
4.094
Tracking Error
1.168
Treynor Ratio
4.838
Total Fees
$0.00
Estimated Strategy Capacity
$480000.00
Lowest Capacity Asset
BTCUSD E3
from datetime import datetime, timedelta

class SimplePullBackStrategy(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1)  # Set Start Date
        self.InitCash = 10000
        self.SetCash(self.InitCash)
        self.profitTargetPercent = 0.02
        self.trailingStopLossPercent = 0.01
        
        btc = self.AddCrypto("BTCUSD", Resolution.Minute, Market.Bitfinex)
        self.btc = btc.Symbol
        self.SetWarmUp(14)
        
        self.entryPrice = 0
        self.period = timedelta(minutes=120)
        self.nextEntryTime = self.Time

        # relative strength index
        self.rsi = self.RSI(self.btc, 14, MovingAverageType.Wilders, Resolution.Minute)
        
        
    def OnData(self, data):
        self.price = self.Securities[self.btc].Price
        price  = self.price
        
        if not self.Portfolio.Invested:
            if self.nextEntryTime <= self.Time and self.rsi.Current.Value < 30 and not self.IsWarmingUp:
                self.SetHoldings(self.btc, 1, True)
                qty = self.Portfolio[self.btc].Quantity
                self.Log("Bought " + "{:.2f}".format(qty) + " BTC @" + str(int(price)))
                self.entryPrice = price

        elif self.entryPrice * (1 + self.profitTargetPercent) < price or self.entryPrice * (1 - self.trailingStopLossPercent) > price:
            pnl = self.Portfolio.TotalUnrealisedProfit
            qty = self.Portfolio[self.btc].Quantity
            self.Liquidate()
            self.Log("Sold " + "{:.2f}".format(qty) + " BTC @" + str(int(price)) + ' for a profit of ' + str(int(pnl)) )
            self.nextEntryTime = self.Time + self.period
    
    def OnEndOfDay(self):
        self.Plot("Price",self.price)