
이 전략은 이중 RSI (대비적으로 강한 지수) 지표에 기반한 자기 적응 거래 시스템이다. 이 전략은 시장의 추세와 거래 기회를 식별하고, 재원 관리 및 위험 제어 메커니즘을 통해 거래 성능을 최적화하기 위해 다른 시간 주기의 RSI 지표를 결합한다. 이 전략의 핵심은 다중 주기의 RSI의 조화를 통해 거래 안전을 보장하면서 수익성을 향상시키는 것이다.
이 전략은 7주기 RSI를 주요 거래 신호로 사용하고, 일간 RSI를 트렌드 필터로 사용한다. 단기 RSI가 40 이하에서 상향으로 돌파되고 일간 RSI가 55 이상일 때, 시스템은 더 많은 신호를 낸다. 포지션 보유 기간 동안 가격이 처음 포지션 가격보다 낮아지면, 시스템은 자동으로 포지션을 높여 평균 비용을 낮추는다.
이것은 기술 분석과 위험 관리를 결합한 완전한 거래 시스템이다. 다중 주기 RSI의 연동 작용을 통해 거래 신호를 제공하고, 재원 관리 및 손해 방지 메커니즘을 통해 위험을 제어한다. 이 전략은 트렌드가 명백한 시장에서 작동하는 데 적합하지만 실제 시장 상황에 따라 파라미터를 최적화해야합니다. 시스템의 확장성은 좋으며, 추가 최적화를 위해 공간을 예약합니다.
/*backtest
start: 2024-11-12 00:00:00
end: 2024-12-11 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Dual RSI with Rebuy Logic + Capital, Commission, and Stop Loss", overlay=true)
// Parameter
rsi_length = input.int(7, title="RSI Length")
daily_rsi_length = input.int(7, title="Daily RSI Length")
capital = input.float(10000, title="Initial Capital", minval=0) // Kapital
risk_per_trade = input.float(0.01, title="Risk per Trade (%)", minval=0.01, maxval=1.0) // Risikogröße in Prozent
commission = input.float(0.1, title="Commission (%)", minval=0, maxval=100) // Kommission in Prozent
stop_loss_pct = input.float(5, title="Stop Loss (%)", minval=0.1, maxval=100) // Stop-Loss in Prozent
// Ordergröße berechnen
risk_amount = capital * risk_per_trade
order_size = risk_amount / close // Größe der Order basierend auf Risikogröße und Preis
// Daily RSI
day_rsi = request.security(syminfo.tickerid, "D", ta.rsi(close, daily_rsi_length), lookahead=barmerge.lookahead_on)
// RSI auf aktuellem Timeframe
rsi = ta.rsi(close, rsi_length)
// Kauf- und Verkaufsbedingungen
buy_condition = rsi[1] < 40 and rsi > rsi[1] and day_rsi > 55
sell_condition = rsi[1] > 60 and rsi < rsi[1]
// Variablen, um den Preis des ersten Kaufs zu speichern
var float first_buy_price = na
var bool is_position_open = false
// Kauf-Logik
if buy_condition
if not is_position_open
// Initiales Kaufsignal
strategy.entry("Buy", strategy.long, qty=1)
first_buy_price := close
is_position_open := true
else if close < first_buy_price
// Rebuy-Signal, nur wenn Preis niedriger als erster Kaufpreis
strategy.entry("Rebuy", strategy.long, qty=1)
// Verkaufs-Logik
if sell_condition and is_position_open
strategy.close("Buy")
strategy.close("Rebuy")
first_buy_price := na // Zurücksetzen des Kaufpreises
is_position_open := false
// Stop-Loss-Bedingung
if is_position_open
// Stop-Loss-Preis berechnen (5% unter dem Einstiegspreis)
stop_loss_price = first_buy_price * (1 - stop_loss_pct / 100)
// Stop-Loss für "Buy" und "Rebuy" festlegen
strategy.exit("Stop Loss Buy", from_entry="Buy", stop=stop_loss_price)
strategy.exit("Stop Loss Rebuy", from_entry="Rebuy", stop=stop_loss_price)
// Performance-Metriken berechnen (mit Kommission)
gross_profit = strategy.netprofit / capital * 100
commission_cost = commission / 100 * strategy.closedtrades
net_profit = gross_profit - commission_cost
// Debug-Plots
plot(first_buy_price, title="First Buy Price", color=color.blue, linewidth=1)
plotchar(buy_condition, title="Buy Condition", char='B', location=location.abovebar, color=color.green)
plotchar(sell_condition, title="Sell Condition", char='S', location=location.belowbar, color=color.red)
// Debugging für Performance