| Overall Statistics |
|
Total Orders 106 Average Win 1.03% Average Loss 0% Compounding Annual Return 42.570% Drawdown 20.200% Expectancy 0 Start Equity 100000 End Equity 142662.56 Net Profit 42.663% Sharpe Ratio 1.224 Sortino Ratio 1.558 Probabilistic Sharpe Ratio 64.253% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.065 Beta 1.58 Annual Standard Deviation 0.204 Annual Variance 0.042 Information Ratio 0.987 Tracking Error 0.134 Treynor Ratio 0.158 Total Fees $154.68 Estimated Strategy Capacity $8200000.00 Lowest Capacity Asset OAC X7PIBAO2WNDX Portfolio Turnover 2.92% |
from AlgorithmImports import *
class RsiTakeProfitAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2024, 1, 1)
self.SetEndDate(2024, 12, 31)
self.SetCash(100000)
self.tickers = ["TSLA", "GOOGL", "NVDA", "MSFT", "META", "HIMS", "UPST", "ORCL", "COIN", "AMD"]
self.symbols = []
self.rsi = {}
self.entry_prices = {} # Track entry prices per symbol
for ticker in self.tickers:
symbol = self.AddEquity(ticker, Resolution.Minute).Symbol
self.symbols.append(symbol)
# Set up 15-minute consolidator and RSI
consolidator = TradeBarConsolidator(timedelta(minutes=15))
self.SubscriptionManager.AddConsolidator(symbol, consolidator)
rsi = RelativeStrengthIndex(14, MovingAverageType.Wilders)
self.rsi[symbol] = rsi
self.RegisterIndicator(symbol, rsi, consolidator)
consolidator.DataConsolidated += self.OnDataConsolidated
def OnDataConsolidated(self, sender, bar):
symbol = bar.Symbol
rsi = self.rsi[symbol]
if not rsi.IsReady:
return
price = bar.Close
holdings = self.Portfolio[symbol].Quantity
# Buy condition: RSI ≤ 30 and no holdings
if rsi.Current.Value <= 30 and holdings == 0:
self.SetHoldings(symbol, 0.1)
self.entry_prices[symbol] = price
self.Debug(f"{self.Time} BUY {symbol.Value} | RSI: {rsi.Current.Value:.2f} | Entry: {price:.2f}")
# Sell condition: If we hold and price ≥ 10% above entry
elif holdings > 0 and symbol in self.entry_prices:
entry_price = self.entry_prices[symbol]
target_price = entry_price * 1.10
if price >= target_price:
self.Liquidate(symbol)
self.Debug(f"{self.Time} SELL {symbol.Value} | Gain: {(price - entry_price) / entry_price:.2%} | Price: {price:.2f}")
def OnData(self, data):
pass