Overall Statistics
Total Orders
374
Average Win
8.76%
Average Loss
-2.45%
Compounding Annual Return
74.663%
Drawdown
41.600%
Expectancy
0.591
Start Equity
100000
End Equity
933529.54
Net Profit
833.530%
Sharpe Ratio
1.46
Sortino Ratio
1.855
Probabilistic Sharpe Ratio
68.013%
Loss Rate
65%
Win Rate
35%
Profit-Loss Ratio
3.58
Alpha
0.545
Beta
0.176
Annual Standard Deviation
0.388
Annual Variance
0.15
Information Ratio
1.084
Tracking Error
0.412
Treynor Ratio
3.22
Total Fees
$0.00
Estimated Strategy Capacity
$2200000.00
Lowest Capacity Asset
BTCUSD 2XR
Portfolio Turnover
25.51%
from AlgorithmImports import *

class TechnicalIndicatorsAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2018, 1, 1)  # Set Start Date
        self.SetEndDate(2022, 1, 1)    # Set End Date
        self.SetCash(100000)           # Set Strategy Cash
        
        # Add the cryptocurrency pair
        self.symbol = self.AddCrypto("BTCUSD", Resolution.HOUR).Symbol
        
        # Define indicators
        self.hammer = self.CandlestickPatterns.Hammer(self.symbol)
        self.hanging_man = self.CandlestickPatterns.HangingMan(self.symbol)
        self.doji = self.CandlestickPatterns.Doji(self.symbol)
        self.spinning_top = self.CandlestickPatterns.SpinningTop(self.symbol)
        self.engulfing = self.CandlestickPatterns.Engulfing(self.symbol)
        self.rsi = self.RSI(self.symbol, 14, MovingAverageType.Wilders, Resolution.HOUR)
        
        # Moving averages
        self.sma10 = self.SMA(self.symbol, 10, Resolution.HOUR)
        self.sma05 = self.SMA(self.symbol, 5, Resolution.HOUR)
        self.ema20 = self.EMA(self.symbol, 20, Resolution.HOUR)
        self.sma30 = self.SMA(self.symbol, 30, Resolution.HOUR)
        self.sma50 = self.SMA(self.symbol, 50, Resolution.HOUR)
        self.sma200 = self.SMA(self.symbol, 200, Resolution.HOUR)
        self.sma600 = self.SMA(self.symbol, 600, Resolution.HOUR)
        self.sma40 = self.SMA(self.symbol, 40, Resolution.HOUR)
        self.sma120 = self.SMA(self.symbol, 120, Resolution.HOUR)
        self.ema05 = self.EMA(self.symbol, 5, Resolution.HOUR)
        self.ema10 = self.EMA(self.symbol, 10, Resolution.HOUR)
        self.ema30 = self.EMA(self.symbol, 30, Resolution.HOUR)
        self.ema65 = self.EMA(self.symbol, 65, Resolution.HOUR)
        self.ema100 = self.EMA(self.symbol, 100, Resolution.HOUR)
        self.ema150 = self.EMA(self.symbol, 150, Resolution.HOUR)
        self.ema500 = self.EMA(self.symbol, 500, Resolution.HOUR)
        self.ema600 = self.EMA(self.symbol, 600, Resolution.HOUR)
        
        self.entry_price = None
    
    def OnData(self, data):
        if not data.ContainsKey(self.symbol):
            return
        
        price = data[self.symbol].Close
        
        # Buy condition
        if (self.rsi.Current.Value > 55) and (self.ema10.Current.Value > self.ema20.Current.Value > self.ema65.Current.Value > self.ema150.Current.Value):
            if not self.Portfolio[self.symbol].Invested:
                self.SetHoldings(self.symbol, 1)
                self.entry_price = price
               # self.stop_price = price*0.95 
        
        # Sell condition
        elif self.rsi.Current.Value < 40 and ((self.ema10.Current.Value < self.ema65.Current.Value) or (self.ema20.Current.Value < self.ema65.Current.Value)):
            if self.Portfolio[self.symbol].Invested:
                self.Liquidate(self.symbol)
                self.entry_price = None
                #self.stop_price = None 
        
        # Stop-loss condition
        if self.Portfolio[self.symbol].Invested and self.entry_price is not None:
            if price < self.entry_price*0.95:
                self.Liquidate(self.symbol)
                self.entry_price = None
         
         # Trailing stop-loss
        #if self.Portfolio[self.symbol].Invested:
        #    self.stop_price = max(self.stop_price, price * 0.85)
        #    if price < self.stop_price:
        #        self.Liquidate(self.symbol)
        #        self.stop_price = None
        
    
   # def PlotIndicators(self):
     #   self.Plot("RSI", "RSI", self.rsi.Current.Value)
     #   self.Plot("SMA", "SMA10", self.sma10.Current.Value)
     #   self.Plot("SMA", "SMA20", self.sma20.Current.Value)