이중 이동 평균 추적 스톱 손실 전략

저자:차오장, 날짜: 2024-02-05 13:45:51
태그:

img

전반적인 설명

이 전략은 빠른 이동 평균이 느린 이동 평균을 넘을 때 구매 신호를 생성합니다. 동시에 매출 신호를 설정하기 위해 평균 진정한 범위를 기반으로 마감 스톱 손실 가격을 계산합니다. 이 전략은 시장 추세를 효과적으로 추적하고 수익을 취할 때 적시에 손실을 줄일 수 있습니다.

원칙

  1. 빠른 이동 평균 (Fast Moving Average, EMA): 가격 변화에 빠르게 반응하는 12일 지수 이동 평균.
  2. 느린 이동 평균 (SMA): 중장기 추세를 나타내는 45일 간편 이동 평균.
  3. 빠른 MA가 느린 MA를 넘어서면 구매 신호가 생성됩니다.
  4. 15일 평균 진 범위 (ATR) 는 스톱 로스의 기준으로 계산됩니다.
  5. ATR (예를 들어, 6 x ATR) 에 기반한 후속 스톱 손실 진폭을 설정하고 실시간으로 스톱 가격을 업데이트합니다.
  6. 판매 신호는 가격이 스톱 로스 가격 이하로 떨어지면 생성됩니다.

이점 분석

  1. MA 콤보는 트렌드를 효과적으로 식별하고 신호 신뢰성을 높입니다.
  2. 동적인 후속 스톱 손실은 적시에 손실을 멈추고 기금 손해를 피합니다.
  3. ATR 기반의 스톱 로스는 스톱 가격을 합리적으로 만들고 과민성을 방지합니다.
  4. 전략 논리는 간단하고 매개 변수는 유연합니다.

위험 분석

  1. MAs는 단기 기회를 놓칠 수 있는 지연을 가지고 있습니다.
  2. 과도한 느슨한 스톱 손실은 수익성을 약화시킵니다.
  3. 과도한 트 스톱 로즈는 거래 빈도와 수수료를 증가시킵니다.
  4. 변동성은 ATR 매개 변수 안정성에 영향을 줄 수 있습니다.

최적화 방향

  1. 최적의 MAs를 찾기 위해 더 많은 매개 변수 조합을 테스트합니다.
  2. ATR 곱셈을 특정 주식 특성에 따라 조정합니다.
  3. 불필요한 거래를 피하기 위해 볼륨 지표와 같은 필터링 조건을 추가합니다.
  4. 매개 변수 안정성을 테스트하기 위해 더 많은 역사 데이터를 수집합니다.

결론


/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
//created by XPloRR 24-02-2018

strategy("XPloRR MA-Buy ATR-MA-Trailing-Stop Strategy",overlay=true, initial_capital=1000,default_qty_type=strategy.percent_of_equity,default_qty_value=100)

testStartYear = input(2005, "Start Year")
testStartMonth = input(1, "Start Month")
testStartDay = input(1, "Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2050, "Stop Year")
testStopMonth = input(12, "Stop Month")
testStopDay = input(31, "Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriodBackground = input(title="Background", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

emaPeriod = input(12, "Exponential MA")
smaPeriod = input(45, "Simple MA")
stopPeriod = input(12, "Stop EMA")
delta = input(6, "Trailing Stop #ATR")

testPeriod() => true

emaval=ema(close,emaPeriod)
smaval=sma(close,smaPeriod)
stopval=ema(close,stopPeriod)
atr=sma((high-low),15)

plot(emaval, color=blue,linewidth=1)
plot(smaval, color=orange,linewidth=1)
plot(stopval, color=lime,linewidth=1)

long=crossover(emaval,smaval) 
short=crossunder(emaval,smaval)

//buy-sell signal
stop=0
inlong=0
if testPeriod()
    if (long and (not inlong[1]))
        strategy.entry("buy",strategy.long)
        inlong:=1
        stop:=emaval-delta*atr
    else
        stop:=iff((nz(emaval)>(nz(stop[1])+delta*atr))and(inlong[1]),emaval-delta*atr,nz(stop[1]))
        inlong:=nz(inlong[1])
        if ((stopval<stop) and (inlong[1]))
            strategy.close("buy")
            inlong:=0
            stop:=0
else
    inlong:=0
    stop:=0
plot(stop,color=green,linewidth=1)


더 많은