이동 평균 크로스오버 전략

저자:차오장, 날짜: 2023-09-18 17:35:37
태그:

전반적인 설명

이동평균 크로스오버 전략은 이동평균 크로스오버를 거래 신호로 기반으로 하는 트렌드 다음 전략이다. 이 전략은 수익을 추구하기 위해 이동평균과 두 이동평균 사이의 가격 크로스오버와 구매 및 판매 신호로 크로스오버를 사용합니다.

전략 원칙

이 전략의 주요 원칙은 다음과 같습니다.

  1. 두 개의 이동 평균을 계산하면, 하나는 빨라지고 하나는 느립니다. SMA나 EMA를 선택할 수 있습니다.

  2. 빠른 선이 느린 선 위에 넘어가면 길게, 빠른 선이 느린 선 아래에 넘어가면 근접하게

  3. 거래 신호로 가격 브레이크오버 또는 이동 평균 크로스오버를 선택할 수 있습니다.

  4. 전략 실행 기간을 설정할 수 있습니다.

  5. 황소 시장에서만 장가가 되고, 곰 시장에서만 단가가 될 수 있습니다.

  6. 다른 기간에 대한 역 테스트를 통해 이동 평균 매개 변수를 최적화합니다.

이 전략은 이동 평균의 트렌드를 따르는 능력을 활용합니다. 단기 MA가 장기 MA를 넘으면 상승 추세를 나타냅니다. 반대로 하락 추세는 위치를 줄여야합니다.

이점 분석

이 전략의 주요 장점:

  1. 간단한 원칙, 실행하기 쉬운, 명확한 거래 신호.

  2. 트렌드를 효과적으로 추적하고 적시에 거래 기회를 잡을 수 있습니다.

  3. 다양한 시장 환경에 대한 다른 MA 매개 변수를 결합 할 수 있습니다.

  4. 불확실한 역작업을 피하기 위해 길거나 짧게 선택할 수 있습니다.

  5. 특정 기간을 피하기 위해 전략 실행 시간을 설정할 수 있습니다.

  6. 매개 변수 최적화를 통해 전략을 지속적으로 개선할 수 있습니다.

위험 분석

이 전략의 주요 위험은:

  1. 잘못된 신호에 취약해서 너무 자주 거래하는 것을 피하세요.

  2. 성능은 MA 매개 변수에 의존하고, 잘못된 선택은 손실로 이어질 수 있습니다.

  3. 약간의 지연이 있습니다. 조기 출입과 지연 출입을 피하세요.

  4. 범위에 한정된 시장 환경에 적합하지 않습니다.

  5. MA 크로스에는 약간의 무작위성이 있습니다. 손실을 완전히 피할 수 없습니다.

위험은 부피 확인, 매개 변수 최적화 또는 다른 지표와 함께 사용함으로써 줄일 수 있습니다.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 기울기 필터를 추가 % ((Line - ShortMa) /ShortMa) / ((Line - LongMa) /LongMa).

  2. 이동평균 기간을 최적화하고 다양한 조합을 테스트합니다.

  3. MACD나 RSI와 같은 지표를 추가하면 여러 번 확인됩니다.

  4. 단일 거래 손실을 제한하기 위해 Stop Loss를 설정합니다.

  5. 조건부 사용에 대한 트렌딩 시장과 범위 시장을 구별하십시오.

  6. 최적의 패턴을 찾기 위해 다른 유지 기간을 테스트합니다.

요약

이동 평균 크로스오버 전략은 추세를 따르는 전략으로 간단하고 실용적입니다. 이점으로는 구현이 쉽고 효과적인 추세 추적입니다. 단점은 뒤쳐지고 잘못된 신호에 취약합니다. 강력한 트렌딩 시장에서 더 나은 성능을 달성하기 위해 매개 변수 최적화 및 지표 필터링을 통해 전략을 향상시킬 수 있습니다.


/*backtest
start: 2023-09-10 00:00:00
end: 2023-09-17 00:00:00
period: 10m
basePeriod: 1m
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/
// © gliese581d

//@version=4
strategy(title="Moving Averages Testing", overlay=true, precision=2, calc_on_every_tick=false, max_bars_back=5000, pyramiding=2,  
 default_qty_type=strategy.percent_of_equity, default_qty_value=50, commission_type=strategy.commission.percent, initial_capital=10000)


//SETTINGS

longs_on = input(title="Long Trades enabled", defval=true)
shorts_on = input(title="Short Trades enabled", defval=true)

long_cond = input(title="Buy/Long Crossover Condition", defval="price x MA1", options=["price x MA1", "price x MA2", "MA1 x MA2"])
short_cond = input(title="Sell/Short Crossunder Condition", defval="price x MA2", options=["price x MA1", "price x MA2", "MA1 x MA2"])

ma1_type = input(title="Moving Average 1 Type", defval="SMA", options=["SMA", "EMA"])
ma1_len = input(defval=20, title="Moving Average 1 Len", type=input.integer, minval=1, maxval=1000, step=1)
ma2_type = input(title="Moving Average 2 Type", defval="SMA", options=["SMA", "EMA"])
ma2_len = input(defval=30, title="Moving Average 2 Len", type=input.integer, minval=1, maxval=1000, step=1)


//MOVING AVERAGES

ma_1 = ma1_type == "EMA" ? ema(close, ma1_len) : sma(close, ma1_len)
ma_2 = ma2_type == "EMA" ? ema(close, ma2_len) : sma(close, ma2_len)


//STRATEGY

//trade entries
long_entry = long_cond == "price x MA1" ? crossover(close, ma_1) : long_cond == "price x MA2" ? crossover(close, ma_2) : long_cond == "MA1 x MA2" ? crossover(ma_1, ma_2) : false
short_entry = short_cond == "price x MA1" ? crossunder(close, ma_1) : short_cond == "price x MA2" ? crossunder(close, ma_2) : short_cond == "MA1 x MA2" ? crossunder(ma_1, ma_2) : false

start_month = input(defval=4, title="Strategy Start Month", type=input.integer, minval=1, maxval=12, step=1)
start_year = input(defval=2018, title="Strategy Start Year", type=input.integer, minval=2000, maxval=2025, step=1)
end_month = input(defval=12, title="Strategy End Month", type=input.integer, minval=1, maxval=12, step=1)
end_year = input(defval=2020, title="Strategy End Year", type=input.integer, minval=2000, maxval=2025, step=1)

in_time = true

strategy.entry("Long", strategy.long, when=longs_on and in_time and long_entry)
strategy.close("Long", when=longs_on and not shorts_on and short_entry)

strategy.entry("Short", strategy.short, when=shorts_on and in_time and short_entry)
strategy.close("Short", when=shorts_on and not longs_on and long_entry)


//PLOTTING

//color background
last_entry_was_long = nz(barssince(long_entry)[1], 5000) < nz(barssince(short_entry)[1], 5000)
bgcol = (longs_on and last_entry_was_long) ? color.green : (shorts_on and not last_entry_was_long) ? color.red : na
bgcolor(color=bgcol, transp=90)

plot((long_cond == "price x MA1" or long_cond == "MA1 x MA2") or (short_cond == "price x MA1" or short_cond == "MA1 x MA2") ? ma_1 : na, color=color.blue)
plot((long_cond == "price x MA2" or long_cond == "MA1 x MA2") or (short_cond == "price x MA2" or short_cond == "MA1 x MA2") ? ma_2 : na, color=color.black)
plotshape(long_entry, style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(short_entry, style=shape.triangledown, location=location.abovebar, color=color.red)

더 많은