이동평균 교차 시스템


생성 날짜: 2024-01-03 16:22:18 마지막으로 수정됨: 2024-01-03 16:22:18
복사: 1 클릭수: 574
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

이동평균 교차 시스템

개요

이 전략은 다공간 상반기 거래 전략으로, 이동 평균에 기반한 황금 포크 사다리 거래 신호를 형성한다. 빠른 이동 평균이 아래에서 느린 이동 평균을 통과하면 구매 신호를 생성한다. 빠른 이동 평균이 위에서 아래에서 느린 이동 평균을 통과하면 판매 신호를 생성한다.

전략 원칙

이 전략은 20일 간단한 이동 평균과 30일 간단한 이동 평균의 두 가지 이동 평균을 사용합니다. 20일 이동 평균이 30일 이동 평균을 아래에서 통과하면 구매 신호가 발생하며, 20일 이동 평균이 30일 이동 평균을 위에서 아래로 통과하면 판매 신호가 발생합니다.

이동 평균은 트렌드 지표로서 시장의 방향을 효과적으로 나타냅니다. 교차 원칙은 트렌드 전환점을 적시에 포착하여 거래 신호를 형성 할 수있게합니다. 20일과 30일 두 개의 주기 길이를 적절하게 설정하면 시장의 흐름을 반영 할 수 있으며 너무 민감하지 않아 잘못된 신호를 생성 할 수 있습니다.

우위 분석

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

  1. 전략적 논리는 간단하고 명확하며, 이해하기 쉽고, 실행하기 쉽고, 초보자를 위한 학습입니다.
  2. 부진 거래는 역동적인 거래를 방지하고 불필요한 손실을 줄일 수 있습니다.
  3. 이동 평균 자체는 필터링 작용을 가지고 있으며, 이는 잘못된 신호를 방지하기 위해 동작 소음을 필터링합니다.
  4. 주기 변수 설정은 합리적이고, 너무 민감하지 않아 전략 안정성에 영향을 미치지 않는다.

위험 분석

이 전략에는 다음과 같은 위험들이 있습니다.

  1. 거래가 흔들릴 때, 이동 평균이 자주 교차하고, 더 많은 손실을 초래할 수 있습니다.
  2. 동향상태에서 이동 평균은 뒤쳐져 있고, 수익의 일부를 놓칠 수 있습니다.
  3. 매개 변수 설정이 잘못되면 정책 안정성에 영향을 미칠 수 있다.

대책:

  1. 이동 평균 주기 조정, 삼각형 이동 평균과 같은 기술을 적용하여 곡선을 평형화하고 교차 빈도를 줄이십시오.
  2. 다른 지표들이 동향을 판단할 수 있도록 도와주고, 불안정한 상황에서 거래하는 것을 피하도록 한다.
  3. 최적화 변수, 최적의 변수 조합을 찾는다.

최적화 방향

이 전략은 다음의 몇 가지 측면에서 최적화될 수 있습니다.

  1. 다른 종류의 이동 평균을 시도해 보세요. 가중 이동 평균, 삼각 이동 평균 등이죠.
  2. 다른 기술 지표 판단을 추가하여 불안정한 시장에서 거래 신호를 피하십시오.
  3. 파동 이론, 통로 이론과 같은 기술 분석 방법과 결합하여 시장 추세를 판단하는 것;
  4. 실시간 최적화 매개 변수, 예를 들어 기계 학습을 이용한 모델;
  5. 수량적 도구와 결합하여, 스톱 스톱 손실 전략을 채택하여 자금 관리를 최적화하십시오.

요약하다

이동 평균 교차 시스템은 간단하고 효과적인 트렌드 추적 전략으로, 원리는 명확하고 이해하기 쉽고, 초보자 학습에 매우 적합하다. 이 전략은 주로 이동 평균의 금叉死叉을 기반으로 거래 신호를 형성하고, 무진행 거래로 수익을 얻는다. 여러면에서 최적화하여 전략을 더 안정적이고 효율적으로 만들 수 있다.

전략 소스 코드
/*backtest
start: 2023-12-03 00:00:00
end: 2024-01-02 00:00:00
period: 1h
basePeriod: 15m
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)