Overall Statistics
Total Trades
11
Average Win
38.72%
Average Loss
-2.95%
Compounding Annual Return
40.264%
Drawdown
24.400%
Expectancy
7.482
Net Profit
139.899%
Sharpe Ratio
1.2
Probabilistic Sharpe Ratio
53.753%
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
13.14
Alpha
0.199
Beta
0.526
Annual Standard Deviation
0.254
Annual Variance
0.064
Information Ratio
0.43
Tracking Error
0.241
Treynor Ratio
0.579
Total Fees
$139.60
Estimated Strategy Capacity
$79000000.00
Lowest Capacity Asset
XON R735QTJ8XC9X
# region imports
from AlgorithmImports import *
# endregion

class DonchianChannelBreakoutAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2022, 8, 1)
        self.SetCash(100000)
        self.symbol = self.AddEquity("XOM", Resolution.Daily).Symbol
        self.EnableAutomaticIndicatorWarmUp = True
        self.indicator = self.DCH(self.symbol, 20, 20)
        self.SetBenchmark(self.symbol)

        self.can_short = False

    def OnData(self, data: Slice):
        if self.symbol not in data.Bars:
            return
        bar = data.Bars[self.symbol]

        if bar.Close > self.indicator.UpperBand.Current.Value and not self.Portfolio[self.symbol].IsLong:
            self.SetHoldings(self.symbol, 1)
        elif bar.Close < self.indicator.LowerBand.Current.Value:
            if self.can_short and not self.Portfolio[self.symbol].IsShort:
                self.SetHoldings(self.symbol, -1)
            if not self.can_short and self.Portfolio[self.symbol].IsLong:
                self.SetHoldings(self.symbol, 0)

        # Plot indicator and prices
        self.Plot("Custom", "Donchian Channel High", self.indicator.UpperBand.Current.Value)
        self.Plot("Custom", "High Price", bar.High)
        self.Plot("Custom", "Close Price", bar.Close)
        self.Plot("Custom", "Low Price", bar.Low)
        self.Plot("Custom", "Donchian Channel Low", self.indicator.LowerBand.Current.Value)