Overall Statistics |
Total Orders 7 Average Win 13.29% Average Loss -3.51% Compounding Annual Return 10.983% Drawdown 22.900% Expectancy 0.595 Start Equity 100000.0 End Equity 101842.85 Net Profit 1.843% Sharpe Ratio 0.245 Sortino Ratio 0.384 Probabilistic Sharpe Ratio 36.904% Loss Rate 67% Win Rate 33% Profit-Loss Ratio 3.78 Alpha 0.187 Beta 1.232 Annual Standard Deviation 0.511 Annual Variance 0.261 Information Ratio 0.353 Tracking Error 0.497 Treynor Ratio 0.102 Total Fees $0.00 Estimated Strategy Capacity $80000.00 Lowest Capacity Asset BTCUSD 2XR Portfolio Turnover 10.80% |
from AlgorithmImports import * class TopCryptoStrategy(QCAlgorithm): def Initialize(self): self.SetStartDate(2024, 3, 1) # Set Start Date self.SetEndDate(2024, 6, 1) self.SetCash(100000) # Set Strategy Cash # Define the symbols self.crypto_symbols = ["BTCUSD"] self.SetBenchmark("SPY") # Attempt to add each cryptocurrency and stock self.active_symbols = [] for symbol in self.crypto_symbols: try: self.AddCrypto(symbol, Resolution.MINUTE) self.active_symbols.append(symbol) except Exception as e: self.Debug(f"Unable to add symbol: {symbol}. Exception: {e}") # Define the technical indicators self.supertrend1 = {} self.supertrend2 = {} self.rsi = {} self.ema100 = {} self.weekly_twap = {} self.entry_prices = {} for symbol in self.active_symbols: self.supertrend1[symbol] = self.STR(symbol, 10, 10, MovingAverageType.Wilders) self.supertrend2[symbol] = self.STR(symbol, 10, 3, MovingAverageType.Wilders) self.rsi[symbol] = self.RSI(symbol, 10, MovingAverageType.Wilders, Resolution.MINUTE) self.ema100[symbol] = self.EMA(symbol, 100, Resolution.MINUTE) self.weekly_twap[symbol] = self.WeeklyTwap(symbol, 5) self.entry_prices[symbol] = None self.SetWarmUp(100, Resolution.MINUTE) # Warm up period for 100 days def WeeklyTwap(self, symbol, num_weeks): twap = self.SMA(symbol, num_weeks * 5, Resolution.MINUTE) # Assuming 5 trading days per week return twap def OnData(self, data): if self.IsWarmingUp: return for symbol in self.active_symbols: if not data.Bars.ContainsKey(symbol): continue bar = data.Bars[symbol] # Get current values current_price = bar.Close supertrend1 = self.supertrend1[symbol].Current.Value supertrend2 = self.supertrend2[symbol].Current.Value rsi = self.rsi[symbol].Current.Value ema100 = self.ema100[symbol].Current.Value weekly_twap = self.weekly_twap[symbol].Current.Value # Define factor based on asset type factor = 1.2 # Entry condition if self.entry_prices[symbol] is None: if ( rsi < 99): # Use appropriate factor self.Debug(f"{symbol}: Supertrend1={supertrend1}, Supertrend2={supertrend2}, RSI={rsi}, EMA100={ema100}, Weekly TWAP={weekly_twap}") self.SetHoldings(symbol, 1.0) self.entry_prices[symbol] = current_price # Exit condition elif rsi < 1: self.Liquidate(symbol) self.entry_prices[symbol] = None