전환점을 기반으로 한 RSI 분기 전략


생성 날짜: 2023-11-28 13:43:05 마지막으로 수정됨: 2023-11-28 13:43:05
복사: 1 클릭수: 977
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

전환점을 기반으로 한 RSI 분기 전략

개요

이 전략은 Pivot-based RSI Divergence Strategy라고 불린다. 이 전략은 RSI 지표의 주기적인 편차를 사용하여 매도/판매 지점을 판단하고, 그 기초에 긴 선 RSI를 필터 조건으로 추가하여 전략의 안정성을 높인다.

전략 원칙

이 전략은 주로 짧은 RSI ((5일 RSI와 같은) 과 가격이 ?? 은형 다중 머리 뒤에서 ?? 또는 ?? 정규형 다중 머리 뒤에서 ?? 을 나타낼 때 기회를 구매; ?? 은형 공표 뒤에서 ?? 또는 ?? 정규형 공표 뒤에서 ?? 을 나타낼 때 기회를 판매한다.

일관형 다면이 낮은 가격으로 RSI가 낮지 않은 것을 뜻하며, 숨겨진 다면이 낮은 가격으로 RSI가 낮지 않은 것을 뜻한다. 두 가지의 정의는 특정 롤링 창의 역사적인 극치에 대한 것이다.

또한, 전략은 긴 라인 RSI (예: 50 일 RSI) 를 필터링 조건으로 도입한다. 긴 RSI가 50보다 크면 구매 신호를 고려할 수 있으며, 긴 RSI가 30보다 작으면 중지 또는 중지 철수를 고려할 수 있다.

전략적 이점

이 전략의 가장 큰 장점은 짧은 라인 RSI의 이탈 신호와 긴 라인 RSI의 필터링을 동시에 이용함으로써, 어느 정도까지 피팅 및 놓친 상황을 피할 수 있다는 것입니다. 구체적으로, 주로 다음과 같은 몇 가지 장점이 있습니다:

  1. 짧은 RSI가 신호에서 벗어나는 것은 가격의 역전 가능성을 미리 판단하여 시장의 전환점을 적시에 잡을 수 있습니다.
  2. 장선 RSI 필터 조건은 추세가 불확실할 때 맹목적으로 과잉을 피합니다.
  3. 여러 종류의 방제 방법, 방제를 분할하여 위험을 줄이는 것이 좋습니다.
  4. 피라미딩 메커니즘은 더 많은 수익을 창출할 수 있는 포지션을 허용합니다.

전략적 위험

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

  1. RSI의 오차는 항상 효과적이지 않으며, 가짜 신호가 발생할 수 있습니다.
  2. “지난 몇 년 동안, 저는 이 문제를 해결하기 위해 많은 노력을 기울여 왔습니다.
  3. 부적절한 정지 설정은 조기 정지 또는 수익 부족으로 이어질 수 있습니다.

이에 대응하는 위험 관리 조치는 다음과 같습니다: 합리적으로 스톱 스톱 조건을 설정하고, 각 포지션 크기를 제어하고, 손실 곡선을 평평하게 하기 위해 포지션을 수량으로 줄인다.

최적화 방향

이 전략에는 더 많은 최적화할 여지가 있습니다:

  1. RSI 파라미터를 더 최적화하여 최적의 파라미터 조합을 찾을 수 있습니다.
  2. MACD, KD 등과 같은 다른 지표의 오차 신호를 테스트할 수 있다.
  3. 특정 품종 (유기, 귀금속 등) 에 대한 특화된 최적화 매개 변수를 사용하여 적응력을 높일 수 있다.

요약하다

이 전략은 단선과 장선 RSI의 다공이 이탈 신호를 통합하여 위험을 제어하면서 수익 효율성을 향상시킵니다. 그것은 입시, 퇴시, 분량 포지션 감축, 스톱 로드 설정 등과 같은 수량 거래 전략 설계의 여러 원칙을 반영합니다. 이것은 참고할 수 있는 RSI 이탈 전략 예시입니다.

전략 소스 코드
/*backtest
start: 2023-11-20 00:00:00
end: 2023-11-27 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mohanee

//@version=4

//GOOGL setting  5 ,50 close, 3 , 1  profitLevel at 75 and No stop Loss shows win rate 99.03 % profit factor 5830.152

strategy(title="RSI5_50 with Divergence", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)

len = input(title="RSI Period", minval=1, defval=5)
longRSILen = input(title="Long RSI Period", minval=10, defval=50)
src = input(title="RSI Source", defval=close)
lbR = input(title="Pivot Lookback Right", defval=3)
lbL = input(title="Pivot Lookback Left", defval=1)
takeProfitRSILevel = input(title="Take Profit at RSI Level", minval=50, defval=75)
stopLoss = input(title="Stop Loss%(if checked 8% rule applied)", defval=false)

shortTermRSI = rsi(close,len)
longTermRSI = rsi(close,longRSILen)

rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)


bearColor = color.purple
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)



plot(shortTermRSI, title="RSI", linewidth=2, color=#8D1699)
plot(longTermRSI, title="longTermRSI", linewidth=2, color=color.orange)

hline(50, title="Middle Line", linestyle=hline.style_dotted)
obLevel = hline(70, title="Overbought", linestyle=hline.style_dotted)
osLevel = hline(30, title="Oversold", linestyle=hline.style_dotted)
fill(obLevel, osLevel, title="Background", color=longTermRSI >=50 ? color.green:color.purple, transp=65)  // longTermRSI >=50

plFound = na(pivotlow(shortTermRSI, lbL, lbR)) ? false : true
phFound = na(pivothigh(shortTermRSI, lbL, lbR)) ? false : true

_inRange(cond) =>
    bars = barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish

// shortTermRSI: Higher Low
oscHL = shortTermRSI[lbR] > valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low
priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)

bullCond = plotBull and priceLL and oscHL and plFound

plot(
	 plFound ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Regular Bullish",
	 linewidth=2,
	 color=(bullCond ? bullColor : noneColor),
	 transp=0
	 )


plotshape(
	 bullCond ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Regular Bullish Label",
	 text=" Bull ",
	 style=shape.labelup,
	 location=location.absolute,
	 color=bullColor,
	 textcolor=textColor,
	 transp=0
	 )

//------------------------------------------------------------------------------
// Hidden Bullish

// shortTermRSI: Lower Low
oscLL = shortTermRSI[lbR] < valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])

// Price: Higher Low
priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)

hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound

plot(
	 plFound ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bullish",
	 linewidth=2,
	 color=(hiddenBullCond ? hiddenBullColor : noneColor),
	 transp=0
	 )

plotshape(
	 hiddenBullCond ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bullish Label",
	 text=" H Bull ",
	 style=shape.labelup,
	 location=location.absolute,
	 color=bullColor,
	 textcolor=textColor,
	 transp=0
	 )

longCondition= longTermRSI >=50  and ( (bullCond or hiddenBullCond ) )  or  (strategy.position_size>0 and crossover(shortTermRSI,20) )
//last condition above is to leg in if you are already in the Long trade, 


strategy.entry(id="RSIDivLE", long=true,  when=longCondition)


//------------------------------------------------------------------------------
// Regular Bearish

// shortTermRSI: Lower High
oscLH = shortTermRSI[lbR] < valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])

// Price: Higher High
priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)

bearCond = plotBear and priceHH and oscLH and phFound

plot(
	 phFound ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Regular Bearish",
	 linewidth=2,
	 color=(bearCond ? bearColor : noneColor),
	 transp=0
	 )

plotshape(
	 bearCond ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Regular Bearish Label",
	 text=" Bear ",
	 style=shape.labeldown,
	 location=location.absolute,
	 color=bearColor,
	 textcolor=textColor,
	 transp=0
	 )

//------------------------------------------------------------------------------
// Hidden Bearish

// shortTermRSI: Higher High
oscHH = shortTermRSI[lbR] > valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])

// Price: Lower High
priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)

hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound

plot(
	 phFound ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bearish",
	 linewidth=2,
	 color=(hiddenBearCond ? hiddenBearColor : noneColor),
	 transp=0
	 )

plotshape(
	 hiddenBearCond ? shortTermRSI[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bearish Label",
	 text=" H Bear ",
	 style=shape.labeldown,
	 location=location.absolute,
	 color=bearColor,
	 textcolor=textColor,
	 transp=0
	 )
	 
	 
//calculate stop Loss
stopLossVal = stopLoss==true ? ( strategy.position_avg_price -  (strategy.position_avg_price*0.08) ) : 0

//partial profit
strategy.close(id="RSIDivLE", comment="TP1", qty=strategy.position_size*3/4, when=strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or crossover(longTermRSI,90)))
strategy.close(id="RSIDivLE",comment="TP2",   qty=strategy.position_size*3/4 , when=crossover(longTermRSI,70))
strategy.close(id="RSIDivLE",comment="TP3",   qty=strategy.position_size/2, when=crossover(longTermRSI,65))
strategy.close(id="RSIDivLE",comment="TP4",   qty=strategy.position_size/2 , when=crossover(longTermRSI,60))

//close the whole position when stoploss hits or longTermRSI goes below 30
strategy.close(id="RSIDivLE",comment="Exit",    when=crossunder(longTermRSI,30) or close<stopLossVal)