빠른 이동평균선과 느린 이동평균선의 교차전략을 기반으로 함


생성 날짜: 2023-11-22 16:38:26 마지막으로 수정됨: 2023-11-22 16:38:26
복사: 0 클릭수: 622
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

빠른 이동평균선과 느린 이동평균선의 교차전략을 기반으로 함

개요

이동 평균 가로 전략은 이동 평균을 기반으로 한 간단하고 효과적인 양적 거래 전략이다. 이 전략은 빠른 이동 평균과 느린 이동 평균의 교차를 구매 및 판매 신호로 사용합니다. 빠른 선이 아래쪽에서 느린 선을 뚫을 때 구매 신호를 생성하고 빠른 선이 위쪽에서 아래쪽에서 느린 선을 뚫을 때 판매 신호를 생성합니다.

전략 원칙

이 전략의 핵심 논리는 이동 평균을 사용하여 시장의 추세를 판단하는 것이다. 이동 평균은 그 자체로 주파수 무작위 시장 소음의 기능을 가지고 있다. 빠른 이동 평균은 최신 추세를 반영하여 가격 변화에 더 빠르게 반응하며, 느린 이동 평균은 최신 가격 변화에 더 느리게 반응하여 중장기적 추세를 나타냅니다.

구체적으로, 이 전략은 먼저 빠른 이동 평균 sign1과 느린 이동 평균 sign2를 정의한다. 그리고는 sig1과 sig2의 교차 관계에 따라 매매점을 판단한다. sign1이 아래에서 sign2을 돌파할 때 구매 신호를 생성한다. longCondition; sign1이 위로부터 아래로 내려가 sign2을 돌파할 때 판매 신호를 생성한다.

우위 분석

이 전략의 장점은 분명합니다.

  1. 논리적으로 간단하고, 이해하기 쉽고, 구현하기 쉽습니다.
  2. 매개 변수 조정 유연성, 시장 조건에 따라 조정 가능
  3. 다른 지표의 필터 신호와 결합하여 안정성을 높일 수 있습니다.
  4. 좋은 성과, 예를 들어 EMA15-EMA30 조합은 EURCHF 일선 데이터에서 83%의 승률을 나타냅니다.

위험 분석

이 전략에는 위험도 있습니다.

  1. 위프사우 효과는 심각한데, 손해 방지 설정이 중요합니다.
  2. “대시장 흔들림은 효과가 없다”
  3. 다양한 품종과 주기에 적응하기 위해 반복적으로 조율 테스트가 필요합니다.

최적화 조치:

  1. 다른 지표들을 추가하고, whipsaw를 피하십시오.
  2. 이동 평균 유형과 변수를 다른 품종에 맞게 조정합니다.
  3. 제약금지 비율을 최적화하고 위험을 통제합니다.

요약하다

이동 평균 가로 전략은 전체적으로 논리적으로 간단하고 실용적인 양적 전략이다. 매개 변수 조정과 적절한 최적화를 통해 다양한 시장 환경에서 안정적인 수익을 낼 수 있다. 양적 거래자가 집중 연구하고 적용할 가치가 있다.

전략 소스 코드
/*backtest
start: 2023-11-14 00:00:00
end: 2023-11-16 04:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Simple yet effective MA cross strategy.
// You'll have to tune the parameters to get an optimal win ratio.
// If JPY or XAU or any other currency with pips defined as the 
// second decimal digit are involved, do not forget to set the respective flag on.
//
// Created by vitelot/yanez/Vts, who's the same fellow with different user names
// December 2018 -- Merry Xmas
//
strategy("MA cross strategy Vts", overlay=true, initial_capital=1000, currency="EUR", pyramiding=0)

yr  = input(2016, title="Starting year to analyse")
src = input(close, title="Source")
maType = input( defval="EMA", title="MA Type", options=["SMA","EMA","HMA","McG","WMA"])
//
isJPY = input(false, title="Is JPY or XAU involved?") // JPY and Gold have the pips defined as the 2 decimal digit

maPar1 = input(26, minval=1, title="MA fast period")
maPar2 = input(51, minval=2, title="MA slow period")

atrPar = input(14,minval=1, title="ATR period")
atrMulSL = input(1.5, title="SL ATR multiplicator")
atrMulTP = input(1.0, title="TP ATR multiplicator")

hma(sig, n) => // Hull moving average definition
    wma( 2*wma(sig,round(n/2))-wma(sig,n), round(sqrt(n)))

mcg(sig,length) => // Mc Ginley MA definition
    mg = 0.0
    mg := na(mg[1]) ? ema(sig, length) : mg[1] + (sig - mg[1]) / (length * pow(sig/mg[1], 4))

ma(t,sig,len) =>
    if t =="SMA"
        sma(sig,len)
    else
        if t == "EMA"
            ema(sig,len)
        else
            if t == "HMA"
                hma(sig,len)
            else
                if t == "McG" // Mc Ginley
                    mcg(sig,len)
                else
                    wma(sig,len)
                    
        
sig1 = ma(maType, src, maPar1)
sig2 = ma(maType, src, maPar2)

tickFactor = isJPY? 1e3: 1e5
sl = atrMulSL*atr(atrPar)*tickFactor
tp = atrMulTP*atr(atrPar)*tickFactor

plot(sig1, color=aqua, title="MA1", linewidth=2)
plot(sig2, color=orange, title="MA2", linewidth=2)

longCondition = crossunder(sig2, sig1) and year>=yr // change the >= to == if you like exact years not a range
if (longCondition)
    strategy.entry("Long", strategy.long, qty=1) // exit trade when SL and TP are hit
    strategy.exit("Exit Long", "Long", loss=sl, profit=tp)
if (crossunder(sig1, sig2)) // or when the short condition is met
    strategy.close("Long")

shortCondition = crossover(sig2,sig1) and year>=yr // change the >= to == if you like exact years not a range
if (shortCondition)
    strategy.entry("Short", strategy.short, qty=1)
    strategy.exit("Exit Short", "Short", loss=sl, profit=tp)
if (crossover(sig1,sig2))
    strategy.close("Short")