EMA 및 SMA 기반 다중 지표 동적 추세 추적 전략

EMA SMA ATR PP supertrend
생성 날짜: 2024-12-27 14:12:50 마지막으로 수정됨: 2024-12-27 14:12:50
복사: 0 클릭수: 426
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

EMA 및 SMA 기반 다중 지표 동적 추세 추적 전략

전략 개요

이 전략은 다중 기술 지표가 결합된 동적 트렌드 추적 시스템이다. 이 전략의 핵심 특징은 고정 시간 주기 분석 방법을 사용하여 신호의 일관성을 보장하고 동시에 지점의 검증을 통해 거래 신호의 신뢰성을 향상시키는 것이다.

전략 원칙

이 전략은 다음과 같은 핵심 메커니즘을 기반으로 운영됩니다.

  1. 고정된 시간 주기의 가격 데이터를 사용하여 분석하여 다른 시간 주기의 간섭을 피합니다.
  2. 8주기 및 21주기 EMA를 통해 SMA를 계산하여 트렌드 추적 기반을 형성합니다.
  3. 트렌드 방향을 확인하기 위해 ATR과 지점 계산 SuperTrend 지표
  4. 지점점 3주기에 걸쳐 나타나는 SMA 교차 신호만이 유효한 신호로 간주된다
  5. 동적으로 계산하고 거래 결정에 대한 지지를 / 저항을 추적

전략적 이점

  1. 다중 지표 크로스 검증, 신호 신뢰성 향상
  2. 고정 시간 주기 분석, 가짜 신호 간섭을 감소
  3. 거래가 중요한 가격 수준에서 이루어지는 것을 보장하는 점수 확인 메커니즘
  4. 동적 추적 지원 저항 지점, 스톱 스톱 위치를 확인하는 데 도움이
  5. 슈퍼 트렌드 지표의 사용은 트렌드 방향에 대한 추가적인 확인을 제공합니다.
  6. 다양한 시장 상황에 따라 조정할 수 있는 유연한 파라미터 설정

전략적 위험

  1. 여러 지표로 인해 신호 지연이 발생할 수 있습니다.
  2. 위축 시장에서 너무 많은 가짜 신호가 발생할 수 있습니다.
  3. 고정 시간 주기의 분석은 다른 주기의 중요한 신호를 놓칠 수 있습니다.
  4. 지점 인증 메커니즘은 중요한 거래 기회를 놓칠 수 있습니다.
  5. 매개 변수를 지나치게 최적화하면 과도한 적합성이 발생할 수 있습니다.

전략 최적화 방향

  1. 변동성 필터링 메커니즘을 도입하여 낮은 변동성 기간 동안 거래 빈도를 줄이십시오.
  2. ADX 또는 MACD와 같은 증가 추세 강도 확인 지표
  3. 시장 상황에 따라 동적으로 조정되는 변수 시스템을 개발
  4. 신호 신뢰성을 향상시키기 위해 거래량 분석을 추가하세요
  5. 동적 중지 메커니즘을 구현하여 시장의 변동에 따라 중지 위치를 조정합니다.

요약하다

이 전략은 여러 기술 지표를 결합하여 비교적 완전한 트렌드 추적 거래 시스템을 구축한다. 그것의 핵심 장점은 고정 시간 주기 분석과 지점 비트 검증을 통해 신호 신뢰성을 향상시키는 것이다. 약간의 지연 위험은 존재하지만, 매개 변수 최적화 및 위험 관리 조치를 통해 효과적으로 제어 할 수 있다.

전략 소스 코드
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy("Buy Sell Pivot Point", overlay=true)

// Input Parameters
prd = input.int(defval=2, title="Periodo Pivot Point", minval=1, maxval=50)
Factor = input.float(defval=3, title="Fator ATR", minval=1, step=0.1)
Pd = input.int(defval=10, title="Periodo ATR", minval=1)
showpivot = input.bool(defval=false, title="Mostrar Pivot Points")
showlabel = input.bool(defval=true, title="Mostrar Buy/Sell Labels")
showcl = input.bool(defval=false, title="Mostrar PP Center Line")
showsr = input.bool(defval=false, title="Mostrar Support/Resistance")
sma1_length = input.int(defval=8, title="SMA 1")
sma2_length = input.int(defval=21, title="SMA 2")
timeframe_fix = input.timeframe("D", title="Timeframe Fixo")

