Overall Statistics
Total Orders
1707
Average Win
10.73%
Average Loss
-3.76%
Compounding Annual Return
19.058%
Drawdown
51.300%
Expectancy
0.846
Start Equity
1000000
End Equity
3050443.99
Net Profit
205.044%
Sharpe Ratio
0.526
Sortino Ratio
0.529
Probabilistic Sharpe Ratio
10.761%
Loss Rate
52%
Win Rate
48%
Profit-Loss Ratio
2.85
Alpha
0.046
Beta
1.003
Annual Standard Deviation
0.267
Annual Variance
0.071
Information Ratio
0.223
Tracking Error
0.206
Treynor Ratio
0.14
Total Fees
$3622.31
Estimated Strategy Capacity
$820000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
Portfolio Turnover
4.33%
#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
# https://www.quantconnect.com/docs/v2/writing-algorithms/trading-and-orders/order-types/limit-orders

class RetrospectiveYellowGreenAlligator(QCAlgorithm):

    def Initialize(self):
        
        # INITIALIZE
        self.SetStartDate(2019, 1, 1) 
        self.SetEndDate(2025, 5, 25)
        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)