이동평균 및 MACD에 기초한 전략을 따르는 경향

저자:차오장, 날짜: 2023년 11월 15일 15:58:19
태그:

img

전반적인 설명

이 전략은 트렌드를 결정하고 거래 신호를 생성하기 위해 이동 평균과 MACD 지표를 결합합니다. 그것은 전형적인 트렌드 다음 전략에 속합니다. 트렌드 방향을 결정하기 위해 다른 시간 프레임의 두 개의 ZLSMA 이동 평균과 특정 구매 및 판매 신호를 생성하기 위해 MACD 크로스오버를 사용합니다. 이것은 중장기 트렌드를 효과적으로 파악하고 단기 시장 소음으로 오해되는 것을 피할 수 있습니다.

전략 논리

이 전략은 다음과 같은 주요 구성 요소로 구성됩니다.

  1. 빠른 ZLSMA와 느린 ZLSMA: 다른 시간 프레임의 ZLSMA 이동 평균을 비교하면 전체 트렌드 방향이 결정됩니다. 빠른 라인은 32 기간 ZLSMA로 구성되며 느린 라인은 400 기간 ZLSMA로 구성됩니다. 빠른 라인이 느린 라인의 위를 넘을 때 상승 신호이며 그 반대의 경우입니다.

  2. MACD 지표: MACD는 느린 라인 (26주기 EMA) 을 빠른 라인 (12주기 EMA) 에서 빼어 계산된다. 신호 라인은 MACD의 9주기 EMA이다. MACD가 신호 라인의 위를 넘으면 구매 신호이며, MACD가 신호 라인의 아래를 넘으면 판매 신호이다.

  3. 거래 신호: ZLSMA 트렌드 방향이 MACD 크로스오버 신호와 일치 할 때만 구매 및 판매 신호가 생성됩니다. 구체적으로, MACD 황금 십자와 일치 할 때 올 트렌드가 길고, MACD 죽음의 십자와 일치 할 때 하얀 트렌드가 짧습니다.

  4. 스톱 로스 및 수익을 취하십시오: 전략은 현재 추가 최적화가 필요한 스톱 로스 및 수익을 취하는 논리를 포함하지 않습니다.

주요 트렌드를 결정하기 위해 이동 평균을 사용하는 조합과 진입 시기를 측정하는 MACD는 잘못된 브레이크오웃을 효과적으로 필터링하고 단기 시장 소음으로 오해되는 것을 피할 수 있습니다.

이점 분석

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

  1. 트렌드 포착: 트렌드 방향을 결정하기 위해 다른 시간 프레임의 이동 평균을 사용하면 트렌드에 따라 거래하고 중장기 트렌드를 효과적으로 포착 할 수 있습니다.

  2. 소음 필터링: MACD 지표를 적용하면 단기 시장 소음을 필터링하고 소규모 시장에 의해 오해되는 것을 피합니다.

  3. 사용자 정의 가능한 매개 변수: 이동 평균 기간 및 MACD 매개 변수는 사용자 정의 가능하며 다른 시장에 최적화 될 수 있습니다.

  4. 구현하기 쉽다: 사용 된 모든 지표는 일반적인 기술 지표입니다. 전략 논리는 간단하고 명확하며 이해하기 쉽고 구현 할 수 있습니다.

  5. 통제 가능한 위험: 명확한 스톱 로스와 수익을 취하면 각 거래의 위험과 수익을 제어 할 수 있습니다.

위험 분석

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

  1. 잘못된 트렌드 결정: 주요 트렌드가 잘못 결정되면 모든 거래가 손실로 이어질 수 있습니다.

  2. 부적절한 매개 변수 최적화: 이동 평균 및 MACD 매개 변수는 철저하게 테스트 및 최적화되어야합니다. 그렇지 않으면 결과는 만족스럽지 않을 수 있습니다.

  3. 스톱 로즈가 없는 상태: 현재 스톱 로즈가 없는 상태인데, 너무 큰 손실의 위험이 있습니다.

  4. 제한된 수익 잠재력: 트렌드를 따르는 전략으로서 각 거래의 수익 잠재력은 제한되어 있으며 수익성을 높이기 위해 높은 볼륨이 필요합니다.

  5. 높은 거래 빈도: 부적절한 매개 변수 조정으로 인해 과도한 거래 빈도가 증가하고 거래 비용이 증가하고 미끄러질 수 있습니다.

