트렌드 이동 평균 거래 전략

저자:차오장, 날짜: 2023-09-21 20:34:43
태그:

전반적인 설명

이 전략은 트렌드 트레이딩을 위해 트렌드 방향을 결정하고 중장기 트렌드를 파악하기 위해 빠르고 느린 이동 평균의 조합을 사용합니다. 빠른 MA가 느린 MA보다 크면 길게, 빠른 MA가 느린 MA보다 크면 짧게됩니다. 이것은 전형적인 트렌드 다음 전략입니다.

전략 논리

이 전략은 주로 이동 평균의 황금 십자 및 죽음의 십자 를 기반으로 시장 추세를 결정합니다. 구체적으로 5 기간 빠른 MA와 21 기간 느린 MA를 사용합니다.

빠른 MA가 느린 MA를 넘을 때 시장의 상승 추세를 알리고 전략은 다음 바의 오픈에서 길게 갈 것입니다. 빠른 MA가 느린 MA를 넘을 때 하락 추세를 알리고 전략은 다음 바의 오픈에서 짧게 갈 것입니다.

또한, bars 매개 변수는 거짓 브레이크아웃을 필터링하도록 설정되어 있습니다. 기본 값은 2입니다. 즉, 빠른 MA는 긴 신호를 유발하기 전에 2 개의 연속적인 바에 걸쳐 느린 MA보다 높게 닫아야합니다. 이것은 거짓 브레이크아웃을 효과적으로 피합니다.

암호화 거래의 경우 전략은 또한 극단적 가치 논리를 포함합니다. 빠르고 느린 MA가 극단적 영역에 도달 할 때만 거래 신호가 활성화됩니다. 이것은 잘못된 신호를 더욱 피합니다.

출구 규칙은 간단하고 직접적입니다.

장점

  • 이중 MA 시스템은 동향을 효과적으로 추적 할 수 있습니다.
  • 빠른 MA는 트렌드 변화에 빠르게 반응합니다.
  • 느린 MA는 전체 방향을 결정합니다.
  • bars 매개 변수는 일부 잘못된 브레이크아웃을 필터링합니다.
  • 극단적 가치 보호자는 중요한 지점 주위에 산발적인 잘못된 신호를 피합니다.
  • 스톱 로스를 옮기는 것은 위험을 관리합니다.

위험성

  • 듀얼 MA 시스템은 트렌드 반전 시 손실을 줄일 경향이 있습니다.
  • 이동 스톱 손실은 조기 중단 될 수 있습니다.
  • 바스 필터는 유효한 신호를 놓칠 수 있습니다.
  • 극단적인 가치 보호자는 때때로 좋은 항목을 놓칩니다.
  • 이 전략은 강한 트렌드 시장에서 더 잘 작동합니다.

위험은 다음과 같이 감소 할 수 있습니다.

  • bars 매개 변수를 최적화
  • MACD와 같은 다른 필터를 추가합니다.
  • 조기 중단을 피하기 위해 스톱 로스 수준을 조정합니다.
  • 재입국을 고려합니다.

최적화 방향

이 전략은 다음과 같은 측면에서 개선될 수 있습니다.

  1. MA 매개 변수 조정

현재 시장에 최적의 매개 변수를 찾기 위해 더 많은 MA 조합을 테스트합니다. 예를 들어 10주기 빠른 MA와 50주기 느린 MA.

  1. 다른 지표를 추가합니다.

MACD, KDJ 및 다른 지표를 추가하여 테스트하여 보다 엄격한 입시 규칙을 설정하고 잘못된 신호를 피합니다.

  1. 항목 최적화

현재 간단한 이중 MA 항목을 향상시킬 수 있습니다:

  • 빠른 MA가 느린 MA를 넘을 때 MACDDIFF가 0을 넘을 때만 길이를 입력합니다.
  • KDJ가 빠른 MA가 느린 MA를 넘을 때 황금 십자 표시만 하면 긴 값을 입력합니다.
  1. 정지 최적화

조기 정지를 피하기 위해 후속 정지 같은 다른 정지 메커니즘을 테스트하십시오.

  1. 재입구를 추가합니다

트렌드를 놓치지 않기 위해 정지된 후에 재입입구를 허용합니다.

요약

요약하자면, 이 기본 트렌드 추적 전략은 단순하고 직설적인 논리를 가지고 있습니다. 트렌드 방향에 대해 듀얼 MAs를 사용하고 위험 관리에 대해 이동 스톱을 사용합니다. 장점은 이해하기 쉽고 트렌드로부터 이익을 얻을 수 있으며 위험을 관리합니다. 그러나 통합 중에 나쁜 신호, 조기 스톱 아웃 등과 같은 한계도 있습니다. 라이브 튜닝과 최적화가 필요합니다. 예를 들어 필터 추가, 스톱 조정, 다른 시장 환경에 적응 할 수 있도록합니다. 입문 트렌드 거래 전략으로, 그것은 초보자가 배우고 적용하기에 적합합니다. 그러나 그 한계를 주목해야하며 더 고급 전략이 탐구되어야합니다. 지속적인 개선으로만 끊임없이 변화하는 시장에서 지속 가능한 이익을 얻을 수 있습니다.


/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title = "Noro's Trend MAs Strategy v2.3", shorttitle = "Trend MAs str 2.3", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)

//Settings
needlong = input(true, "long")
needshort = input(true, "short")
needstops = input(false, "stops")
stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")
usefastsma = input(true, "Use fast MA Filter")
fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")
slowlen = input(21, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")
bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")
needbg = input(false, defval = false, title = "Need trend Background?")
needex = input(true, defval = true, title = "Need extreme? (crypto/fiat only!!!)")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

src = close

//PriceChannel 1
lasthigh = highest(src, slowlen)
lastlow = lowest(src, slowlen)
center = (lasthigh + lastlow) / 2

//PriceChannel 2
lasthigh2 = highest(src, fastlen)
lastlow2 = lowest(src, fastlen)
center2 = (lasthigh2 + lastlow2) / 2

//Trend
trend = low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend[1]

//Bars
bar = close > open ? 1 : close < open ? -1 : 0
redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0
greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Fast RSI
fastup = rma(max(change(close), 0), 2)
fastdown = rma(-min(change(close), 0), 2)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//CryptoBottom
mac = sma(close, 10)
len = abs(close - mac)
sma = sma(len, 100)
max = max(open, close)
min = min(open, close)

//Signals
up1 = trend == 1 and (low < center2 or usefastsma == false) and redbars == 1
dn1 = trend == -1 and (high > center2 or usefastsma == false) and greenbars == 1
up2 = high < center and high < center2 and bar == -1 and needex
dn2 = low > center and low > center2 and bar == 1 and needex
up3 = close < open and len > sma * 3 and min < min[1] and fastrsi < 10 ? 1 : 0

//Lines
plot(center2, color = red, linewidth = 3, transp = 0, title = "Fast MA")
plot(center, color = blue, linewidth = 3, transp = 0, title = "Slow MA")

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 80)

//Trading
stoplong = up1 == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]
stopshort = dn1 == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

if up1 or up2 or up3
    strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    strategy.exit("Stop Long", "Long", stop = stoplong)

if dn1
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    strategy.exit("Stop Short", "Short", stop = stopshort)
    
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
    

더 많은