| Overall Statistics |
|
Total Orders 32 Average Win 4.35% Average Loss 0% Compounding Annual Return 63.481% Drawdown 19.400% Expectancy 0 Start Equity 100000 End Equity 163627.76 Net Profit 63.628% Sharpe Ratio 1.707 Sortino Ratio 2.308 Probabilistic Sharpe Ratio 77.226% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.187 Beta 1.701 Annual Standard Deviation 0.226 Annual Variance 0.051 Information Ratio 1.704 Tracking Error 0.158 Treynor Ratio 0.227 Total Fees $51.21 Estimated Strategy Capacity $9900000.00 Lowest Capacity Asset OAC X7PIBAO2WNDX Portfolio Turnover 0.93% |
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 ≥ 50% above entry
elif holdings > 0 and symbol in self.entry_prices:
entry_price = self.entry_prices[symbol]
target_price = entry_price * 1.50
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