DMI와 RSI를 기반으로 한 트렌드 다음 전략

저자:차오장, 날짜: 2024-01-25 15:56:41
태그:

img

##전략 논리

  1. 트렌드 방향을 판단하기 위해 DMI 지표를 사용
    • DMI는 세 줄로 구성됩니다. +DI는 상승 추세를 나타냅니다. -DI는 하락 추세를 나타냅니다. ADX는 추세 강도를 판단합니다.
  2. RSI 인디케이터를 사용하여 과반 구매 및 과반 판매를 판단합니다.
    • RSI는 초고가 또는 초판매를 결정하기 위해 기간 동안 평균 이익과 손실을 비교합니다.
  3. 트렌드 방향을 결정하기 위해 DMI와 과반 구매/ 과반 판매를 위한 RSI를 결합하면 시장 리듬을 더 잘 파악할 수 있습니다.
    • DMI가 상승 추세를 보이고 RSI가 과잉 판매되면
    • DMI가 하락 추세를 보이고 RSI가 과잉 매입되었을 때, 짧은 시기는 좋습니다.
  4. 수익을 차단하기 위해 이동 스톱 손실을 설정

##우익 분석 이것은 다음과 같은 강점을 가진 전략에 따라 비교적 성숙하고 안정적인 추세입니다.

  1. 트렌드와 과잉 구매/ 과잉 판매를 결합하면 범위에 제한된 시장에서 빈번한 거래가 피할 수 있습니다.
  2. 인기 있는 지표 DMI와 RSI는 매개 변수 조정과 철저한 실제 검증을 쉽게 수행합니다.
  3. 후속 스톱 손실은 수익을 차단하고 어느 정도 스톱 손실을 피합니다.
  4. 명확하고 쉬운 규칙, 쉽게 실행

##위험 분석 또한 몇 가지 위험 요소가 있습니다.

  1. DMI와 RSI는 잘못된 신호를 쉽게 생성하여 불필요한 손실을 유발할 수 있습니다.
  2. 부적절한 후속 스톱 손실 설정은 손실을 너무 일찍 또는 너무 많이 중지 할 수 있습니다.
  3. 시장을 효과적으로 필터링 할 수 없습니다. 함정에 빠질 가능성이 높습니다.
  4. 트렌드를 따라가는 것은 트렌드가 역전되면 즉시 종료되지 않습니다.

  1. 거짓 브레이크오웃을 피하기 위해 촛불 패턴을 조합
  2. 손실을 제한하기 위해 주요 지원/저항 근처에 적절한 스톱 손실을 설정
  3. 트렌드 예측을 위한 기계 학습 모델을 향상
  4. DMI 및 RSI 매개 변수의 동적 최적화


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-24 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © YingYangJPN

//@version=5
strategy("DMI and RSI Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// DMI indikatörünü tanımlayalım
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
len = input.int(14, minval=1, title="DI Length")
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / trur)
minus = fixnan(100 * ta.rma(minusDM, len) / trur)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
trailing_stop_loss_factor = input.float(0.50, "Trailing Stop Loss Factor", step = 0.01)

// RSI indikatörünü tanımlayalım
rsiLength = input.int(14, minval=1, title="RSI Length")
rsiSource = input(close, title="RSI Source")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
rsiValue = ta.rsi(rsiSource, rsiLength)

// Uzun pozisyon açma koşullarını tanımlayalım
longCondition1 = rsiValue < rsiOversold // RSI oversold seviyesinin altındaysa
longCondition2 = adx > 20 // ADX 20'den büyükse
longCondition3 = minus > plus

// Kısa pozisyon açma koşullarını tanımlayalım
shortCondition1 = rsiValue > rsiOverbought // RSI overbought seviyesinin üstündeyse
shortCondition2 = adx > 20 // ADX 20'den büyükse
shortCondition3 = plus > minus

// Uzun pozisyon açalım
if longCondition1 and longCondition2 and longCondition3
    strategy.entry("Long", strategy.long)
    

// Kısa pozisyon açalım
if shortCondition1 and shortCondition2 and shortCondition3
    strategy.entry("Short", strategy.short)
    
// Trailing Stop Loss
longTrailingStopLoss = strategy.position_avg_price * (1 - trailing_stop_loss_factor / 100)
shortTrailingStopLoss = strategy.position_avg_price * (1 + trailing_stop_loss_factor / 100)
if strategy.position_size > 0 
    strategy.exit("Exit Long", "Long", stop  = longTrailingStopLoss)
if strategy.position_size < 0 
    strategy.exit("Exit Short", "Short", stop = shortTrailingStopLoss)

// DMI ve RSI indikatörlerini grafiğe çizelim
plot(adx, color=#F50057, title="ADX")
plot(plus, color=#2962FF, title="+DI")
plot(minus, color=#FF6D00, title="-DI")
plot(rsiValue, color=#9C27B0, title="RSI")
hline(rsiOverbought, title="RSI Overbought Level", color=#E91E63, linestyle=hline.style_dashed)
hline(rsiOversold, title="RSI Oversold Level", color=#4CAF50, linestyle=hline.style_dashed)



더 많은