삼중 이동 평균 양적 거래 전략

저자:차오장, 날짜: 2024-01-23 14:20:50
태그:

img

이 전략은 다른 기간의 세 개의 이동 평균을 계산하고 가격 돌파구를 결합하여 거래 신호를 생성합니다. 이는 전형적인 트렌드 추적 전략에 속합니다. 전략은 시장의 중장기 트렌드를 따라가며 파러미터를 동적으로 조정하여 다른 제품과 거래 환경에 적응 할 수 있습니다.

원칙

이 전략은 MA1, MA2 및 MA3의 이동 평균을 3개로 구성합니다. MA1 및 MA2는 거래 채널을 형성하고, 그들의 크로스오버는 거래 신호를 생성합니다. MA3는 신호를 필터링하는 데 사용됩니다.

빠른 이동 평균 MA1이 중장기 이동 평균 MA2를 넘으면 단기 트렌드의 강화를 나타냅니다. 이 시점에서 가격이 장기 이동 평균 MA3보다 높으면 긴 신호가 생성됩니다. 반대로 MA1이 MA2를 넘어서 가격이 MA3보다 낮으면 짧은 신호가 생성됩니다.

MA3의 역할은 단기 시장 소음을 필터링하고 중장기 단계로 진입한 경향을 결정한 후에 신호를 생성하는 것입니다. 세 이동 평균의 매개 변수를 동적으로 조정함으로써 전략은 다른 시장에서 최적의 매개 변수 조합을 찾을 수 있습니다.

장점

  • 여러 이동 평균을 통해 다른 주기의 경향을 포착
  • MA3는 화살기를 피하기 위해 신호를 필터링합니다.
  • 조정 가능한 이동 평균 유형 및 매개 변수, 높은 적응력
  • 신호 포인트를 식별하기 위해 십자가를 시각화

위험성

  • 주요 트렌드가 역전될 때 이동 평균이 늦어질 수 있습니다.
  • 잠재적으로 높은 거래 빈도, 증가하는 거래 비용 및 미끄러짐 위험
  • 부적절한 매개 변수는 오버 트레이딩 또는 지연 신호를 일으킬 수 있습니다.

다른 제품에 대한 MA 기간을 최적화 할 수 있습니다. 단일 손실을 제어하기 위해 스톱 손실을 최적화 할 수 있습니다. 신호 유효성을 확인하고 잘못된 신호를 줄이기 위해 다른 기술적 지표를 결합 할 수 있습니다.

최적화 방향

  • 추세를 결정하기 위해 다른 지표를 추가하십시오. 예를 들어 MACD, 볼링거 밴드 등.
  • 스톱 로스/프로프트 취득 전략을 추가합니다.
  • 최적의 조합을 찾기 위해 동적으로 매개 변수를 조정
  • 다른 제품에 대한 매개 변수 최적화
  • 거래 비용을 고려하고 거래 빈도를 최적화하십시오.

요약

이 전략은 세 개의 이동 평균을 계산하고 그 교차점을 관찰함으로써 거래 신호를 생성한다. 트렌드를 결정하기 위해 빠른, 중간 및 느린 라인을 결합하는 아이디어를 사용하여 전형적인 트렌드를 따르는 전략이다. 이 전략은 매개 변수 최적화를 통해 다른 제품에 적응할 수 있지만, 윙사 및 놓친 회전 위험이 있다. 미래의 개선은 신호 유효성을 판단하기 위해 다른 기술적 지표를 도입하고, 동적 매개 변수 최적화 메커니즘을 개발하여 전략을 보다 유연하게 할 수 있다.


