월 플래그 MACD 모멘텀 스톡RSI 거래 전략

저자:차오장, 날짜: 2024-02-23 15:06:59
태그:

img

전반적인 설명

월 플래그 MACD 모멘텀 스톡RSI 거래 전략은 판단을 위해 MACD, 모멘텀 및 스톡RSI 지표를 활용하는 양적 거래 전략입니다. 주로 비트코인 및 이더리움 매일 거래에 적합합니다.

전략 논리

이 전략은 다음의 핵심 지표를 이용해서 판단합니다.

  1. MACD 지표: 빠른 SMA 기간은 50이며 느린 SMA 기간은 200이며 일반적으로 사용되는 50 일선과 200 일선을 나타냅니다. 이 지표는 시장의 장기 트렌드 방향을 판단합니다.

  2. 맞춤형 동력 지표: 시장의 단기 동력 방향을 판단하는 데 사용되는 스톡 지표와 본질적으로 유사합니다.

  3. 스톡RSI 지표: 시장의 강도와 과잉 구매/ 과잉 판매 수준을 판단합니다.

장기화하기 위해서는 MACD>0 (중장기 상승 추세를 나타내는) 의 3가지 조건, 사용자 지정 모멘텀 지표 >0 (단기 상승 동력을 나타내는) 과 이전 클로즈보다 높은 클로즈 가격 (현행 상승 추세를 나타내는) 의 3가지 조건을 동시에 충족해야 합니다.

긴 신호를 닫는 것은 조금 더 복잡하며 MACD <0, 사용자 지정 모멘텀 표시기 <0, 이전 클로즈보다 낮은 클로즈 가격과 StochRSI>20 4 가지 조건을 동시에 충족시켜야합니다.

이 전략은 중장기 동향, 단기 동력 및 현재 동향을 포괄적으로 판단하며 비교적 견고한 브레이크아웃 시스템입니다.

전략 의 장점

  1. 여러 지표에 대한 포괄적 인 판단은 잘못된 신호를 생성하는 것을 피합니다

  2. MACD 매개 변수 선택은 시장에서 중요한 50일 라인과 200일 라인을 고려합니다.

  3. 각 지표의 매개 변수가 테스트된 후, 전략 성과가 거의 변하지 않았고, 과도한 적합성 위험을 피했습니다.

  4. 높은 신뢰성으로 충분한 데이터로 백테스트

전략 의 위험

  1. 브레이크아웃 시스템은 중재율에 취약하여 거래 수와 미끄러짐 비용을 증가시킬 수 있습니다.

  2. 포괄적 인 다중 지표 판단과 함께 높은 복잡성, 매개 변수 조정 및 최적화에 어려움이 있습니다.

  3. 높은 내일 단기 거래 위험

최적화 방향

  1. 거래량과 같은 더 많은 지표의 분석을 포함합니다.

  2. 동적 매개 변수 최적화를 위한 기계 학습 알고리즘을 늘려

  3. 거래 빈도가 낮고 판단의 주기율이 높습니다.

요약

월 플래그 MACD 모멘텀 스톡RSI 거래 전략은 여러 지표로 시장 추세와 강도를 포괄적으로 판단하고, 좋은 백테스트 결과와 높은 신뢰성을 가지고 있으며, 경험이 많은 양적 거래자가 품질 암호화폐에 적용하고 최적화하는 데 적합합니다.


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

// // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// // © MoonFlag
//@version=5
strategy("MoonFlag 1D MACD Momentum StochRSI Strategy", max_bars_back=500, overlay=false, initial_capital=5000, default_qty_type=strategy.percent_of_equity, default_qty_value=80, pyramiding=0, calc_on_order_fills=true)


d(gaps_1, data)=>
    float out = 0.
    out :=(ta.wma(ta.wma(ta.wma(data,  math.round(((1 * gaps_1) - math.round((1 * gaps_1) / 3)) / 2)), math.round((1 * gaps_1) / 3)) , int(((1 * gaps_1) - math.round((1 * gaps_1) / 3)) / 2)))
    out
