EMA 및 스토카스틱 RSI 기반의 다중 시간 프레임 트렌드 거래 전략

저자:차오장, 날짜: 2024-03-08 17:32:38
태그:

img

전략 개요

이 전략은 EMA 및 스토카스틱 RSI 기반의 멀티 타임프레임 트렌드 다음 트레이딩 전략으로, 다른 기간과 스토카스틱 RSI 지표와 두 개의 기하급수적인 이동 평균 (EMA) 을 사용하여 중장기 시장 트렌드를 파악합니다. 핵심 아이디어는 EMA 크로스오버를 기반으로 트렌드 방향을 결정하는 데 있으며, 스토카스틱 RSI를 트렌드 강도 및 잠재적 인 반전을 확인하는 신호로 사용합니다. 트렌드의 시작에서 포지션을 열고 끝으로 닫습니다.

전략 원칙

  1. 빠른 EMA와 느린 EMA를 계산한다. 빠른 EMA의 기본 매개 변수는 12, 느린 EMA의 기본 매개 변수는 25이다. 시장 특성과 거래 빈도에 따라 조정될 수 있다.

  2. 상승/하락 추세를 결정합니다.

  • 빠른 EMA가 느린 EMA를 넘을 때 상승 신호가 발생합니다.
  • 빠른 EMA가 느린 EMA 아래로 넘어가면 하향 신호를 발생시킵니다.
  1. 트렌드 확인: 상승/하락 신호가 나타난 후, 트렌드를 확인하기 위해 2 개의 연속 상승/하락 촛불이 필요합니다. 이것은 잘못된 신호를 필터링하는 데 도움이됩니다.

  2. 보조적인 판단으로 스토카스틱 RSI를 사용하세요:

  • 스토카스틱 RSI %K 라인이 %D 라인의 위를 넘어서고 %K가 20보다 낮으면 과잉 판매 신호를 생성하여 잠재적인 상승 반전을 나타냅니다.
  • 스토카스틱 RSI %K 라인이 %D 라인 아래로 넘어가고 %K가 80보다 높을 때, 잠재적인 하향 반전을 나타내는 과잉 구매 신호를 생성합니다.
  1. 거래 규칙:
  • EMA가 상승 신호를 생성하고 스토카스틱 RSI가 과잉 매수 영역에 있지 않은 경우 긴 지위를 열기
  • EMA가 하향 신호를 생성하고 스토카스틱 RSI가 과판 영역에 있지 않을 때 짧은 지위를 열기

전략적 장점

  1. 서로 다른 기간에 두 개의 EMA를 사용함으로써 전략은 트렌드 포착의 민감성과 신뢰성을 더 잘 균형 잡을 수 있습니다. 분석은 12/25 기간 EMA 조합이 중장기 트렌드에 잘 수행된다는 것을 보여줍니다.

  2. 트렌드 확인 메커니즘은 대부분의 잘못된 신호를 효과적으로 필터링하여 승률을 향상시킬 수 있습니다.

  3. 스토카스틱 RSI는 보조 판단으로 작용하여 초기 단계에서 트렌드 강도를 평가하고 늦은 단계에서 잠재적 인 반전을 미리 경고합니다.

  4. 전략 논리는 몇 가지 매개 변수와 함께 간단하여 이해하기 쉽고 구현하기 쉽습니다. 또한 다양한 시장과 도구에 적용됩니다.

위험 분석

  1. EMA는 뒤떨어진 지표이며 트렌드 전환의 시작에 상당한 미끄러짐을 초래할 수 있습니다.

  2. 트렌드를 따르는 전략은 일반적으로 불안정한 시장에서 낮은 성과를 내고 있습니다. 이 전략은 범위 조건에 대한 구체적인 판단이 부족합니다.

  3. 스토카스틱 RSI는 극심한 시장 변동성 동안 잘못된 신호를 생성하여 판단 품질에 영향을 줄 수 있습니다.

  4. 고정된 매개 변수는 모든 시장 조건에 적응하지 않을 수 있으며 시장 특성에 따라 동적 조정이 필요합니다.

최적화 방향

  1. ATR 같은 변동성 지표를 도입하여 EMA 매개 변수를 동적으로 조정하고 다른 시장 리듬에 적응합니다.

  2. 폭이 제한된 시장에 대한 판단을 추가하십시오. 예를 들어 볼링거 밴드 폭을 결합하여 불안정한 조건에서 빈번한 거래를 피하십시오.

  3. 신호 신뢰성을 향상시키기 위해 볼륨 변화와 같은 스토카스틱 RSI 위에 더 많은 보조 기준을 포함합니다.

  4. 시장 상관관계를 고려하고 시스템의 위험 회복력을 높이기 위해 여러 자산의 시장 간 신호를 도입하십시오.

요약

이 전략은 EMA와 스토카스틱 RSI의 강점을 효과적으로 활용하여 트렌드 추적 및 모멘텀 반전을 기반으로 중장기 거래 접근 방식을 형성합니다. EMA 크로스오버를 통해 트렌드를 캡처하고 스토카스틱 RSI로 트렌드 강도를 확인하고 반전을 경고하며 트렌드 확인 메커니즘으로 신호 품질을 향상시킵니다. 세 가지 구성 요소가 유기적으로 결합하여 간단하고 효과적인 양적 거래 전략 프레임워크를 만듭니다. 주요 장점은 간결한 논리, 몇 가지 매개 변수, 낮은 구현 어려움 및 광범위한 적용 가능성에 있습니다. 그러나 전략은 또한 큰 미끄러움과 불안정한 시장에 적응할 수 없다는 것과 같은 고유 한계도 있습니다. 향후 개선은 동적 매개 변수 최적화, 더 많은 보조 기준을 도입하고 시장 간 링크 메커니즘을 구축하는 데 초점을 맞출 수 있습니다. 전반적으로, 이것은 양적 거래 방안으로 최적화되고 광범위한 응용 가능성이 있습니다.


