Overall Statistics
Total Trades
50
Average Win
5.54%
Average Loss
-4.57%
Compounding Annual Return
187.407%
Drawdown
19.800%
Expectancy
0.504
Net Profit
67.722%
Sharpe Ratio
3.205
Probabilistic Sharpe Ratio
83.447%
Loss Rate
32%
Win Rate
68%
Profit-Loss Ratio
1.21
Alpha
1.104
Beta
0.635
Annual Standard Deviation
0.386
Annual Variance
0.149
Information Ratio
2.703
Tracking Error
0.38
Treynor Ratio
1.946
Total Fees
$0.00
Estimated Strategy Capacity
$14000000.00
Lowest Capacity Asset
BTCUSD XJ
Portfolio Turnover
18.43%
from AlgorithmImports import *


class RetrospectiveYellowGreenAlligator(QCAlgorithm):

    def Initialize(self):
        # INITIALIZE
        self.SetStartDate(2023, 1, 1)
        self.SetEndDate(2023, 6, 28)
        self._cash = 100000
        self.SetCash(self._cash)

        self.ticker = "BTCUSD"
        self.AddCrypto(self.ticker, Resolution.Daily, Market.GDAX,).Symbol

        # SET BENCHMARK AND PREPARE COMPARATIVE PLOT
        self.reference_ticker = self.History(self.Symbol(self.ticker), 10, Resolution.Daily)['close']
        self._initialValue_ticker = self.reference_ticker.iloc[0]

        # SET Candlestick patterns 
        self.hammer = self.CandlestickPatterns.Hammer(self.ticker, Resolution.Daily)
        self.hangingman = self.CandlestickPatterns.HangingMan(self.ticker, Resolution.Daily)
         
         
        # Risk management
        self.AddRiskManagement(TrailingStopRiskManagementModel(0.06))
        self.Debug("Stop loss hit")
        self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(0.05))
        self.Debug("Drawdown limit hit")

    def OnData(self, data):
        price = self.Securities[self.ticker].Close
 
        if self.hangingman.Current.Value == -1:
            self.SetHoldings(self.ticker, -1)
            self.Debug("Hanging man candle")
        
        if self.hammer.Current.Value == 1:
            self.SetHoldings(self.ticker, 1)
            self.Debug("Hammer candle")

        elif self.Portfolio[self.ticker].UnrealizedProfitPercent > 0.1:
            self.Liquidate(self.ticker)
            self.Debug("Take profit triggered")
        else:
            self.SetHoldings(self.ticker, 1)

        self.Plot("Strategy Equity", str(self.ticker), self._cash * self.Securities[self.ticker].Close / self._initialValue_ticker)
        self.Plot("Strategy Equity", 'Portfolio Value', self.Portfolio.TotalPortfolioValue)
        self.Plot("Hammer", "value", self.hammer.Current.Value)
        self.Plot("HangingMan", "hangingman", self.hangingman.Current.Value)