MoonFlagAverage(gaps_1,data)=>
    float out = 0.
    out:=d(gaps_1,d(gaps_1, d(gaps_1, data)))
    out

fastLength = input.int(50,  "MACD SMA Fast Length")
slowlength = input.int(200, "MACD SMA Slow Length")
MACDLength = 9//input.int(9,   "MACD Length")

MACD  = ta.ema(close, fastLength) - ta.ema(close, slowlength)
aMACD = ta.sma(MACD, MACDLength)
MACDdelta = MACD - aMACD

//plot (MACD, "MACD1", color.red)
//plot (aMACD, "aMACD1", color.green)
//plot (delta, "MACD delta", color.white)

fastLength2 = input.int(12, "MoonFlag Momentum Length")
slowlength2 = 2*fastLength2//input.int(50, "MoonFlag Momentum Slow Length")
MACDLength2 = 20//input.int(20, "Momentum Delta")

MoonFlag_MACD2 = MoonFlagAverage(fastLength2, close) - MoonFlagAverage(slowlength2,close)
MoonFlag_aMACD2 = MoonFlagAverage(MACDLength2, MoonFlag_MACD2)

MoonFlag_delta = MoonFlag_MACD2 - MoonFlag_aMACD2
MoonFlag_delta_line=0
if MoonFlag_delta < 0
    MoonFlag_delta_line:=-100
else
    MoonFlag_delta_line:=100
//plot (MoonFlag_MACD2, "MoonFlag Momentum Fast Length", color.red)
//plot (MoonFlag_aMACD2, "MoonFlag Momentum Slow Length", color.green)
//plot (MoonFlag_delta2, "MoonFlag Delta", color.white)

uptrend   = (close + high)/(close[1] + high[1])
downtrend =  (close + low)/(close[1] + low[1])

lineColor = color.green
if uptrend > 1
    lineColor := color.green
if downtrend < 1
    lineColor := color.red

smoothK     = 2//input.int(2, minval=1, title="K smoothing Stoch RSI")
smoothD     = 3//input.int(3, minval=1, title= "D smoothing for Stoch RSI")
lengthRSI   = 7//input.int(7, minval=1, title="RSI Length")
lengthStoch = 8//input.int(8, minval=1, title="Stochastic Length")
src = close//input(close, title="RSI Source")

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

MACDdirection_line = 0
MACDdirection_line := MACDdirection_line[1]
if (MACDdelta > 0) 
    MACDdirection_line := 50
if (MACDdelta < 0) 
    MACDdirection_line := -50

useStochRSI = input.bool(true,"Include Condition (StochRSI > 20) with Exit Long/Enter Short")
StochRSI_val = 20//input.int(20,"StochRSI greater than to exit short")
h1 = hline(StochRSI_val)

StochRSIGreaterThanSetValue = true
if useStochRSI
    if  (StochRSI > StochRSI_val)
        StochRSIGreaterThanSetValue := true
    else
        StochRSIGreaterThanSetValue := false

stoch20 = lineColor
if StochRSI < StochRSI_val
    stoch20 := color.white

yearin = input.int(2019, title="Start backtesting from year:")

includeShorts = false//input.bool(false, "Include Shorts")

plot(MoonFlag_delta_line,"MoonFlag Momentum Direction", color.white)
plot(MACDdirection_line,"MACD Direction", color = color.orange)
plot(StochRSI, "StochRSI", color=lineColor)

if  (year>=yearin)
    if (MACDdelta > 0) and (uptrend > 1)   and MoonFlag_delta_line > 0
        strategy.entry("buy2", strategy.long, comment="buy")
    if (MACDdelta < 0) and (downtrend < 1) and MoonFlag_delta_line < 0 and StochRSIGreaterThanSetValue
        if includeShorts    
            strategy.entry("sell", strategy.short, comment="sell")
        else
            strategy.close("buy2", comment = "sell")



더 많은