// Request data from the fixed timeframe
fix_close = request.security(syminfo.tickerid, timeframe_fix, close)
fix_high = request.security(syminfo.tickerid, timeframe_fix, high)
fix_low = request.security(syminfo.tickerid, timeframe_fix, low)
fix_ph = request.security(syminfo.tickerid, timeframe_fix, ta.pivothigh(prd, prd))
fix_pl = request.security(syminfo.tickerid, timeframe_fix, ta.pivotlow(prd, prd))
fix_atr = request.security(syminfo.tickerid, timeframe_fix, ta.atr(Pd))

// Convert Pivot High/Low to valid boolean for conditions
ph_cond = not na(fix_ph)
pl_cond = not na(fix_pl)

// Draw Pivot Points
plotshape(ph_cond and showpivot, title="Pivot High", text="H", style=shape.labeldown, color=color.red, textcolor=color.red, location=location.abovebar, offset=-prd)
plotshape(pl_cond and showpivot, title="Pivot Low", text="L", style=shape.labelup, color=color.lime, textcolor=color.lime, location=location.belowbar, offset=-prd)

// Calculate the Center line using pivot points
var float center = na
lastpp = ph_cond ? fix_ph : pl_cond ? fix_pl : na
if not na(lastpp)
    center := na(center) ? lastpp : (center * 2 + lastpp) / 3

// Upper/Lower bands calculation
Up = center - (Factor * fix_atr)
Dn = center + (Factor * fix_atr)

// Get the trend
var float TUp = na
var float TDown = na
var int Trend = 0
TUp := na(TUp[1]) ? Up : fix_close[1] > TUp[1] ? math.max(Up, TUp[1]) : Up
TDown := na(TDown[1]) ? Dn : fix_close[1] < TDown[1] ? math.min(Dn, TDown[1]) : Dn
Trend := fix_close > TDown[1] ? 1 : fix_close < TUp[1] ? -1 : nz(Trend[1], 1)
Trailingsl = Trend == 1 ? TUp : TDown

// Plot the trend
linecolor = Trend == 1 ? color.lime : Trend == -1 ? color.red : na
plot(Trailingsl, color=linecolor, linewidth=2, title="PP SuperTrend")

// Plot Center Line
plot(showcl ? center : na, color=showcl ? (center < fix_close ? color.blue : color.red) : na, title="Center Line")

// Calculate Base EMAs
ema_8 = ta.ema(fix_close, 8)
ema_21 = ta.ema(fix_close, 21)

// Calculate SMAs based on EMAs
sma1 = ta.sma(ema_8, sma1_length)
sma2 = ta.sma(ema_21, sma2_length)

// Plot SMAs
plot(sma1, color=#ffff00, linewidth=2, title="SMA 1 (based on EMA 8)")
plot(sma2, color=#aa00ff, linewidth=2, title="SMA 2 (based on EMA 21)")

// Initialize variables to track pivot points
var float last_pivot_time = na

// Update the pivot time when a new pivot is detected
if (ph_cond)
    last_pivot_time := bar_index
if (pl_cond)
    last_pivot_time := bar_index

// Calculate the crossover/crossunder signals
buy_signal = ta.crossover(sma1, sma2)  // SMA 8 crossing SMA 21 upwards
sell_signal = ta.crossunder(sma1, sma2)  // SMA 8 crossing SMA 21 downwards

// Ensure signal is only valid if it happens within 3 candles of a pivot point
valid_buy_signal = buy_signal and (bar_index - last_pivot_time <= 3)
valid_sell_signal = sell_signal and (bar_index - last_pivot_time <= 3)

// Plot Buy/Sell Signals
plotshape(valid_buy_signal and showlabel, title="Buy Signal", text="BUY", style=shape.labelup, color=color.lime, textcolor=color.black, location=location.belowbar)
plotshape(valid_sell_signal and showlabel, title="Sell Signal", text="SELL", style=shape.labeldown, color=color.red, textcolor=color.white, location=location.abovebar)

// Get S/R levels using Pivot Points
var float resistance = na
var float support = na
support := pl_cond ? fix_pl : support[1]
resistance := ph_cond ? fix_ph : resistance[1]

// Plot S/R levels
plot(showsr and not na(support) ? support : na, color=showsr ? color.lime : na, style=plot.style_circles, offset=-prd)
plot(showsr and not na(resistance) ? resistance : na, color=showsr ? color.red : na, style=plot.style_circles, offset=-prd)

// Execute trades based on valid signals
if valid_buy_signal
    strategy.entry("Buy", strategy.long)
if valid_sell_signal
    strategy.entry("Sell", strategy.short)

// Alerts
alertcondition(valid_buy_signal, title="Buy Signal", message="Buy Signal Detected")
alertcondition(valid_sell_signal, title="Sell Signal", message="Sell Signal Detected")
alertcondition(Trend != Trend[1], title="Trend Changed", message="Trend Changed")