3가지 이동 평균 추세 추종 전략


생성 날짜: 2024-02-02 17:30:09 마지막으로 수정됨: 2024-02-02 17:30:09
복사: 1 클릭수: 567
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

3가지 이동 평균 추세 추종 전략

개요

이 전략은 3개의 이동 평균을 기반으로 한 트렌드 추적 전략이다. 그것은 빠른 라인, 중간 라인, 그리고 느린 라인의 교차를 계산하여 가격 추세를 판단하고 ATR 값으로 목표 가격과 중지 가격을 설정한다.

전략 원칙

이 전략은 다음의 세 가지 이동 평균을 사용합니다.

  1. 13일 중화 이동 평균, 단기 경향을 판단하기 위한
  2. 55일 지수 이동 평균, 중기 추세를 판단하기 위한
  3. 110일 간단한 이동 평균, 장기적인 추세를 판단하기 위한

빠른 선에서 중간 선, 중간 선에서 느린 선을 통과 할 때, 다중 추세로 판단; 빠른 선 아래에서 중간 선을 통과 할 때, 중간 선 아래에서 느린 선을 통과 할 때, 공허 추세로 판단.

이 전략은 일부 노이즈 트레이딩을 필터링하기 위해 여러 가지 보조 조건을 설정했습니다.

  1. K선 아래의 5개는 모두 중간선 위에 있습니다.
  2. K 선의 첫 두 선은 중간선 아래로 내려갑니다.
  3. 1 K 선의 마감값은 중간선 위에 있습니다.

이 조건이 충족되면, 더 많은 또는 더 적은 신호가 발송됩니다. 매번 한 가지 포지션만 가지고, 평형 포지션 또는 손실을 막은 후에 다시 포지션을 열 수 있습니다.

타겟 가격과 스톱 스로드는 ATR 값에 따라 일정 배수를 설정한다.

우위 분석

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 세 개의 이동 평균 조합을 사용하여 추세를 판단하여 단일 지표 판단 오류의 확률을 피합니다.
  2. 여러 보조 조건을 설정하여 노이즈 트레이드를 필터링하여 신호 품질을 향상시킬 수 있다.
  3. ATR 동적 상쇄는 단편 손실을 제어하는 데 도움이 됩니다.

위험 분석

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

  1. 이동 평균 조합은 잘못된 신호를 발산할 수 있으며, 충분히 회전할 필요가 있다.
  2. ATR 배수 설정을 잘못하면 너무 느슨하거나 엄격한 정지 손실이 발생할 수 있습니다.
  3. 이 사건은 스카이 (Zacco) 에 의해 발생한 것으로 추정된다.

위험을 제어하기 위해, 이동 평균 파라미터를 적절히 조정하고 ATR 배수를 최적화하고 단일 손실을 너무 많이 피하기 위해 최대 보유 시간을 설정하는 것이 좋습니다.

최적화 방향

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

  1. 다양한 길이 또는 유형의 이동 평균을 테스트하십시오.
  2. 보조 조건의 최적화 파라미터를
  3. MACD, DMI 등과 같은 다른 지표로 트렌드를 예측해보세요.
  4. 결합량은 거래량, 가격차 등과 같은 지표로 필터 신호를 다.

요약하다

이 전략은 전체적으로 안정적인 트렌드를 따르는 전략이다. 그것은 주로 이동 평균을 기반으로 트렌드 방향을 판단하며, 특정 기술 지표 그룹이 보조적으로 작용하여 일부 잡음을 필터링 할 수 있다. 추가적인 최적화 공간이 남아 있지만, 전체적인 위험은 통제 가능하며, 중장선 트렌드를 따르는 데 적합하다.

전략 소스 코드
/*backtest
start: 2024-01-02 00:00:00
end: 2024-02-01 00:00:00
period: 2h
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/
// © greenmask9

//@version=4
strategy("Dazzling Bolts", overlay=true)
//max_bars_back=3000

// 13 SMMA
len = input(10, minval=1, title="SMMA Period")
src = input(close, title="Source")
smma = 0.0
smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len

// 55 EMA
emalength = input(55, title="EMA Period")
ema = ema(close, emalength)

// 100 SMA
smalength = input(110, title="SMA Period")
sma = sma(close, smalength)

emaforce = input(title="Force trend with medium EMA", type=input.bool, defval=true)
offsetemavalue = input(defval = 6)

bullbounce = smma>ema and ema>sma and low[5]>ema and low[2]<ema and close[1]>ema and (ema[offsetemavalue]>sma or (not emaforce))
bearbounce = smma<ema and ema<sma and high[5]<ema and high[2]>ema and close[1]<ema and (ema[offsetemavalue]<sma or (not emaforce))
plotshape(bullbounce,  title= "Purple", location=location.belowbar, color=#ff33cc, transp=0, style=shape.triangleup, size=size.tiny, text="Bolts")
plotshape(bearbounce,  title= "Purple", location=location.abovebar, color=#ff33cc, transp=0, style=shape.triangledown, size=size.tiny, text="Bolts")
strategy.initial_capital = 50000
ordersize=floor(strategy.initial_capital/close)
longs = input(title="Test longs", type=input.bool, defval=true)
shorts = input(title="Test shorts", type=input.bool, defval=true)
atrlength = input(title="ATR length", defval=12)
atrm = input(title="ATR muliplier",type=input.float, defval=2)
atr = atr(atrlength)

target = close + atr*atrm
antitarget = close - (atr*atrm)

//limits and stop do not move, no need to count bars from since

bullbuy = bullbounce and longs and strategy.opentrades==0
bb = barssince(bullbuy)
bearsell = bearbounce and shorts and strategy.opentrades==0
bs = barssince(bearsell)

if (bullbuy)
    strategy.entry("Boltsup", strategy.long, ordersize)
    strategy.exit ("Bolts.close", from_entry="Boltsup", limit=target, stop=antitarget)
if (crossover(smma, sma))
    strategy.close("Boltsup", qty_percent = 100, comment = "Bolts.crossover")

if (bearsell)
    strategy.entry("Boltsdown", strategy.short, ordersize)
    strategy.exit("Bolts.close", from_entry="Boltsdown", limit=antitarget, stop=target)
if (crossunder(smma, sma))
    strategy.close("Boltsdown", qty_percent = 100, comment = "Bolts.crossover")

// if (bb<5)
//     bulltarget = line.new(bar_index[bb], target[bb], bar_index[0], target[bb], color=color.blue, width=2)
//     bullclose = line.new(bar_index[bb], close[bb], bar_index[0], close[bb], color=color.blue, width=2)
//     bullstop = line.new(bar_index[bb], antitarget[bb], bar_index[0], antitarget[bb], color=color.blue, width=2)
// if (bs<5)
//     bulltarget = line.new(bar_index[bs], antitarget[bs], bar_index[0], antitarget[bs], color=color.purple, width=2)
//     bullclose = line.new(bar_index[bs], close[bs], bar_index[0], close[bs], color=color.purple, width=2)
//     bullstop = line.new(bar_index[bs], target[bs], bar_index[0], target[bs], color=color.purple, width=2)