3배 기하급수적 이동 평균 컨버전스 디버전스 및 상대적 강도 지표 결합 1분 차트 암호화폐 양적 거래 전략

저자:차오장, 날짜: 2024-03-29 11:16:10
태그:

img

전반적인 설명

이 전략은 트리플 익스포넌셜 모닝 평균 컨버전스 디버전스 (Triple MACD) 와 상대 강도 지수 (RSI) 방법을 결합하여 1분 시간 프레임에서 암호화폐 시장의 양적 거래에 특별히 설계되었습니다. 전략의 주된 아이디어는 다른 기간 매개 변수와 함께 MACD 지표를 사용하여 상승 및 하락 동력의 변화를 포착하는 한편, 트렌드 강도를 확인하기 위해 RSI 지표를 사용하는 것입니다. 세 가지 MACD 신호의 평균을 통해 소음을 효과적으로 부드럽게하여 거래 신호의 신뢰성을 향상시킬 수 있습니다. 또한 전략은 시장의 통합 단계를 식별하기 위해 선형 회귀 기술을 활용하여 가격 행동 중에 빈번한 거래를 피합니다. 이 전략은 전체 암호화폐 시장의 급속한 변동 속에서도 안정적인 수익을 창출 할 수있는 격자 거래에 적합합니다.

전략 원칙

이 전략은 5/13/34의 빠른 라인 기간과 8/21/144의 느린 라인 기간이라는 다른 매개 변수를 가진 세 개의 MACD 지표를 사용합니다. MACD 값을 얻기 위해 이들 사이의 차이를 계산합니다. 이 세 가지 MACD 값은 평균화되고 최종 MACD 히스토그램은 평균 MACD에서 신호 값 (MACD의 N-period EMA) 을 빼서 도출됩니다. 동시에, 트렌드 강도를 결정하는 데 도움이되는 14 기간 RSI 지표가 계산됩니다. 평균 MACD 히스토그램이 음에서 양으로 이동하고, RSI는 55 이하이고, 상승률이 발생하면 긴 신호가 생성됩니다. 반대로 평균 MACD 히스토그램이 양에서 음으로 변화하고, RSI는 45 이상이고, 호환 전략이 발생하면 긴 신호가 발생합니다. 또한, 촛불의 길이를 분석하여 시장의 길이를 따라 변하는 촛불 그림자를 식별하는 11 기간 회귀 라인을 적용합니다.

이점 분석

  1. 여러 기간 MACD 지표의 조합은 다른 시간 스케일에서 시장의 트렌드 변화를 객관적으로 반영하여 트렌드 식별의 정확성을 향상시킵니다.
  2. MACD를 RSI 지표와 통합하면 엄격한 진입 및 출구 조건을 형성하여 전략 수익성 향상 및 유출 통제에 기여합니다.
  3. MACD 신호를 평균화하면 자주 표시 변동으로 인한 잘못된 신호를 효과적으로 제거하여 거래 신호를 더 신뢰할 수 있습니다.
  4. 선형 회귀를 사용하여 시장의 범위를 결정하는 것은 트렌드가 불분명할 때 변동하는 시장에서 거래에 들어가는 것을 피하고 손실 거래를 줄이는 데 도움이됩니다.
  5. 급변하는 암호화폐 시장에서 1분 수준의 양적 거래 전략은 시장 변동으로 인한 거래 기회를 적시에 포착하는 데 더 적합합니다.

위험 분석

  1. 이 전략은 단방향 트렌드 시장에서 더 잘 수행됩니다. 시장이 장기간 광범위한 오스실레이션 상태로 남아있는 경우 거래 신호가 종종 무효가 될 수 있습니다.
  2. 암호화폐 시장의 높은 변동성으로 인해 단기적으로 극심한 비정상적인 변동은 상당한 마감으로 이어질 수 있습니다.
  3. 전략 매개 변수 선택은 전반적인 수익성에 명확한 영향을 미칩니다. 잘못된 매개 변수 설정으로 인해 전략이 실패 할 수 있습니다. 따라서 라이브 거래 전에 다양한 거래 도구에 대한 충분한 매개 변수 최적화 및 백테스팅 검증이 필요합니다.

