| Overall Statistics |
|
Total Orders 291 Average Win 0.36% Average Loss 0% Compounding Annual Return 55.307% Drawdown 16.300% Expectancy 0 Start Equity 100000 End Equity 154870.05 Net Profit 54.870% Sharpe Ratio 1.934 Sortino Ratio 2.528 Probabilistic Sharpe Ratio 86.218% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.176 Beta 1.125 Annual Standard Deviation 0.167 Annual Variance 0.028 Information Ratio 1.681 Tracking Error 0.114 Treynor Ratio 0.287 Total Fees $500.60 Estimated Strategy Capacity $7200000.00 Lowest Capacity Asset OAC X7PIBAO2WNDX Portfolio Turnover 8.01% |
from AlgorithmImports import *
class RsiTakeProfitAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2023, 1, 1)
self.SetEndDate(2023, 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 ≥ 3% above entry
elif holdings > 0 and symbol in self.entry_prices:
entry_price = self.entry_prices[symbol]
target_price = entry_price * 1.03
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