Overall Statistics
Total Trades
497
Average Win
3.41%
Average Loss
-1.81%
Compounding Annual Return
15.364%
Drawdown
24.300%
Expectancy
0.479
Net Profit
581.729%
Sharpe Ratio
1.012
Probabilistic Sharpe Ratio
40.615%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.89
Alpha
0.15
Beta
0.159
Annual Standard Deviation
0.168
Annual Variance
0.028
Information Ratio
0.182
Tracking Error
0.238
Treynor Ratio
1.075
Total Fees
$5325.46
Estimated Strategy Capacity
$24000000.00
Lowest Capacity Asset
TLT SGNKIKYGE9NP
# Trading Donchian Channel by Vladimir

class DonchianChannel(QCAlgorithm):
    
    def Initialize(self): 
        self.SetStartDate(2008, 1, 1)
        self.SetEndDate(2021, 6, 2)
        period = 20;
        ma = 2
        self.stock = self.AddEquity('QQQ', Resolution.Hour).Symbol 
        self.bond = self.AddEquity('TLT', Resolution.Hour).Symbol
        self.SetWarmUp(period + ma + 1)
        self.sma = self.SMA(self.stock, ma, Resolution.Daily)
        self.donchian = self.DCH(self.stock, period, period, Resolution.Daily)
        self.in_stock = 0


    def OnData(self, data):
        if self.IsWarmingUp or not self.donchian.IsReady: return

        ml = self.donchian.Current.Value
        sma = self.sma.Current.Value

        if sma >= ml and not self.in_stock:
            self.SetHoldings(self.stock, 1)
            self.SetHoldings(self.bond, 0)
            self.in_stock = 1
                
        elif sma < ml and self.in_stock:
            self.SetHoldings(self.stock, 0)
            self.SetHoldings(self.bond, 1)
            self.in_stock = 0