
이동 평균 가로 전략은 이동 평균을 기반으로 한 간단하고 효과적인 양적 거래 전략이다. 이 전략은 빠른 이동 평균과 느린 이동 평균의 교차를 구매 및 판매 신호로 사용합니다. 빠른 선이 아래쪽에서 느린 선을 뚫을 때 구매 신호를 생성하고 빠른 선이 위쪽에서 아래쪽에서 느린 선을 뚫을 때 판매 신호를 생성합니다.
이 전략의 핵심 논리는 이동 평균을 사용하여 시장의 추세를 판단하는 것이다. 이동 평균은 그 자체로 주파수 무작위 시장 소음의 기능을 가지고 있다. 빠른 이동 평균은 최신 추세를 반영하여 가격 변화에 더 빠르게 반응하며, 느린 이동 평균은 최신 가격 변화에 더 느리게 반응하여 중장기적 추세를 나타냅니다.
구체적으로, 이 전략은 먼저 빠른 이동 평균 sign1과 느린 이동 평균 sign2를 정의한다. 그리고는 sig1과 sig2의 교차 관계에 따라 매매점을 판단한다. sign1이 아래에서 sign2을 돌파할 때 구매 신호를 생성한다. longCondition; sign1이 위로부터 아래로 내려가 sign2을 돌파할 때 판매 신호를 생성한다.
이 전략의 장점은 분명합니다.
이 전략에는 위험도 있습니다.
최적화 조치:
이동 평균 가로 전략은 전체적으로 논리적으로 간단하고 실용적인 양적 전략이다. 매개 변수 조정과 적절한 최적화를 통해 다양한 시장 환경에서 안정적인 수익을 낼 수 있다. 양적 거래자가 집중 연구하고 적용할 가치가 있다.
/*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")