Overall Statistics
Total Trades
450
Average Win
8.48%
Average Loss
-3.27%
Compounding Annual Return
17.943%
Drawdown
51.100%
Expectancy
0.711
Net Profit
101.628%
Sharpe Ratio
0.624
Probabilistic Sharpe Ratio
15.206%
Loss Rate
52%
Win Rate
48%
Profit-Loss Ratio
2.59
Alpha
0.062
Beta
0.825
Annual Standard Deviation
0.252
Annual Variance
0.064
Information Ratio
0.208
Tracking Error
0.203
Treynor Ratio
0.191
Total Fees
$2825.85
Estimated Strategy Capacity
$640000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
Portfolio Turnover
5.20%
#region imports
from AlgorithmImports import *
#endregion
#Stop Limit Orders create a limit order when a specified price is reached. 
#The associated limit order is filled when it reaches the limit price or better. 
#As with all limit orders, the order is not filled
#if the price does not reach the specified price. 
#Stop limit orders are often used to control risk, without the risk of a large gap filling trades unfavorably

# https://www.quantconnect.com/docs/algorithm-reference/trading-and-orders#Trading-and-Orders-Stop-Limit-Orders

class RetrospectiveYellowGreenAlligator(QCAlgorithm):

    def Initialize(self):
        
        # INITIALIZE
        self.SetStartDate(2019, 1, 1) 
        self.SetEndDate(2023, 3, 31)
        self._cash=1000000
        self.SetCash(self._cash) 
        self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.qqq = self.AddEquity("QQQ", Resolution.Daily).Symbol
        
        # SET BENCHMARK AND PREPARE COMPARATIVE PLOT
        self.reference = self.History(self.spy, 10, Resolution.Daily)['close']
        self._initialValue = self.reference.iloc[0]
        
        self.reference_qqq = self.History(self.qqq, 10, Resolution.Daily)['close']
        self._initialValue_qqq = self.reference_qqq.iloc[0]
        
        
    def OnData(self, data):
        self.close = self.Securities["QQQ"].Close
        self.stopPrice = self.close * .985
        self.limitPrice = self.close * 1.015
        self.orderSize = int(self.Portfolio.TotalPortfolioValue*.10/self.close)
        self.stopLimitTicket = self.StopLimitOrder("QQQ", self.orderSize, self.stopPrice, self.limitPrice)
        
        if self.Securities["QQQ"].Low <0.975*self.close:
            self.Liquidate("QQQ")
        
        self.Plot("Strategy Equity", "SPY", self._cash*self.Securities["SPY"].Close/self._initialValue)
        self.Plot("Strategy Equity", "QQQ", self._cash*self.Securities["QQQ"].Close/self._initialValue_qqq)