/*backtest
start: 2023-03-02 00:00:00
end: 2024-03-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('[Jacky] Trader XO Macro Trend Scanner', overlay=true)

// Variables
var ok = 0
var countBuy = 0
var countSell = 0
src = input(close, title='OHLC Type')
i_fastEMA = input(12, title='Fast EMA')
i_slowEMA = input(25, title='Slow EMA')
i_defEMA = input(25, title='Consolidated EMA')

// Allow the option to show single or double EMA
i_bothEMAs = input(title='Show Both EMAs', defval=true)

// Define EMAs
v_fastEMA = ta.ema(src, i_fastEMA)
v_slowEMA = ta.ema(src, i_slowEMA)
v_biasEMA = ta.ema(src, i_defEMA)

// Color the EMAs
emaColor = v_fastEMA > v_slowEMA ? color.green : v_fastEMA < v_slowEMA ? color.red : #FF530D

// Plot EMAs
plot(i_bothEMAs ? na : v_biasEMA, color=emaColor, linewidth=3, title='Consolidated EMA')
plot(i_bothEMAs ? v_fastEMA : na, title='Fast EMA', color=emaColor)
plot(i_bothEMAs ? v_slowEMA : na, title='Slow EMA', color=emaColor)

// Colour the bars
buy = v_fastEMA > v_slowEMA
sell = v_fastEMA < v_slowEMA

if buy
    countBuy += 1
    countBuy

if buy
    countSell := 0
    countSell

if sell
    countSell += 1
    countSell

if sell
    countBuy := 0
    countBuy

buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and not buy[1]
sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and not sell[1]

barcolor(buysignal ? color.green : na)
barcolor(sellsignal ? color.red : na)

// Strategy backtest
if (buysignal)
    strategy.entry("Buy", strategy.long)

if (sellsignal)
    strategy.entry("Sell", strategy.short)

// Plot Bull/Bear

plotshape(buysignal, title='Bull', text='Bull', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.black, 0), size=size.tiny)
plotshape(sellsignal, title='Bear', text='Bear', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.black, 0), size=size.tiny)

bull = countBuy > 1
bear = countSell > 1

barcolor(bull ? color.green : na)
barcolor(bear ? color.red : na)

// Set Alerts

alertcondition(ta.crossover(v_fastEMA, v_slowEMA), title='Bullish EMA Cross', message='Bullish EMA crossover')
alertcondition(ta.crossunder(v_fastEMA, v_slowEMA), title='Bearish EMA Cross', message='Bearish EMA Crossover')

// Stoch RSI code

smoothK = input.int(3, 'K', minval=1)
smoothD = input.int(3, 'D', minval=1)
lengthRSI = input.int(14, 'RSI Length', minval=1)
lengthStoch = input.int(14, 'Stochastic Length', minval=1)

rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

bandno0 = input.int(80, minval=1, title='Upper Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno2 = input.int(50, minval=1, title='Middle Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno1 = input.int(20, minval=1, title='Lower Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')

// Alerts

crossoverAlertBgColourMidOnOff = input.bool(title='Crossover Alert Background Colour (Middle Level) [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourOBOSOnOff = input.bool(title='Crossover Alert Background Colour (OB/OS Level) [ON/OFF]', group='Crossover Alerts', defval=false)

crossoverAlertBgColourGreaterThanOnOff = input.bool(title='Crossover Alert >input [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourLessThanOnOff = input.bool(title='Crossover Alert <input [ON/OFF]', group='Crossover Alerts', defval=false)

maTypeChoice = input.string('EMA', title='MA Type', group='Moving Average', options=['EMA', 'WMA', 'SMA', 'None'])
maSrc = input.source(close, title='MA Source', group='Moving Average')
maLen = input.int(200, minval=1, title='MA Length', group='Moving Average')

maValue = if maTypeChoice == 'EMA'
    ta.ema(maSrc, maLen)
else if maTypeChoice == 'WMA'
    ta.wma(maSrc, maLen)
else if maTypeChoice == 'SMA'
    ta.sma(maSrc, maLen)
else
    0

crossupCHECK = maTypeChoice == 'None' or open > maValue and maTypeChoice != 'None'
crossdownCHECK = maTypeChoice == 'None' or open < maValue and maTypeChoice != 'None'

crossupalert = crossupCHECK and ta.crossover(k, d) and (k < bandno2 or d < bandno2)
crossdownalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno2 or d > bandno2)
crossupOSalert = crossupCHECK and ta.crossover(k, d) and (k < bandno1 or d < bandno1)
crossdownOBalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno0 or d > bandno0)

aboveBandalert = ta.crossunder(k, bandno0)
belowBandalert = ta.crossover(k, bandno1)

bgcolor(color=crossupalert and crossoverAlertBgColourMidOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert Background Colour (Middle Level)', transp=70)
bgcolor(color=crossupOSalert and crossoverAlertBgColourOBOSOnOff ? #fbc02d : crossdownOBalert and crossoverAlertBgColourOBOSOnOff ? #000000 : na, title='Crossover Alert Background Colour (OB/OS Level)', transp=70)

bgcolor(color=aboveBandalert and crossoverAlertBgColourGreaterThanOnOff ? #ff0014 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K > Upper level', transp=70)
bgcolor(color=belowBandalert and crossoverAlertBgColourLessThanOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K < Lower level', transp=70)

alertcondition(crossupalert or crossdownalert, title='Stoch RSI Crossover', message='STOCH RSI CROSSOVER')





더 많은