피브 (Pivot) 기반의 RSI 격차 전략

저자:차오장, 날짜: 2023-11-28 13:43:05
태그:

img

전반적인 설명

이 전략은 Pivot 기반의 RSI 분산 전략이라고 불립니다. 그것은 입점 및 출구 지점을 결정하기 위해 다른 주기에 있는 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)



더 많은