RSI와 캔들스틱 패턴을 기반으로 한 거래 전략


생성 날짜: 2023-09-22 17:10:39 마지막으로 수정됨: 2023-09-22 17:10:39
복사: 0 클릭수: 786
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 상대적으로 약한 지수 ((RSI) 지표와 K선 형태 모드를 결합하여 RSI가 초과 구매 초과 판매 영역에 도달 할 때 특정 K선 형태를 입문 신호로 인식하여 트렌드 추적을 수행합니다.

전략 원칙

  1. RSI의 값을 계산하여 30을 초과 라인, 70을 초과 라인으로 니다.

  2. RSI에서 30을 넘으면 과매매 신호로 간주하고, RSI에서 70을 넘으면 과매매 신호로 간주한다.

  3. 위의 신호가 발생했을 때, 현재 K선 또는 이전 K선에서 흰색/흑색 개체, 頭/吊線 등의 특정 형태가 형성되었는지 판단한다.

  4. RSI 신호와 K선 형태 조건이 동시에 충족되면 구매/판매 신호가 생성된다.

  5. 대조적으로, 헤드 라인 등과 같은 다중 헤드 형태가 형성되면 RSI가 초과할 때 구매합니다. 쏘는 별 등과 같은 공허 헤드 형태가 형성되면 RSI가 초과할 때 판매합니다.

  6. 더 복잡한 조합된 캔들리스틱 패턴을 식별하여 입구 신호로 사용한다.

  7. RSI 회귀는 중선을 통과하여 평소 지점을 나타냅니다.

전략적 이점

  1. 지표와 형태를 결합하여, 가짜 신호를 필터링하여, 진입의 정확성을 향상시킵니다.

  2. K선 형태를 식별하여 보다 명백한 트렌드 전환점을 포착할 수 있다.

  3. RSI의 오버 바이 오버 셀 영역을 활용하여 수익을 올릴 수 있는 신호를 발산합니다.

  4. 트렌드가 강한 전환점을 잡을 수 있는 쌍삼선 형태 조합을 식별한다.

  5. RSI는 중선을 가로질러 중지/정지 신호로, 이윤을 잠금하는 데 도움이 됩니다.

전략적 위험

  1. RSI 지표는 뒤쳐져 있고, 전환점을 놓칠 수도 있다.

  2. 일부 K선 형태 신호는 약하고, 가짜 신호가 있을 수 있다.

  3. 파격 전 최고점, 재검토 전 최저점은 스톱 스톱 신호로 고려되지 않아 손실 위험이 있습니다.

  4. 이동식 스톱을 설정하지 않으면, 큰 반전이 손실을 확대할 수 있다.

  5. 탐사 데이터가 부족하여 변수 최적화 결과에 대한 편차가 발생할 수 있습니다.

전략 최적화 방향

  1. MACD, 브린 띠 등과 같은 다른 지표 필터링 입력 신호와 함께.

  2. 트렌드 라인을 추가하여 스톱로스트를 설정합니다.

  3. 피드백 결과에 따라 RSI 변수를 최적화하고 최적의 변수 조합을 찾습니다.

  4. 추적 스톱, 간격 스톱과 같은 스톱 스톱 전략을 최적화하십시오.

  5. 더 긴 시간 주기의 데이터를 테스트하고, 변수 안정성을 평가한다.

  6. 다른 품종, 시장 상황에 따라 파라미터를 조정한다.

요약하다

이 전략은 RSI 지표와 K선 형태 인식의 장점을 통합하여 오버 바이 오버 셀 포인트에서 고품질의 신호를 선택하여 트렌드 추적의 효과를 달성한다. 동시에 몇 가지 더 강력한 조합 형태 신호를 식별하여 수익률을 높일 수 있다. 그러나 어느 정도 지연, 가짜 신호의 위험이 있으며, 다른 수단과 함께 사용되고 계속 최적화해야 한다.

전략 소스 코드
/*backtest
start: 2022-09-15 00:00:00
end: 2023-09-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

/////////////////////////////////////
//@version=2
//@author=sb
strategy("RSI-candlestick Strategy", overlay=true)
src = hlc3, len = input(14, minval=1, title="Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
//plot(rsi, color=purple)
//band1 = hline(70)
//band0 = hline(30)
//band2 = hline(50,linestyle=dotted,color=silver)
//fill(band1, band0, color=#cc99ff, transp=70)
//end premade RSI
oversold = rsi < 30
overbought = rsi > 70
barcolor(oversold? #7fff00 : overbought? red : na )
//
//
level_70 = 70
level_70rsi = rsi > level_70 ? rsi : level_70
level_30 = 30
level_30rsi = rsi < 30 ? rsi : level_30

level_50 = 50
//


//p1 = plot(series=level_70, color=red, linewidth=1, transp=100)
//p2 = plot(series=level_70rsi, color=red, linewidth=1, transp=100)
//p3 = plot(series=level_30, color=green, linewidth=1, transp=100)
//p4 = plot(series=level_30rsi, color=green, linewidth=1, transp=100)
//fill(p1, p2, color=red, transp=50)
//fill(p3, p4, color=#7fff00, transp=50)




/////////////////////////////////////


bullishcriteria = input(title="RSI Bullish Criteria",  defval=55, minval=50, maxval=100)
bearishcriteria = input(title="RSI Bearish Criteria",  defval=45, minval=0, maxval=50)

range = high - low
body = abs(close - open)
oc2 = min(close, open) + body/2
upperwick = high - max(open, close)
lowerwick = min(open, close) - low

isUp = close > open
isTrendUp = rsi(close, 14) >= bullishcriteria
isTrendDown = rsi(close, 14) <= bearishcriteria
isDoji = abs(close-open)/(high-low) < 0.05

// Single Candlestick Pattern
// white marubozu
wm = (isUp) and (upperwick <= 0.05*body) and (lowerwick <= 0.05*body) and isTrendDown
plotshape(wm, color=green, style=shape.triangleup, location=location.belowbar, title='white marubozu',text='wm')
if (not na(rsi))
    if (crossover(rsi, level_30) and (wm or wm[1]))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
// black marubozu
bm = (not isUp) and (upperwick <= 0.05*body) and (lowerwick <= 0.05*body) and isTrendUp
plotshape(bm, color=red, style=shape.triangledown, location=location.abovebar, title='black marubozu',text='bm')

if (not na(rsi))
    if (crossunder(rsi, level_70)and (bm or bm[1]))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
// hammer
h = (isUp) and (lowerwick >= 2*body) and (upperwick <= 0.1*body) and isTrendDown
plotshape(h, color=green, style=shape.triangleup, location=location.belowbar, title='hammer',text='h')

if (not na(rsi))
    if (crossover(rsi, level_30) and (h or h[1]))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
// hanging man
hm = (not isUp) and (lowerwick >= 2*body) and (upperwick <= 0.1*body) and isTrendUp
plotshape(hm, color=red, style=shape.triangledown, location=location.abovebar, title='hanging man',text='hm')

if (not na(rsi))
    if (crossunder(rsi, level_70)and (hm or hm[1]))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        
// inverted hammer
ih = (isUp) and (upperwick >= 2*body) and (lowerwick <= 0.1*body) and isTrendDown
plotshape(ih, color=green, style=shape.triangleup, location=location.belowbar, title='inverted hammer',text='ih')

//if (not na(rsi))
//    if (crossover(rsi, level_30) and (ih or ih[1]))
//        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
        
// shooting star
ss = (not isUp) and (upperwick >= 2*body) and (lowerwick <= 0.1*body) and isTrendUp
plotshape(ss, color=red, style=shape.triangledown, location=location.abovebar, title='shooting star',text='ss')

if (not na(rsi))
    if (crossunder(rsi, level_70)and (ss or ss[1]))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        
// Double Candlestick Pattern
// bullish engulfing
bulle = not isDoji[1] and (not isUp[1] and isUp) and (close > open[1] and open < close[1]) and isTrendDown
plotshape(bulle, color=green, style=shape.triangleup, location=location.belowbar, title='bullish engulfing', text='e')

// bearish engulfing
beare = not isDoji[1] and (isUp[1] and not isUp) and (open > close[1] and close < open[1]) and isTrendUp
plotshape(beare, color=red, style=shape.triangledown, location=location.abovebar, title='bearish engulfing',text='e')

// tweezer bottom
twb = (not isUp[1] and isUp) and (min(lowerwick,lowerwick[1])/max(lowerwick,lowerwick[1]) >= 0.99) and (min(low,low[1])/max(low,low[1]) >= 0.99) and isTrendDown
plotshape(twb, color=green, style=shape.triangleup, location=location.belowbar, title='tweezer bottom', text='tb')

if (not na(rsi))
    if (crossover(rsi, level_30) and (twb or twb[1]))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
        
// tweezer top
twt = (isUp[1] and not isUp) and (min(upperwick,upperwick[1])/max(upperwick,upperwick[1]) >= 0.99) and (min(high,high[1])/max(high,high[1]) >= 0.99) and isTrendUp
plotshape(twt, color=red, style=shape.triangledown, location=location.abovebar, title='tweezer top',text='tt')

if (not na(rsi))
    if (crossunder(rsi, level_70)and (twt or twt[1]))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
// Trible Candlestick Pattern
// three white soldier
tws = (not isUp[3] and isUp[2] and isUp[1] and isUp) and (body[1]>body[2]) and (upperwick<0.1*body and lowerwick<0.1*body) and isTrendDown
plotshape(tws, color=green, style=shape.triangleup, location=location.belowbar, title='three white soldiers',text='tws')

if (not na(rsi))
    if (crossover(rsi, level_30) and (tws or tws[1]))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
        
// three black crows
tbc = (isUp[3] and not isUp[2] and not isUp[1] and not isUp) and (body[1]>body[2]) and (upperwick<0.1*body and lowerwick<0.1*body) and isTrendUp
plotshape(tbc, color=red, style=shape.triangledown, location=location.abovebar, title='three black crows',text='tbc')

if (not na(rsi))
    if (crossunder(rsi, level_70)and (tbc or tbc[1]))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        
// morning star
ms = (not isUp[1]) and (abs(close[1]-open[1])/(high[1]-low[1]) < 0.1) and (close > oc2[2] and close < open[2]) and isTrendDown
plotshape(ms, color=green, style=shape.triangleup, location=location.belowbar, title='morning star',text='ms')

if (not na(rsi))
    if (crossover(rsi, level_30) and (ms or ms[1]))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
        
// evening star
es = (isUp[1]) and (abs(close[1]-open[1])/(high[1]-low[1]) < 0.1) and (close < oc2[2] and close > open[2]) and isTrendUp
plotshape(es, color=red, style=shape.triangledown, location=location.abovebar, title='evening star',text='es')

//if (not na(rsi))
//    if (crossunder(rsi, level_70)and (es or es[1]))
//        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        
// three inside up
tiu = (not isUp[2]) and (close[1] > oc2[2] and close[1] < open[2]) and (close > high[2]) and isTrendDown
plotshape(tiu, color=green, style=shape.triangleup, location=location.belowbar, title='three inside up',text='tiu')

if (not na(rsi))
    if (crossover(rsi, level_30) and (tiu or tiu[1]))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
        
// three inside down
tid = (isUp[2]) and (close[1] < oc2[2] and close[1] > open[2]) and (close < low[2]) and isTrendUp
plotshape(tid, color=red, style=shape.triangledown, location=location.abovebar, title='three inside down',text='tid')

if (not na(rsi))
    if (crossunder(rsi, level_70)and (tid or tid[1]))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")
        
if (not na(rsi))
    if (crossover(rsi, level_70))
        //strategy.exit("RsiSE")
        //if(chk[1]==0 or chk[2]==0 or chk[3]==0 or chk[4]==0 or chk[5]==0 or chk[6]==0 or chk[7]==0 or chk[8]==0 or chk[9]==0 or chk[10]==0)
        //if(crossover(col[1],zero) or crossover(col[2],zero) or crossover(col[3],zero) or crossover(col[4],zero) or crossover(col[5],zero) or crossover(col[6],zero) or crossover(col[7],zero) or crossover(col[8],zero))
        //strategy.entry("RsiLE", strategy.long,0, comment="RsiLE")
        strategy.entry("RsiSE", strategy.short,0, comment="RsiSE")

    if (crossunder(rsi, level_30))
        //strategy.entry("RsiSE", strategy.short,0, comment="RsiSE")
        strategy.entry("RsiLE", strategy.long,0, comment="RsiLE")

//if (not na(rsi))
//    if (crossover(rsi, level_50))
        //strategy.exit("RsiSE")
        //if(chk[1]==0 or chk[2]==0 or chk[3]==0 or chk[4]==0 or chk[5]==0 or chk[6]==0 or chk[7]==0 or chk[8]==0 or chk[9]==0 or chk[10]==0)
        //if(crossover(col[1],zero) or crossover(col[2],zero) or crossover(col[3],zero) or crossover(col[4],zero) or crossover(col[5],zero) or crossover(col[6],zero) or crossover(col[7],zero) or crossover(col[8],zero))
//        strategy.entry("RsiSE", strategy.short,0, comment="RsiSE")
//    else
//        strategy.exit("RsiSE")
//    if (crossunder(rsi, level_50))
//        strategy.entry("RsiLE", strategy.long,0, comment="RsiLE")
//    else
//        strategy.exit("RsiLE")