/*backtest
start: 2023-01-16 00:00:00
end: 2024-01-22 00:00:00
period: 1d
basePeriod: 1h
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/
// © Meesemoo

//@version=4
strategy("Custom MA Strategy Tester", overlay = true)
MA1Period = input(13, title="MA1 Period")
MA1Type = input(title="MA1 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA", "DEMA", "TEMA"])
MA1Source = input(title="MA1 Source", type=input.source, defval=close)
MA1Visible = input(title="MA1 Visible", type=input.bool, defval=true)
MA2Period = input(50, title="MA2 Period")
MA2Type = input(title="MA2 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA", "DEMA", "TEMA"])
MA2Source = input(title="MA2 Source", type=input.source, defval=close)
MA2Visible = input(title="MA2 Visible", type=input.bool, defval=true) 
MA3Period = input(200, title="MA3 Period")
MA3Type = input(title="MA3 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "HMA", "DEMA", "TEMA"])
MA3Source = input(title="MA3 Source", type=input.source, defval=close)
MA3Visible = input(title="MA3 Visible", type=input.bool, defval=true)
ShowCrosses = input(title="Show Crosses", type=input.bool, defval=true)

MA1 = if MA1Type == "SMA"
    sma(MA1Source, MA1Period)
else
    if MA1Type == "EMA"
        ema(MA1Source, MA1Period)
    else
        if MA1Type == "WMA"
            wma(MA1Source, MA1Period)
        else
            if MA1Type == "RMA"
                rma(MA1Source, MA1Period)
            else
                if MA1Type == "HMA"
                    wma(2*wma(MA1Source, MA1Period/2)-wma(MA1Source, MA1Period), round(sqrt(MA1Period)))
                else
                    if MA1Type == "DEMA"
                        e = ema(MA1Source, MA1Period)
                        2 * e - ema(e, MA1Period)
                    else
                        if MA1Type == "TEMA"
                            e = ema(MA1Source, MA1Period)
                            3 * (e - ema(e, MA1Period)) + ema(ema(e, MA1Period), MA1Period)

                    
MA2 = if MA2Type == "SMA"
    sma(MA2Source, MA2Period)
else
    if MA2Type == "EMA"
        ema(MA2Source, MA2Period)
    else
        if MA2Type == "WMA"
            wma(MA2Source, MA2Period)
        else
            if MA2Type == "RMA"
                rma(MA2Source, MA2Period)
            else
                if MA2Type == "HMA"
                    wma(2*wma(MA2Source, MA2Period/2)-wma(MA2Source, MA2Period), round(sqrt(MA2Period)))
                else
                    if MA2Type == "DEMA"
                        e = ema(MA2Source, MA2Period)
                        2 * e - ema(e, MA2Period)
                    else
                        if MA2Type == "TEMA"
                            e = ema(MA2Source, MA2Period)
                            3 * (e - ema(e, MA2Period)) + ema(ema(e, MA2Period), MA2Period)
                    
MA3 = if MA3Type == "SMA"
    sma(MA3Source, MA3Period)
else
    if MA3Type == "EMA"
        ema(MA3Source, MA3Period)
    else
        if MA3Type == "WMA"
            wma(MA3Source, MA3Period)
        else
            if MA3Type == "RMA"
                rma(MA3Source, MA3Period)
            else
                if MA3Type == "HMA"
                    wma(2*wma(MA3Source, MA3Period/2)-wma(MA3Source, MA3Period), round(sqrt(MA3Period)))
                else
                    if MA3Type == "DEMA"
                        e = ema(MA3Source, MA3Period)
                        2 * e - ema(e, MA3Period)
                    else
                        if MA3Type == "TEMA"
                            e = ema(MA3Source, MA3Period)
                            3 * (e - ema(e, MA3Period)) + ema(ema(e, MA3Period), MA3Period)
                    


p1 = plot(MA1Visible ? MA1 : na, color=color.green, linewidth=1)
p2 = plot(MA2Visible ? MA2 : na, color=color.yellow, linewidth=1)
p3 = plot(MA3Visible ? MA3 : na, color=color.red, linewidth=2)

fill(p1, p2, color.silver, transp=80, title="Fill")


start = timestamp(2019, 1, 1, 1, 0)
end = timestamp(2025, 1, 1, 1, 0)

if time >= start and time <= end
    longCondition = crossover(MA1, MA2) and close > MA3
    if (longCondition)
        strategy.entry("Long", strategy.long)
        
    shortCondition = crossunder(MA1, MA2) and close < MA3
    if (shortCondition)
        strategy.entry("Short", strategy.short)

더 많은