Overall Statistics
Total Trades
2772
Average Win
0.80%
Average Loss
-0.38%
Compounding Annual Return
-8.638%
Drawdown
29.400%
Expectancy
-0.080
Net Profit
-24.020%
Sharpe Ratio
-0.37
Probabilistic Sharpe Ratio
0.182%
Loss Rate
71%
Win Rate
29%
Profit-Loss Ratio
2.12
Alpha
-0.051
Beta
-0.004
Annual Standard Deviation
0.137
Annual Variance
0.019
Information Ratio
-0.62
Tracking Error
0.18
Treynor Ratio
13.568
Total Fees
$64758.13
Estimated Strategy Capacity
$4700000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
#region imports
from AlgorithmImports import *
#endregion
# Trading QC Super Trend Indicator
# --------------------------------------------
STOCK = "QQQ";  BAR = 201; SL = -0.0145; TP = 0.005; ATR = 1; MULT = 0.165; 
# --------------------------------------------

class SuperTrendIndicator(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(DateTime(2005, 5, 17, 9, 30, 0))  
        self.SetEndDate(DateTime(2008, 6, 1, 16, 0, 0)) 
        self.SetCash(200000)
        res = Resolution.Minute
        #ATR = int(self.GetParameter("ATR_A"))   
        #MULT = float(self.GetParameter("MULT_A"))
        self.stock = self.AddEquity(STOCK, res, extendedMarketHours = True).Symbol
        consolidator = TradeBarConsolidator(timedelta(minutes = BAR))
        self.Consolidate(self.stock, timedelta(minutes = BAR), self.BarHandler)
        self.st = SuperTrend(ATR, MULT, MovingAverageType.Wilders)
        self.RegisterIndicator(self.stock, self.st, consolidator)

        self.SetWarmUp(50*BAR*ATR, res)
        
        #self.rollingWindow = RollingWindow[TradeBar](3)      #Rolling window ???
        
    def BarHandler(self, consolidated):
        
        if self.IsWarmingUp: return

        if not self.st.IsReady: return 


        self.Plot(STOCK, "Price", self.Securities[self.stock].Price)
        self.Plot(STOCK, "Super Trend", self.st.Current.Value)


        pnl = self.Securities[self.stock].Holdings.UnrealizedProfitPercent

 
        if self.Securities[self.stock].High > self.st.Current.Value: # and self.Securities[self.stock].Open < self.Securities[self.stock].High:      # trend is bullish  and (self.Securities[self.stock].Price > self.st.Current.Value)  
            self.SetHoldings(self.stock, 1, True, "Buy Signal")

    
        elif self.Securities[self.stock].Low < self.st.Current.Value: # and self.Securities[self.stock].Open > self.Securities[self.stock].Low:   # trend is bearish and (self.Securities[self.stock].Price < self.st.Current.Value)
            self.SetHoldings(self.stock, -1, True, "Sell Signal")
            #self.Liquidate(self.stock, "Sell Signal")
           


        if self.Portfolio[self.stock].Invested: 
            if pnl < SL:
                self.Liquidate(self.stock, "Stop Loss")
            elif pnl > TP:
                self.Liquidate(self.stock, "Take Profit")