RSI 및 피보나치 리트랙먼트 거래 전략

저자:차오장, 날짜: 2023-12-27 16:49:52
태그:

img

전반적인 설명

이 문서에서는 주로 상대적 강도 지수 (RSI) 와 피보나치 리트레이싱 수준을 결합한 거래 전략을 설명합니다. 이 전략은 먼저 특정 기간 동안의 역사적 가격 역동성에 기초하여 주요 피보나치 리트레이싱 수준을 계산하고, RSI 지표를 사용하여 시장이 리트레이싱 수준 근처에서 과소매 또는 과소매 여부를 판단하여 거래 신호를 생성합니다.

전략 원칙

이 전략의 기본 원칙은 다음과 같습니다.

  1. 특정 기간 (예를 들어 200 바) 의 가격 데이터를 사용하여 해당 기간의 중간 가격, 표준편차 및 키 피보나치 리트랙시 레벨 (예를 들어 0.764) 을 계산합니다.

  2. 가격이 상위 또는 하위 리트레이싱 수준에 접근하면 RSI 지표를 사용하여 해당 수준 주변에서 과잉 구매 또는 과잉 판매 상태가 있는지 여부를 결정합니다.

  3. 만약 RSI 지표가 과잉 구매 또는 과잉 판매 신호를 나타낸다면, 리트레이싱 수준 주변에서 긴 신호 또는 짧은 신호가 생성됩니다.

  4. 스톱 로스를 설정하고, 가격이 미리 설정된 수준을 초과하거나 스톱 로스가 트리거되면 포지션을 닫기 위해 수익을 취합니다.

위는 이 전략에서 거래 기회를 식별하는 기본 작업 흐름입니다.

이점 분석

RSI 또는 피보나치 단독으로 사용하는 것과 비교하면 이 결합 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 이중 표시기 필터링은 잘못된 신호를 줄이고 신호 품질을 향상시킬 수 있습니다.

  2. 피보나치 리트레이싱 수준에서의 거래는 고전적인 기술 분석 기술입니다.

  3. 스톱 로즈와 이윤을 취하는 속도로 거래당 최대 손실을 효과적으로 제어 할 수 있습니다.

  4. 매개 변수는 다양한 기간과 제품에 최적화 될 수 있습니다.

위험 분석

이 전략에는 몇 가지 위험 요소가 있습니다.

  1. 주요 수준에서 반전 가능성은 100%가 아니며 가격 행동과 결합해야합니다.

  2. 단일 기간 RSI는 죽은 고양이 반발에서 잘못된 신호를 생성 할 수 있습니다. 여러 시간 프레임 검증을 고려하십시오.

  3. 느슨한 스톱 손실 설정은 손실을 증가시킬 수 있습니다.

  4. 가격 변동 도중 스톱은 실행 될 수 있습니다. 더 넓은 스톱을 고려해야합니다.

이러한 위험은 매개 변수 조정, 지표 조합 최적화 등으로 관리될 수 있습니다.

최적화 방향

추가 최적화 영역은 다음과 같습니다.

  1. 부피 표시기를 추가하여 부피가 낮을 때 잘못된 파열을 피합니다.

  2. 폭파의 신호를 볼링거 밴드 (Bollinger Bands) 로 간주합니다.

  3. 높은 품질의 거래 기회를 자동으로 탐지하기 위해 기계 학습 모델을 구축합니다.

  4. 자동 매개 변수를 조정하고 스톱 손실/이익 수준을 조정하기 위해 유전 알고리즘을 사용합니다.

요약

이 문서에서는 RSI와 피보나치 리트레이스먼트 분석을 결합한 양적 거래 전략을 상세히 설명합니다. 이중 지표 분석과 고전적인 기술 전략을 혼합함으로써 전략은 관리된 위험 하에서 신호 품질을 향상시킵니다. 지속적인 매개 변수 조정 및 모델 최적화로 추가 성능 향상을 달성 할 수 있습니다.


/*backtest
start: 2023-11-26 00:00:00
end: 2023-12-26 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title="Gab Fib  + RSI", overlay=true, default_qty_type=strategy.cash, default_qty_value=100000, initial_capital=1000, currency=currency.USD, commission_type=strategy.commission.cash_per_order, commission_value=4)

// Inputs
timeFilter = year >= 2000
    // Stop Loss 
stop_loss = input(title="SL in % of Instrum. i.e 1.5%=150pips", minval=0, step=0.1, defval=1.5) /100
    // RSI Inputs
len = input(title="[RSI] Length", minval=0, step=1, defval=14)
overSold = input(title="[RSI] Over Sold %", defval=30)
overBought = input(title="[RSI] Over Bought %", defval=70)
    // Fibonacci Levels
length = input(title="[Fibonacci] Length", defval=200, minval=1)
src = input(hlc3, title="[Fibonacci] Source")
mult = input(title="[Fibonacci] Multiplier", defval=3.0, minval=0.001, maxval=50)
level = input(title="[Fibonacci] Level", defval=764)


// Calculate Fibonacci
basis = vwma(src, length)
dev = mult * stdev(src, length)
fu764= basis + (0.001*level*dev)
fu1= basis + (1*dev)
fd764= basis - (0.001*level*dev)
fd1= basis - (1*dev)

// Calculate RSI
vrsi = rsi(close, len)

// Calculate the Targets
targetUp = fd764
targetDown = fu764
    // Actual Targets
bought = strategy.position_size[0] > strategy.position_size[1]
exit_long = valuewhen(bought, targetUp, 0)
sold = strategy.position_size[0] < strategy.position_size[1]
exit_short = valuewhen(sold, targetDown, 0)

// Calculate Stop Losses
sl_long = close * (1-stop_loss)
sl_short = close * (1+stop_loss)


// Conditions to Open Trades
openLong = low < fd1 and crossover(vrsi[1], overSold)
openShort = high > fu1 and crossunder(vrsi[1], overBought)

// Conditions to Close Trades
closeLong = high > exit_long or sl_long
closeShort = low < exit_short or sl_short


//Rounding to MinTick value
roundtargetUp = round_to_mintick(targetUp)
roundtargetDown = round_to_mintick(targetDown)
roundsllong = round_to_mintick(sl_long)
roundslshort = round_to_mintick(sl_short)

// Plots
plot(basis, color=color.blue, linewidth=2, title="[Fibonacci Level] Basis")
plot(fu764, color=color.white, linewidth=1, title="[Fibonacci Level] Short Target")
plot(fu1, color=color.red, linewidth=2, title="[Fibonacci Level] Top")
plot(fd764, color=color.white, linewidth=1, title="[Fibonacci Level] Long Target")
plot(fd1, color=color.green, linewidth=2, title="[Fibonacci Level] Bottom")


// Strategy Orders
if timeFilter
    // Entry Orders
    strategy.entry(id="buy", long=true, when=openLong and high < targetUp, limit=close, alert_message="buy,"+tostring(syminfo.ticker)+",tp="+tostring(roundtargetUp)+",sl="+tostring(roundsllong))
    strategy.entry(id="sell", long=false, when=openShort and low > targetDown, limit=close,  alert_message="sell,"+tostring(syminfo.ticker)+",tp="+tostring(roundtargetDown)+",sl="+tostring(roundslshort))

    // Exit Orders
    strategy.exit(id="closelong", when=closeLong and strategy.position_size > 0, limit=exit_long, stop=sl_long, alert_message="closelong,"+tostring(syminfo.ticker))
    strategy.exit(id="closeshort", when=closeShort and strategy.position_size < 0, limit=exit_short, stop=sl_short, alert_message="closeshort,"+tostring(syminfo.ticker))

더 많은