이동 평균 후속 정지 전략

저자:차오장, 날짜: 2023-09-19 21:33:48
태그:

전반적인 설명

이 전략은 빠른 EMA 구매 라인이 느린 SMA 구매 라인을 넘을 때 구매 신호를 생성하고 위험 통제를 위해 ATR 동적 트레일링 스톱을 사용합니다. 제한된 거래로 구매 및 보유 전략을 능가하는 것을 목표로합니다.

전략 논리

  1. 빠른 EMA와 느린 SMA 구매 라인을 계산합니다. 빠른 라인이 특정 구매 힘으로 느린 라인을 넘을 때 구매 신호를 생성합니다.

  2. 빠른 EMA와 느린 SMA 판매 라인을 계산합니다. 빠른 라인이 느린 라인을 넘을 때 판매 신호를 생성합니다.

  3. N 일 ATR 평균을 동수로 곱하여 위험 통제를 위해 동적 후속 정지로 사용하십시오.

  4. 구매 및 판매 실행을 위해 백테스트 기간에 전략을 시작.

  5. 각 주식에 대한 매개 변수를 최적화하여 최적의 값을 찾습니다.

이 전략은 신호에 대한 MA 교차와 위험 통제에 대한 ATR 후속 정지 등의 장점을 결합합니다. 매개 변수 최적화는 각 제품의 특성에 적응하여 정확한 거래로 구매 및 보유보다 과도한 수익을 목표로합니다.

이점 분석

  1. 빠른 EMA와 느린 SMA 크로스오버는 트렌드를 식별하고 신호를 생성합니다.

  2. ATR 정지 조정은 시장 변동성에 따라 효과적으로 위험을 제어합니다.

  3. 각 주식에 대한 최적화는 수익성을 향상시킵니다.

  4. 간단한 논리와 규칙, 구현하고 확인하기 쉬운

  5. 전략 검증을 위한 백테스트 기능을 완료합니다.

  6. 매입과 보유보다 안정적인 실적을 추구합니다.

위험 분석

  1. 최적화된 매개 변수는 미래에 작동하지 않을 수 있습니다. 주기적인 재 최적화가 필요할 수 있습니다.

  2. EMA와 SMA의 교차는 잘못된 신호 또는 지연 신호를 생성할 수 있습니다.

  3. ATR 스톱은 너무 공격적이어서 스톱 손실 범위를 느슨하게 할 수 있습니다.

  4. 낮은 거래 빈도는 좋은 기회를 놓칠 수 있습니다.

  5. 거래 비용의 영향을 고려해야 합니다.

최적화 방향

  1. 다양한 매개 변수 조합을 테스트하여 최적의 값을 얻습니다.

  2. 신호 필터링을 위해 다른 표시기를 도입해보세요.

  3. ATR 기간을 최적화하여 스톱 손실 감수성을 균형 잡습니다.

  4. 스톱 로스 범위의 완화의 효과를 평가합니다.

  5. 자동화된 매개 변수 최적화를 위해 기계 학습을 고려해 보세요.

  6. 무역 빈도의 증가에 대한 연구 효과

요약

이 이동 평균 트레일링 스톱 전략은 신호에 대한 MA 크로스오버와 위험 통제에 대한 ATR 스톱의 장점을 결합합니다. 매개 변수 최적화는 각 주식의 특성에 맞게 조정됩니다. 최적화된 매개 변수에는 보장이 없지만 전체 논리는 구매 및 보유를 능가하는 간단하고 실용적입니다. 전략이 좋은 영감을 주는 가치를 가지고 있기 때문에 추가 개선 및 검증이 가치가 있습니다.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
//created by XPloRR 04-03-2018

strategy("XPloRR 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)

ema1Period = input(12, "Fast EMA Buy")
sma1Period = input(54, "Slow SMA Buy")
strength1 = input(52, "Minimum Buy Strength")

ema2Period = input(18, "Fast EMA Sell")
sma2Period = input(55, "Slow SMA Sell")
strength2 = input(100, "Minimum Sell Strength")

delta = input(8, "Trailing Stop (#ATR)")

testPeriod() => true

ema1val=ema(close,ema1Period)
sma1val=sma(close,sma1Period)
ema1strength=10000*(ema1val-ema1val[1])/ema1val[1]

ema2val=ema(close,ema2Period)
sma2val=sma(close,sma2Period)
ema2strength=10000*(ema2val-ema2val[1])/ema2val[1]

plot(ema1val,color=blue,linewidth=1)
plot(sma1val,color=orange,linewidth=1)
plot(ema2val,color=navy,linewidth=1)
plot(sma2val,color=red,linewidth=1)

long=crossover(ema1val,sma1val) and (ema1strength > strength1) 
short=crossunder(ema2val,sma2val) and (ema2strength < -strength2)

stopval=ema(close,6)
atr=sma((high-low),15)

inlong=0
buy=0
stop=0
if testPeriod()
    if (inlong[1])
        inlong:=inlong[1]
        buy:=close
        stop:=iff((stopval>(stop[1]+delta*atr)),stopval-delta*atr,stop[1])
    if (long) and (not inlong[1])
        strategy.entry("buy",strategy.long)
        inlong:=close
        buy:=close
        stop:=stopval-delta*atr
plot(buy,color=iff(close<inlong,red,lime),style=columns,transp=90,linewidth=1)
plot(stop,color=iff((short or (stopval<stop)) and (close<inlong),red,lime),style=columns,transp=60,linewidth=1)
if testPeriod()
    if (short or (stopval<stop)) and (inlong[1])
        strategy.close("buy")
        inlong:=0
        stop:=0
        buy:=0



더 많은