Overall Statistics
Total Trades
170
Average Win
1.11%
Average Loss
-0.74%
Compounding Annual Return
18.995%
Drawdown
6.000%
Expectancy
0.588
Net Profit
41.665%
Sharpe Ratio
1.297
Probabilistic Sharpe Ratio
64.202%
Loss Rate
37%
Win Rate
63%
Profit-Loss Ratio
1.50
Alpha
0.062
Beta
0.519
Annual Standard Deviation
0.103
Annual Variance
0.011
Information Ratio
-0.038
Tracking Error
0.099
Treynor Ratio
0.258
Total Fees
$447.70
Estimated Strategy Capacity
$1100000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
#region imports
from AlgorithmImports import *
#endregion
from datetime import timedelta
from AlgorithmImports import *
# QC Super Trend Indicator
# -------------------------------------------
STOCK = "SPY"; ATR = 2; MULT = 0.1;  BAR = 50;
# -------------------------------------------

class SuperTrendIndicator(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 5, 27)
        self.SetEndDate(2022, 5, 27)
        self.SetCash(200000)
        res = Resolution.Daily
        self.STOCK = self.AddEquity(STOCK, res).Symbol
        consolidator = TradeBarConsolidator(timedelta(hours = BAR))
        self.Consolidate(self.STOCK, timedelta(hours = BAR), self.BarHandler)
        self.st = SuperTrend(ATR, MULT, MovingAverageType.Wilders)
        self.RegisterIndicator(self.STOCK, self.st, consolidator)
        self.SetWarmUp(5*BAR*ATR, res)
        
    
    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)


# SUPERTREND = IF(Current Close <= Current Final Upperband ) Then Current Final
#  Upperband ELSE Current  Final Lowerband

# BUY market order when trend is bullish , and close this order once the trend reverses , then open market order
#  SELL when trend is bearinsh , and close it as soon as it changes to bullish.

    def OnData(self, data): 

        if self.st.IsReady:

            if self.Securities[self.STOCK].Price <= self.st.Current.Value:
                    self.SetHoldings(self.STOCK, 1, True, "Buy Signal")
                    self.Debug(self.Portfolio[self.STOCK].AveragePrice)


            elif self.Securities[self.STOCK].Price >= self.st.Current.Value:
                        self.Liquidate(self.STOCK, "Sell Signal")
                        self.Debug(self.Portfolio[self.STOCK].AveragePrice)