최적화 방향

  1. 입시 신호를 필터링하고 비정상적인 시장 변동으로 인한 잠재적 손실을 줄이기 위해 ATR과 같은 가격 변동과 관련된 지표를 도입하는 것을 고려하십시오.
  2. 선형 회귀 외에도 다른 방법들, 예를 들어 지원 수준과 저항 수준, 볼링거 밴드 채널 등은 범위 시장을 식별하는 정확성을 더욱 향상시키기 위해 탐색될 수 있다.
  3. 트렌드 시장에서는 매 거래의 수익을 극대화하여 출구 지점을 최적화하기 위해 후속 스톱 로스를 도입합니다.
  4. 다양한 거래 도구의 특징적인 차이점을 고려하여, 전체 전략의 적응성과 안정성을 높이기 위해 다른 도구에 대한 다른 전략 매개 변수를 설정합니다.

요약

이 전략은 트리플 MACD를 RSI 지표와 똑똑하게 결합하고 선형 회귀 기술을 활용하여 범위 시장을 식별하여 고주파 양적 거래 전략의 완전한 세트를 형성합니다. 엄격한 입출시장 조건과 평균 MACD 신호의 적용은 거래 정확성과 드래운 다운 컨트롤을 향상시키는 데 기여합니다. 전략이 일방향 트렌드 시장에서 더 잘 수행되지만 변동성 필터 도입, 범위 시장 식별 방법 최적화, 트레일링 스톱 로스 설정 및 다른 도구에 대한 독립적인 매개 변수를 설정하는 등의 조치는 전략의 적응성과 견고성을 더욱 향상시킬 수 있습니다. 전반적으로 이것은 더 이상 최적화 및 라이브 거래 응용을받을 가치가있는 매우 유망한 암호화폐 양적 거래 전략입니다.


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

//@version=5
strategy(title="TrippleMACD", shorttitle="TrippleMACD + RSI strategy", format=format.price, precision=4, overlay=true)

// RSI 
ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
showDivergence = input.bool(false, title="Show Divergence", group="RSI Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"

bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)

// Divergence
lookbackRight = 5
lookbackLeft = 5
rangeUpper = 60
rangeLower = 5
bearColor = color.red
bullColor = color.green
textColor = color.white
noneColor = color.new(color.white, 100)

plFound = na(ta.pivotlow(rsi, lookbackLeft, lookbackRight)) ? false : true
phFound = na(ta.pivothigh(rsi, lookbackLeft, lookbackRight)) ? false : true
_inRange(cond) =>
	bars = ta.barssince(cond == true)
	rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// rsi: Higher Low

