Overall Statistics
Total Orders
23
Average Win
80.42%
Average Loss
0%
Compounding Annual Return
47.286%
Drawdown
69.100%
Expectancy
0
Start Equity
100000
End Equity
22671688.01
Net Profit
22571.688%
Sharpe Ratio
0.961
Sortino Ratio
0.986
Probabilistic Sharpe Ratio
22.115%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.174
Beta
2.735
Annual Standard Deviation
0.446
Annual Variance
0.198
Information Ratio
1.013
Tracking Error
0.331
Treynor Ratio
0.156
Total Fees
$10539.83
Estimated Strategy Capacity
$200000000.00
Lowest Capacity Asset
TQQQ UK280CGTCB51
Portfolio Turnover
0.41%
from AlgorithmImports import *

class SMAStrategyWithConfigurableAssets(QCAlgorithm):

    def Initialize(self):
        # --- Strategy Initialization ---
        self.SetStartDate(2010, 9, 1)
        self.SetEndDate(2024, 9, 1)
        self.SetCash(100000)  # Set the initial capital for the strategy

        # --- Signal Generator: Use QQQ for the SMA calculations ---
        self.qqq = self.AddEquity("QQQ", Resolution.Daily).Symbol

        # --- Configurable Assets for Uptrend and Downtrend ---
        self.uptrend_asset = self.AddEquity("TQQQ", Resolution.Daily).Symbol  # Asset for uptrend
        self.downtrend_asset = self.AddEquity("HON", Resolution.Daily).Symbol  # Asset for downtrend

        # --- Data Preparation: SMA Definitions ---
        # Define fast and slow SMAs for QQQ
        self.fast_sma = self.SMA(self.qqq, 100, Resolution.Daily)
        self.slow_sma = self.SMA(self.qqq, 200, Resolution.Daily)

        # --- RSI for Filtering Overbought/Oversold Conditions ---
        self.rsi = self.RSI(self.qqq, 14, MovingAverageType.Simple, Resolution.Daily)

        # --- Data Warmup: Ensure enough data for SMA and RSI calculations ---
        self.SetWarmUp(252)  # Warm up period of 252 days (~12 months)

    def OnData(self, data: Slice):
        if self.IsWarmingUp:
            return

        # Ensure data is available for QQQ (used for SMA and RSI)
        if not data.ContainsKey(self.qqq):
            return

        # --- Trade Logic with SMA and RSI ---
        # Ensure SMAs and RSI are ready before executing trades
        if not self.fast_sma.IsReady or not self.slow_sma.IsReady or not self.rsi.IsReady:
            return

        # --- RSI Filter: Avoid overbought or oversold markets ---
        if self.rsi.Current.Value > 65:  # RSI above 70 (overbought)
            self.Debug("RSI overbought - Avoid buying")
            return  # Avoid buying if RSI is overbought
        elif self.rsi.Current.Value < 35:  # RSI below 30 (oversold)
            self.Debug("RSI oversold - Avoid selling")
            return  # Avoid selling if RSI is oversold

        # --- SMA Crossover Logic ---
        # If fast SMA > slow SMA, buy the configured uptrend asset (e.g., TQQQ)
        if self.fast_sma.Current.Value > self.slow_sma.Current.Value:
            # Sell the downtrend asset if held (e.g., SQQQ)
            if self.Portfolio[self.downtrend_asset].Invested:
                self.Liquidate(self.downtrend_asset)
            # Buy the uptrend asset if not already invested (e.g., TQQQ)
            if not self.Portfolio[self.uptrend_asset].Invested:
                self.SetHoldings(self.uptrend_asset, 1.0)  # Invest 100% in the uptrend asset

        # If fast SMA <= slow SMA, buy the configured downtrend asset (e.g., SQQQ)
        elif self.fast_sma.Current.Value <= self.slow_sma.Current.Value:
            # Sell the uptrend asset if held (e.g., TQQQ)
            if self.Portfolio[self.uptrend_asset].Invested:
                self.Liquidate(self.uptrend_asset)
            # Buy the downtrend asset if not already invested (e.g., SQQQ)
            if not self.Portfolio[self.downtrend_asset].Invested:
                self.SetHoldings(self.downtrend_asset, 1.0)  # Invest 100% in the downtrend asset
# region imports
from AlgorithmImports import *
# endregion

# Your New Python File