이동평균 교차 전략


생성 날짜: 2023-09-18 17:35:37 마지막으로 수정됨: 2023-09-18 17:35:37
복사: 0 클릭수: 688
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이동평균선 교차는 이동평균선 교차를 거래 신호로 사용하는 트렌드 추적 전략이다. 이 전략은 가격과 이동평균선 교차 및 두 개의 이동평균선이 교차하는 것을 구매 및 판매 신호로 사용하여 수익을 추구한다.

전략 원칙

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

  1. 두 개의 이동 평균을 계산하고, SMA 또는 EMA를 선택합니다.

  2. 빠른 선에서 느린 선을 통과할 때, 더 많은 일을하십시오. 빠른 선 아래의 느린 선을 통과할 때, 평지하십시오.

  3. 거래 신호로 평균선을 뚫거나 평균선 간 교차를 선택할 수 있다.

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

  5. 다단시장에선 더만 할 수 있고, 빈시장에선 빈만 할 수 있다.

  6. 이동 평균선 변수를 최적화하여 다른 주기들에 적응한다.

이 전략은 이동평균선의 트렌드 추적 기능을 활용하여, 단기평균선 상에서 장기평균선을 통과하면, 현재 상승 추세에 있다는 것을 나타내며, 더 많이 해야 한다. 반대로, 단기평균선 아래에서 장기평균선을 통과하면, 현재 하향 추세에 있다는 것을 나타내며, 지위를 줄여야 한다.

우위 분석

이 전략의 주요 장점은 다음과 같습니다.

  1. 이 원칙은 간단하고, 실행하기 쉽습니다. 거래 신호는 명확합니다.

  2. 트렌드를 효과적으로 추적하여 구매 및 판매 기회를 잡을 수 있습니다.

  3. 다양한 평균선 변수를 결합하여 다양한 시장 환경에 적용할 수 있다.

  4. 선택적으로 더 많은 일을 하거나 공백을 하는 것, 불확실한 역작업을 피하는 것.

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

  6. 매개 변수를 최적화하여 전략의 성능을 지속적으로 개선할 수 있다.

위험 분석

이 전략의 주요 위험은 다음과 같습니다.

  1. 가짜 신호가 발생하기 쉽기 때문에 너무 자주 거래하는 것은 피해야 합니다.

  2. 표시는 평균선 변수 선택에 의존하며, 잘못 선택하면 손실이 발생할 수 있다.

  3. 어느 정도의 지연이 있을 때, 너무 이른 입국과 너무 늦은 퇴출을 막아야 한다.

  4. 은 시장 환경에서는 적용되지 않습니다.

  5. 평균선 교차는 약간의 무작위성을 가지고 있으며, 손실을 완전히 피할 수 없습니다.

거래량 확인, 최적화 매개 변수 또는 다른 지표 조합과 함께 사용함으로써 위험을 줄일 수 있다.

최적화 방향

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

  1. /%(Line - ShortMa) /ShortMa) /(Line - LongMa) /LongMa) /를 평균선 기울기 필터 조건으로 추가한다.

  2. 이동 평균주기 파라미터를 최적화하여 다양한 조합을 테스트한다.

  3. MACD 또는 RSI와 같은 지표에 추가하여 여러 번 확인하십시오.

  4. 단편적 손실을 제한하기 위한 스톱 로즈 조건을 설정합니다.

  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)