MACD 이중 이동 평균 추적 전략

저자:차오장, 날짜: 2023-12-18 12:25:13
태그:

img

전반적인 설명

이 전략은MACD 이중 이동 평균 추적 전략MACD 지표의 황금 십자와 이중 이동 평균의 죽음의 십자 를 거래 신호로 사용하며, 단기 가격 움직임을 추적하기 위해 전날의 최저 가격과 함께 스톱 로스 포인트를 사용합니다.

전략 논리

  1. 빠른 EMA를 계산합니다. 가까운,5), 느린 EMA를 계산합니다. 가까운8 그리고 신호 SMA를 계산합니다. 가까운3
  2. 긴 신호 정의: 빠른 MA가 느린 MA를 넘을 때
  3. 짧은 신호를 정의합니다. 빠른 MA가 느린 MA보다 낮을 때 또는 종료 가격이 전날의 최저 가격보다 낮을 때
  4. 포지션 크기는 초기 자본 2천 달러 (USD) 를 종료 가격으로 나누는 것입니다.
  5. 짧은 신호를 사용하여 Stop Loss로 긴 포지션을 닫습니다.

이점 분석

  1. MACD 지표를 사용하여 과잉 구매 및 과잉 판매 구역을 결정하고, 가짜 브레이크오웃을 피하여 트레이딩 신호를 형성하기 위해 이중 MA를 사용합니다.
  2. 단기 트렌드를 추적하고 적시에 스톱 로스
  3. 포지션 크기의 동적 조정은 과도하게 큰 단일 손실을 피합니다.

위험 분석

  1. MACD 지표는 지연 효과, 단기 기회를 놓칠 수 있습니다.
  2. 이중 MA 거래 신호는 잘못된 신호를 생성할 수 있습니다.
  3. 스톱 손실 포인트는 너무 공격적이며, 높은 빈도로 중단됩니다

최적화 방향

  1. 지표 감수성을 향상시키기 위해 MACD 매개 변수 조합을 최적화하십시오.
  2. 시장 통합에서 잘못된 신호를 피하기 위해 트렌드 판단을 추가하십시오.
  3. 시장 변동성을 평가하기 위해 변동성 지수와 결합, 손실 중지 지점을 조정

요약

이 전략은 고전적인 MACD 이중 이동 평균 조합 지표를 사용하여 과잉 구매 및 과잉 판매 구역을 결정하고, 거래 신호를 생성하며, 동적 위치 사이징 및 전날의 최저 가격을 단기 가격 변동을 포착하기 위해 스톱 로스 포인트 디자인으로 도입합니다. 전반적인 전략 논리는 명확하고 이해하기 쉽습니다. 추가 테스트 및 최적화 가치가 있습니다.


/*backtest
start: 2023-12-10 00:00:00
end: 2023-12-13 02:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
// macd/cam v1 strategizing Chris Moody Macd indicator https://www.tradingview.com/script/OQx7vju0-MacD-Custom-Indicator-Multiple-Time-Frame-All-Available-Options/
// macd/cam v2 changing to macd 5,8,3
// macd/cam v2.1 
//      Sell when lower than previous day low. 
//      Initial capital of $2k. Buy/sell quantity of initial capital / close price
//      Quitar short action
//      Note: custom 1-week resolution seems to put AMD at 80% profitable

strategy(title="MACD/CAM 2.1", shorttitle="MACD/CAM 2.1") //
source = close
//get inputs from options
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", defval="60")
smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
sh = input(true, title="Show Histogram?")
macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
hist_colorChange = input(true,title="MacD Histogram 4 Colors?")
venderLowerPrev = input(true,title="Vender cuando closing price < previous day low?")

res = useCurrentRes ? timeframe.period : resCustom

fastLength = input(5, minval=1), slowLength=input(8,minval=1)
signalLength=input(3,minval=1)

// find exponential moving average of price as x and fastLength var as y
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)

macd = fastMA - slowMA
// simple moving average
signal = sma(macd, signalLength)
hist = macd - signal

outMacD = request.security(syminfo.tickerid, res, macd)
outSignal = request.security(syminfo.tickerid, res, signal)
outHist = request.security(syminfo.tickerid, res, hist)

histA_IsUp = outHist > outHist[1] and outHist > 0
histA_IsDown = outHist < outHist[1] and outHist > 0
histB_IsDown = outHist < outHist[1] and outHist <= 0
histB_IsUp = outHist > outHist[1] and outHist <= 0

//MacD Color Definitions
macd_IsAbove = outMacD >= outSignal
macd_IsBelow = outMacD < outSignal

plot_color = hist_colorChange ? histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon :yellow :gray
macd_color = macd_colorChange ? macd_IsAbove ? lime : red : red
signal_color = macd_colorChange ? macd_IsAbove ? yellow : yellow : lime

circleYPosition = outSignal
 
plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=line ,linewidth=2)
plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=histogram, linewidth=4)

circleCondition = sd and cross(outMacD, outSignal)

// Determine long and short conditions
longCondition  = circleCondition and macd_color == lime

redCircle = circleCondition and macd_color == red
redCirclePrevLow = redCircle or low<low[1]
shortCondition = redCircle
if (venderLowerPrev)
    shortCondition = redCirclePrevLow

strategy.initial_capital = 20000
// Set quantity to initial capital / closing price
cantidad = strategy.initial_capital/close

// Submit orders
strategy.entry(id="long", long=true, qty=cantidad, when=longCondition)
strategy.close(id="long", when=shortCondition)
plot(circleCondition ? circleYPosition : na, title="Cross", style=cross, linewidth=10, color=macd_color)
// hline(0, '0 Line', linestyle=solid, linewidth=2, color=white)

더 많은