Overall Statistics
Total Trades
45
Average Win
25.03%
Average Loss
-3.17%
Compounding Annual Return
11.258%
Drawdown
23.400%
Expectancy
1.831
Net Profit
319.197%
Sharpe Ratio
0.84
Probabilistic Sharpe Ratio
22.693%
Loss Rate
68%
Win Rate
32%
Profit-Loss Ratio
7.90
Alpha
0.073
Beta
0.407
Annual Standard Deviation
0.149
Annual Variance
0.022
Information Ratio
-0.013
Tracking Error
0.173
Treynor Ratio
0.308
Total Fees
$472.42
Estimated Strategy Capacity
$120000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
# Last N bars above a moving average
# ------------------------------------------
STOCK = 'QQQ'; MA_F = 1; MA_S = 200; N = 5;
# ------------------------------------------
class MAC(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2008, 1, 1)
        self.SetEndDate(2021, 6, 4)
        self.SetCash(100000)
        self.stock = self.AddEquity(STOCK, Resolution.Hour).Symbol 
        self.SetWarmUp(MA_S, Resolution.Daily)
        self.sma_fast = self.SMA(self.stock, MA_F, Resolution.Daily)
        self.sma_slow = self.SMA(self.stock, MA_S, Resolution.Daily)
        self.Schedule.On(self.DateRules.EveryDay(self.stock), self.TimeRules.AfterMarketOpen(self.stock, 31), 
            self.trade)
        self.count = 0
        

    def trade(self):
        if self.IsWarmingUp: return 
        if not self.sma_fast.IsReady: return 
        if not self.sma_slow: return 

        self.Plot("SMA", "sma_fast", self.sma_fast.Current.Value)
        self.Plot("SMA", "sma_slow", self.sma_slow.Current.Value)
        
        if self.sma_fast.Current.Value > self.sma_slow.Current.Value:  
            self.count += 1
            
        elif self.sma_fast.Current.Value < self.sma_slow.Current.Value: 
            self.count = 0
                
        if self.count > N and not self.Portfolio[self.stock].IsLong:
            self.SetHoldings(self.stock, 1)  
            
        elif self.count <= N and self.Portfolio[self.stock].IsLong: 
            self.SetHoldings(self.stock, 0) 
            
        self.Plot("Above MA", "count", self.count)
        self.Plot("Above MA", "threshold", N)
            
'''
START
1/1/2008
END 
6/4/2021

STOCK = 'QQQ'; MA_F = 10; MA_S = 100; MDD = 0.081; LS = 0;

QQQ 10-100 .081

Sharpe Ratio
0.976
Total Trades
91
Average Win
9.57%
Average Loss
-3.56%
Compounding Annual Return
13.207%
Drawdown
19.800%
Expectancy
1.214
Net Profit
429.364%
PSR
37.444%
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
2.69
Alpha
0.092
Beta
0.419
Annual Standard Deviation
0.149
Annual Variance
0.022
Information Ratio
0.102
Tracking Error
0.17
Treynor Ratio
0.346
Total Fees
$1040.79
Estimated Strategy Capacity
$130000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX




'''