Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Sortino Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -0.836 Tracking Error 0.143 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% |
# region imports from AlgorithmImports import * from collections import deque # endregion class SmoothYellowGreenOwl(QCAlgorithm): def Initialize(self): self.SetStartDate(2022, 6, 26) self.SetCash(100000) self.AddEquity("SPY", Resolution.Minute).Symbol self.custom_mss = CustomMSS("CustomMSS", 10) def OnData(self, data: Slice): # Check if "SPY" data is available in the slice and is not None if "SPY" in data.Bars and data.Bars["SPY"] is not None: # Assuming self.custom_mss is properly initialized if self.custom_mss is not None: self.custom_mss.Update(data.Bars["SPY"]) # Insert your buy/sell logic here # Check if CustomMSS indicates a buy signal and the portfolio has enough cash if self.custom_mss.S < -10 and not self.Portfolio["SPY"].Invested: self.SetHoldings("SPY", 1) # Invest all available cash in SPY # Check if CustomMSS indicates a sell signal and the portfolio has the equity # elif self.custom_mss.S > 10 and self.Portfolio["SPY"].Invested: # self.Liquidate("SPY") # Sell all holdings of SPY class CustomMSS(PythonIndicator): def __init__(self, name, period): self.Name = name lookback = 10 self.WarmUpPeriod = lookback*3 self.Time = datetime.min self.Value = 0 self.short_window = RollingWindow[float](lookback) self.long_window = RollingWindow[float](lookback*2) self.short_min = 0 self.long_min = 0 self.S = 0 def Update(self, input: BaseData) -> bool: if not input: # Check for valid input return False # Add new data to the windows self.short_window.Add(input.Low) self.long_window.Add(input.Low) # Check if windows have enough data if self.short_window.Count == self.short_window.Size and self.long_window.Count == self.long_window.Size: self.short_min = min(self.short_window) self.long_min = min(self.long_window) self.S = self.short_min - self.long_min self.Time = input.Time return True