RSI 및 Stochastic RSI를 기반으로 한 거래 전략


생성 날짜: 2024-02-18 16:13:50 마지막으로 수정됨: 2024-02-18 16:13:50
복사: 1 클릭수: 711
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

RSI 및 Stochastic RSI를 기반으로 한 거래 전략

개요

이 거래 전략은 상대적으로 약한 지표 ((RSI) 와 임의의 상대적으로 강한 지표 ((Stochastic RSI) 를 결합하여 거래 신호를 생성합니다. 전략은 더 높은 시간 프레임의 암호화폐 가격 움직임을 사용하여 트렌드를 확인하여 신호의 신뢰성을 높입니다.

전략 이름

멀티 타임 프레임 RSI-SRSI 트레이딩 전략

전략 원칙

이 전략은 RSI 지표 값의 높낮이에 따라 과매매 현상을 판단한다. RSI가 30보다 낮으면 과매매 신호이며, 70보다 높으면 과매매 신호이다. 스토카스틱 RSI 지표는 RSI 지표 자체의 변동을 관찰한다.

전략은 동시에 더 높은 시간 프레임 (예: 주주선) 의 암호화폐 가격 움직임과 결합한다. 구매 거래 신호는 더 높은 시간 프레임의 RSI가 하락보다 높을 때만 생성된다. (예: 45). 이 설정은 전체적으로 하락 추세에있을 때 발생하는 비 지속적 인 과매매 신호를 필터링 할 수 있습니다.

구매 및 판매 신호는 트리거 후, 일정 주기 (예: 8개의 K선) 를 거쳐 확인해야 하며, 잘못된 신호를 발생하지 않도록 한다.

전략적 이점

  • RSI를 이용한 고전적인 기술적 분석 방법
  • 스토카스틱 RSI 지표와 결합하여 RSI 자체의 역전 신호를 식별합니다.
  • 다중 시간 프레임 기술 필터링을 사용하여 잘못된 신호를 제거하고 신호 품질을 향상시킵니다.

전략적 위험과 해결 방법

  • RSI 지표는 잘못된 신호를 만들어 낼 수 있습니다.
    • 다른 지표와 함께 필터링 잘못된 신호
    • 적용 트렌드 확인 기술
  • 부적절하게 설정된 경량 변수는 과도한 거래 신호를 발생시킬 수 있습니다.
    • 최적화 변수 모음에서 최적의 변수를 찾습니다
  • 구매 신호는 확인이 필요합니다.
    • 균형 잡힌 확인 주기를 찾아서 잘못된 신호를 필터링하고 기회를 놓치지 마십시오.

전략 최적화 방향

  • 더 강력한 신호를 찾기 위해 더 많은 조합을 테스트합니다.
    • 예를 들어, MACD 지표를 전략에 포함합니다.
  • 최적의 매개 변수를 찾기 위한 기계 학습 방법을 시도합니다.
    • 유전적/진화적 알고리즘을 사용하여 자동적으로 최적화
  • 단편 거래 위험을 제어하기 위한 손실 방지 전략의 증가
    • 가격 지지율이 떨어질 때 멈춰야 합니다.

요약하다

이 전략은 주로 RSI와 Stochastic RSI 두 가지의 클래식 거래 지표에 의존하여 거래 신호를 생성한다. 동시에, 더 높은 시간 프레임을 도입하여 트렌드 확인을 할 수 있으며, 잘못된 신호를 효과적으로 필터링하여 신호 품질을 향상시킬 수 있다. 변수 최적화, 손실 중지 전략 등의 수단으로 전략 성능을 더욱 향상시킬 수 있다. 이 전략 아이디어는 간단하고 직접적이며 이해하기 쉬운 구현으로 거래량을 측정하는 데 좋은 출발점이다.

전략 소스 코드
/*backtest
start: 2023-02-11 00:00:00
end: 2024-02-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("RSI and Stochatic Strategy", overlay=true, use_bar_magnifier = false)


/////// Inputs ///////////////

// RSI and SRSI
rsiLength = input(14, title="RSI Length") 
stochLength = input(14, title="Stochastic Length")
kSmooth = input(3, title="K Smooth")
dSmooth = input(3, title="D Smooth")


//////// thresholds ///////////////
st_low = input(5, title="Low SRSI") // stochastic RSI low -- prepare to sell
st_hi = input(50, title="High SRSI") // stochastic RSI high -- prepare to buy
diff = input(5, title="difference") // minimum change in RSI
// inval_diff = input(12, title="difference") // invalidation difference: change in the oposite direction that invalidates rsi falling/rising
rsi_low = input(30, title="Low RSI") // RSI considered low
rsi_hi = input(60, title="High RSI") // RSI considered high
rsi_ht_hi = input(45, title="High higher time frame RSI") // RSI in higher time frame considered high


/// buy trigger duration 
tr_dur = input(8, title="Trigger duration")
low_dur = input(20, title="Monitoring last low")


///////////////// Higher time frame trend ///////////////////
// higher time frame resolution
res2 = input.timeframe("W", title="Higher time-frame")
// Input for the ticker symbol, default is an empty string
// For instance we could monitor BTC higher time frame trend
symbol = input("BTC_USDT:swap", "Input Ticker (leave empty for current)")

// Determine the symbol to use
inputSymbol = symbol == "" ? syminfo.tickerid : symbol
//////////////////////////////////////////////////////////

// Calculate RSI //
rsi = ta.rsi(close, rsiLength)

// Calculate Stochastic RSI //
rsiLowest = ta.lowest(rsi, stochLength)
rsiHighest = ta.highest(rsi, stochLength)
stochRsi = 100 * (rsi - rsiLowest) / (rsiHighest - rsiLowest)

// Apply smoothing
K = ta.sma(stochRsi, kSmooth)
D = ta.sma(K, dSmooth)

// Higher time Frame RSI
cl2 = request.security(inputSymbol, res2, close)
rsi2 = ta.rsi(cl2, 14)

// SRSI BUY/SELL signals 
sell_stoch = (ta.lowest(K, tr_dur) < st_low) or (ta.highest(rsi, tr_dur) < rsi_low)
buy_stoch = ((ta.lowest(K, tr_dur) > st_hi) or (ta.lowest(rsi, tr_dur) > rsi_hi)) and (rsi2 > rsi_ht_hi)

 // valitation / invalidation sell signal
ll = ta.barssince(not sell_stoch)+1
sell_validation = (ta.highest(rsi, ll)>rsi[ll]+diff and rsi < rsi[ll]) or (rsi < rsi[ll]-diff)

// valitation / invalidation buy signal
llb = ta.barssince(not buy_stoch)+1
buy_validation = (ta.lowest(rsi, llb)<rsi[llb]-diff and rsi > rsi[llb]) or (rsi > rsi_hi and rsi - rsi[tr_dur] > 0)

sell_signal = sell_stoch and sell_validation
buy_signal = buy_stoch and buy_validation 

// Define the start date for the strategy
startYear = input(2019, "Start Year")
startMonth = input(1, "Start Month")
startDay = input(1, "Start Day")

// Convert the start date to Unix time
startTime = timestamp(startYear, startMonth, startDay, 00, 00)

// Define the end date for the strategy
endYear = input(2030, "End Year")
endMonth = input(1, "End Month")
endDay = input(1, "End Day")

// Convert the end date to Unix time
endTime = timestamp(endYear, endMonth, endDay, 00, 00)


if true
    if buy_signal
        strategy.entry("buy", strategy.long, comment = "Buy")
    if sell_signal
        strategy.close("buy", "Sell")