rsiHL = rsi[lookbackRight] > ta.valuewhen(plFound, rsi[lookbackRight], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
bullCondAlert = priceLL and rsiHL and plFound
bullCond = showDivergence and bullCondAlert

// rsi: Lower High

rsiLH = rsi[lookbackRight] < ta.valuewhen(phFound, rsi[lookbackRight], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)

bearCondAlert = priceHH and rsiLH and phFound
bearCond = showDivergence and bearCondAlert

// Getting inputs
stopLuse          = input(1.040)
fast_length = input(title = "Fast Length", defval = 5)
slow_length = input(title = "Slow Length", defval = 8)
fast_length2 = input(title = "Fast Length2", defval = 13)
slow_length2 = input(title = "Slow Length2", defval = 21)
fast_length3 = input(title = "Fast Length3", defval = 34)
slow_length3 = input(title = "Slow Length3", defval = 144)
fast_length4 = input(title = "Fast Length3", defval = 68)
slow_length4 = input(title = "Slow Length3", defval = 288)
src = input(title = "Source", defval = close)
signal_length2 = input.int(title="Signal Smoothing", minval = 1, maxval = 200, defval = 11)
signal_length = input.int(title = "Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title = "Oscillator MA Type",  defval = "EMA", options = ["SMA", "EMA"])
sma_signal = input.string(title = "Signal Line MA Type", defval = "EMA", options = ["SMA", "EMA"])
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)

fast_ma2 = sma_source == "SMA2" ? ta.sma(src, fast_length2) : ta.ema(src, fast_length2)
slow_ma2 = sma_source == "SMA2" ? ta.sma(src, slow_length2) : ta.ema(src, slow_length2)

fast_ma3 = sma_source == "SMA3" ? ta.sma(src, fast_length3) : ta.ema(src, fast_length3)
slow_ma3 = sma_source == "SMA3" ? ta.sma(src, slow_length3) : ta.ema(src, slow_length3)

fast_ma4 = sma_source == "SMA3" ? ta.sma(src, fast_length3) : ta.ema(src, fast_length3)
slow_ma4 = sma_source == "SMA3" ? ta.sma(src, slow_length3) : ta.ema(src, slow_length3)

macd = fast_ma - slow_ma
macd2 = fast_ma2 - slow_ma2
macd3 = fast_ma3 - slow_ma3
macd4 = fast_ma4 - slow_ma4

signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
signal2 = sma_signal == "SMA" ? ta.sma(macd2, signal_length) : ta.ema(macd2, signal_length)
signal3 = sma_signal == "SMA" ? ta.sma(macd3, signal_length) : ta.ema(macd3, signal_length)
signal4 = sma_signal == "SMA" ? ta.sma(macd4, signal_length) : ta.ema(macd4, signal_length)
//hist = (macd + macd2 + macd3)/1 - (signal + signal2 + signal3)/1
hist = (macd + macd2 + macd3 + macd4)/4 - (signal + signal2 + signal3 + signal4)/4
signal5 = (signal + signal2 + signal3)/3

sma_signal2 = input.bool(title="Simple MA (Signal Line)", defval=true)

lin_reg = input.bool(title="Lin Reg", defval=true)
linreg_length = input.int(title="Linear Regression Length", minval = 1, maxval = 200, defval = 11)

bopen = lin_reg ? ta.linreg(open, linreg_length, 0) : open
bhigh = lin_reg ? ta.linreg(high, linreg_length, 0) : high
blow = lin_reg ? ta.linreg(low, linreg_length, 0) : low
bclose = lin_reg ? ta.linreg(close, linreg_length, 0) : close

shadow = (bhigh - bclose) + (bopen - blow)
body = bclose - bopen
perc = (shadow/body)
cond2 = perc >=2 and bclose+bclose[1]/2 > bopen+bopen[1]/2

r = bopen < bclose

//signal5 = sma_signal2 ? ta.sma(bclose, signal_length) : ta.ema(bclose, signal_length)
plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow: na, r ? bclose : na, title="LinReg Candles", color= color.green, wickcolor=color.green, bordercolor=color.green, editable= true)
plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose, title="LinReg Candles", color=color.red, wickcolor=color.red, bordercolor=color.red, editable= true)
//alertcondition(hist[1] >= 0 and hist < 0, title = 'Rising to falling', message = 'The MACD histogram switched from a rising to falling state')
//alertcondition(hist[1] <= 0 and hist > 0, title = 'Falling to rising', message = 'The MACD histogram switched from a falling to rising state')

green = hist >= 0 ? (hist[1] < hist ? "G" : "GL") : (hist[1] < hist ? "RL" : "R")
Buy = green == "G" and green[1] != "G" and green[1] != "GL" and bopen < bclose and rsi < 55.0 //and not cond2
//StopBuy = (green == "R" or green == "RL" or green == "RL") and bopen > bclose and bopen[1] < bclose[1]
StopBuy = bopen > bclose and bopen[1] < bclose[1] and (green == "G" or green == "GL" or green == "R") and bopen[2] < bclose[2] and bopen[3] < bclose[3]
hists = close[3] < close[2] and close[2] < close[1]
//Buy = green == "RL" and hist[0] > -0.07 and hist[0] < 0.00 and rsi < 55.0 and hists
//StopBuy = green == "GL" or green == "R"
alertcondition(Buy, "Long","Покупка в лонг")
alertcondition(StopBuy, "StopLong","Закрытие сделки")

//hline(0, "Zero Line", color = color.new(#787B86, 50))
plot(hist + (close - (close * 0.03)), title = "Histogram", style = plot.style_line, color = (hist >= 0 ? (hist[1] < hist ? #26A69A : #B2DFDB) : (hist[1] < hist ? #FFCDD2 : #FF5252)))
plotshape(Buy ? low : na, 'Buy', shape.labelup, location.belowbar , color=color.new(#0abe40, 50), size=size.small, offset=0)
plotshape(StopBuy ? low : na, 'Buy', shape.cross, location.abovebar , color=color.new(#be0a0a, 50), size=size.small, offset=0)
plot(macd4  + (close - (close * 0.01)),   title = "MACD",   color = #2962FF)
plot(signal5 + (close - (close * 0.01)), title = "Signal", color = #FF6D00)

plotchar(cond2 , char='↓', color = color.rgb(0, 230, 119), text = "-")

if (Buy)
    strategy.entry("long", strategy.long)

// if (startShortTrade)
//     strategy.entry("short", strategy.short)

profitTarget = strategy.position_avg_price * stopLuse
strategy.exit("Take Profit", "long", limit=profitTarget)
// strategy.exit("Take Profit", "short", limit=profitTarget)

더 많은