최적화 방향

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

  1. 스톱 로스 메커니즘을 추가합니다. 거래당 최대 손실을 엄격히 제어하기 위해 적절한 스톱 로스 포인트를 설정합니다.

  2. 매개 변수 최적화: 최적의 이동 평균과 MACD 매개 변수 조합을 찾기 위해 백테스트 및 최적화.

  3. 거래 빈도가 낮습니다. 트렌드가 뚜렷할 때만 거래 신호가 생성되도록 매개 변수를 조정합니다.

  4. 다른 요인을 포함합니다. 트렌드와 신호를 확인하기 위해 볼륨 변화와 같은 요인이 추가 될 수 있습니다.

  5. 입시 시기를 개선: 입시 정확도를 높이기 위해 MACD 사용을 더욱 향상시킵니다.

  6. 보편적으로 적용 가능: 다양한 제품에서 전략을 광범위하게 적용할 수 있도록 매개 변수를 최적화하여 적용 가능성을 확장합니다.

결론

결론적으로, 이 전략은 이동 평균과 MACD의 간단하면서도 효과적인 조합을 통해 중장기 트렌드를 효과적으로 포착하여 탄탄한 양적 거래 전략 기반이 된다. 그러나 매개 변수는 추가 최적화가 필요하고, 위험은 더 나은 통제가 필요하며, 더 일관된 결과를 달성하기 위해 다른 요인이 포함되어야 한다. 실용적인 가치가 있고 개선할 여지가 많다.


/*backtest
start: 2023-11-07 00:00:00
end: 2023-11-10 05:00:00
period: 1m
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/
// © veryfid

//@version=5
strategy("Stratégie ZLSMA Bruno", shorttitle="Stratégie ZLSMA Bruno", overlay=false)

source = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
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?")

//res = useCurrentRes ? period : resCustom

fastLength = input(12), 
slowLength=input(26)
signalLength=input(9)

fastMA = ta.ema(source, fastLength)
slowMA = ta.ema(source, slowLength)

macd = fastMA - slowMA
signal = ta.sma(macd, signalLength)
hist = macd - signal

outMacD =  macd
outSignal = signal
outHist =  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 ? color.lime : color.red : color.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)
plot(sd and ta.cross(outMacD, outSignal) ? circleYPosition : na, title="Cross", style=plot.style_circles, linewidth=4, color=macd_color)
hline(0, '0 Line', linestyle=hline.style_solid, linewidth=2, color=color.white)

// Paramètres de la ZLSMA
length = input(32, title="Longueur")
offset = input(0, title="Décalage")
src = input(close, title="Source")
lsma = ta.linreg(src, length, offset)
lsma2 = ta.linreg(lsma, length, offset)
eq = lsma - lsma2
zlsma = lsma + eq

length_slow = input(400, title="Longueur")
offset_slow = input(0, title="Décalage")
lsma_slow = ta.linreg(src, length_slow, offset_slow)
lsma2_slow = ta.linreg(lsma_slow, length_slow, offset_slow)
eq_slow = lsma_slow - lsma2_slow
zlsma_slow = lsma_slow + eq_slow

// Paramètres de la sensibilité
sensitivity = input(0.5, title="Sensibilité")

// Règles de trading
longCondition = zlsma < zlsma_slow and  zlsma_slow < zlsma_slow[1] and zlsma > zlsma[1] and ta.cross(outMacD, outSignal) and  macd_color == color.lime//ta.crossover(zlsma, close) and ta.crossover(zlsma, zlsma[1]) // Croisement vers le haut
shortCondition = zlsma > zlsma_slow and  zlsma_slow > zlsma_slow[1] and zlsma < zlsma[1] and ta.cross(outMacD, outSignal) and  macd_color == color.lime   //ta.crossunder(zlsma, close) and ta.crossunder(zlsma, zlsma[1]) // Croisement vers le bas

// Entrée en position
strategy.entry("Achat", strategy.long, when=longCondition)
strategy.entry("Vente", strategy.short, when=shortCondition)
botifySignalZLSMA = longCondition ? 1 : shortCondition ? -1 : 0
plot(botifySignalZLSMA, title='Botify_signal', display=display.none)
// Sortie de position
strategy.close("Achat", when=ta.crossunder(zlsma, close)) // Close the "Achat" position
strategy.close("Vente", when=ta.crossover(zlsma, close)) // Close the "Vente" position


// Tracé de la courbe ZLSMA
plot(zlsma, color=color.yellow, linewidth=3)
plot(zlsma_slow, color=color.red, linewidth=3)



더 많은