다기간에 기반한 SMA에 기반한 전략을 따르는 경향

저자:차오장, 날짜: 2024-02-04 14:50:24
태그:

img

전반적인 설명

이 전략은 트렌드를 식별하고 따라가기 위해 다른 기간과 여러 SMA 라인을 결합합니다. 핵심 아이디어는: 트렌드를 결정하기 위해 다른 기간과 SMA의 상승/하락 방향을 비교하십시오. 단기 SMA가 장기 기간 SMA를 넘을 때 길게 이동하고 짧은 SMA가 긴 SMA를 넘을 때 짧게 이동합니다. ZeroLagEMA는 입출을 확인하는 데도 사용됩니다.

전략 논리

  1. 각각 10, 20, 50, 100 및 200의 기간을 가진 5개의 SMA 라인을 사용합니다.
  2. 트렌드를 결정하기 위해 이 5개의 SMA의 방향을 비교하십시오. 예를 들어, 10~20~100~200주기 SMA가 함께 상승할 때 상승 추세를 나타냅니다. 모두 하락할 때 하락 추세를 나타냅니다.
  3. 트레이딩 신호를 생성하기 위해 SMA의 값을 다른 기간과 비교합니다. 예를 들어, 10 기간 SMA가 20 기간 SMA를 넘을 때, 길게 가십시오. 10 기간 SMA가 20 기간 SMA를 넘을 때 짧게 가십시오.
  4. 진입 확인 및 출구 신호를 위해 ZeroLagEMA를 사용하십시오. 빠른 ZeroLagEMA가 느린 ZeroLagEMA를 넘을 때 길게 이동하고, 아래에 넘을 때 길게 종료하십시오. 쇼트에 대한 판단 논리는 반대입니다.

장점

  1. 여러 개의 SMA를 서로 다른 기간으로 결합하면 시장 트렌드를 효과적으로 결정할 수 있습니다.
  2. SMA 값을 비교하면 입출입 규칙이 생성됩니다.
  3. ZeroLagEMA 필터는 불필요한 트레이드를 피하고 안정성을 향상시킵니다.
  4. 트렌드 판단과 트레이딩 신호를 결합하면 트렌드를 따라 트레이딩이 이루어집니다.

위험 과 해결책

  1. 시장이 고집합될 때, 빈번한 SMA 크로스오버는 불필요한 손실을 초래할 수 있습니다.
    • 솔루션: 유효하지 않은 신호 입력을 피하기 위해 ZeroLagEMA 필터를 높입니다.
  2. 여러 기간 SMA를 판단하면 급격한 단기 가격 변동에 신속하게 대응하지 못하는 다소 후진이 있습니다.
    • 해결책: 판단을 돕기 위해 MACD와 같은 더 빠른 지표를 추가하십시오.

최적화 방향

  1. 가장 좋은 조합을 찾기 위해 SMA 기간 매개 변수를 최적화합니다.
  2. 손실을 더 제한하기 위해 트레일링 스톱과 같은 스톱 손실 전략을 추가하십시오.
  3. 포지션 사이즈 메커니즘을 추가하여 강력한 트렌드에 대한 베팅을 증가시키고 통합에 대한 베팅을 감소시킵니다.
  4. MACD와 KDJ와 같은 더 많은 보조 지표를 통합하여 전반적인 안정성을 향상시킵니다.

결론

이 전략은 여러 기간 SMA를 결합하여 시장 트렌드를 효과적으로 결정하고 정량화 된 거래 신호를 생성합니다. ZeroLagEMA는 승률을 향상시킵니다. 요약하자면, 전략은 주목할만한 결과로 거래 후 정량 트렌드를 달성했습니다. 추가 최적화 기간, 스톱 로스, 포지션 사이징 등을 통해 라이브 거래에 대한 전략을 강화 할 수 있습니다.


/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy("Forex MA Racer - SMA Performance /w ZeroLag EMA Trigger", shorttitle = "FX MA Racer (5x SMA, 2x zlEMA)", overlay=false )

// === INPUTS ===
hr0             = input(defval = true, title = "=== SERIES INPUTS ===")
smaSource       = input(defval = close, title = "SMA Source")
sma1Length      = input(defval = 10, title = "SMA 1 Length")
sma2Length      = input(defval = 20, title = "SMA 2 Length")
sma3Length      = input(defval = 50, title = "SMA 3 Length")
sma4Length      = input(defval = 100, title = "SMA 4 Length")
sma5Length      = input(defval = 200, title = "SMA 5 Length")
smaDirSpan      = input(defval = 4, title = "SMA Direction Span")
zlmaSource      = input(defval = close, title = "ZeroLag EMA Source")
zlmaFastLength  = input(defval = 9, title = "ZeroLag EMA Fast Length")
zlmaSlowLength  = input(defval = 21, title = "ZeroLag EMA Slow Length")
hr1             = input(defval = true, title = "=== PLOT TIME LIMITER ===")
useTimeLimit    = input(defval = true, title = "Use Start Time Limiter?")
// set up where we want to run from
startYear       = input(defval = 2018, title = "Start From Year", minval = 0, step = 1)
startMonth      = input(defval = 02, title = "Start From Month", minval = 0,step = 1)
startDay        = input(defval = 01, title = "Start From Day", minval = 0,step = 1)
startHour       = input(defval = 00, title = "Start From Hour", minval = 0,step = 1)
startMinute     = input(defval = 00, title = "Start From Minute", minval = 0,step = 1)
hr2             = input(defval = true, title = "=== TRAILING STOP ===")
useStop     = input(defval = false, title = "Use Trailing Stop?")
slPoints    = input(defval = 200, title = "Stop Loss Trail Points", minval = 1)
slOffset    = input(defval = 400, title = "Stop Loss Trail Offset", minval = 1)
// === /INPUTS ===

// === SERIES SETUP ===
// Fast ZeroLag EMA
zema1=ema(zlmaSource, zlmaFastLength)
zema2=ema(zema1, zlmaFastLength)
d1=zema1-zema2
zlemaFast=zema1+d1

// Slow ZeroLag EMA
zema3=ema(zlmaSource, zlmaSlowLength)
zema4=ema(zema3, zlmaSlowLength)
d2=zema3-zema4
zlemaSlow=zema3+d2

// Simple Moving Averages
period10 = sma(close, sma1Length)
period20 = sma(close, sma2Length)
period50 = sma(close, sma3Length)
period100 = sma(close, sma4Length)
period200 = sma(close, sma5Length)
// === /SERIES SETUP ===

// === PLOT ===
// colors of plotted MAs
p1 = (close < period10) ? #FF0000 : #00FF00
p2 = (close < period20) ? #FF0000 : #00FF00
p3 = (close < period50) ? #FF0000 : #00FF00
p4 = (close < period100) ? #FF0000 : #00FF00
p5 = (close < period200) ? #FF0000 : #00FF00

plot(period10, title='10 Period', color = p1, linewidth=1)
plot(period20, title='20 Period', color = p2, linewidth=2)
plot(period50, title='50 Period', color = p3, linewidth=4)
plot(period100, title='100 Period', color = p4, linewidth=6)
plot(period200, title='200 Period', color = p5, linewidth=10)
// === /PLOT ===

//BFR = BRFIB ? (maFast+maSlow)/2 : abs(maFast - maSlow)

// === STRATEGY ===
// calculate SMA directions
direction10 = rising(period10, smaDirSpan) ? +1 : falling(period10, smaDirSpan) ? -1 : 0
direction20 = rising(period20, smaDirSpan) ? +1 : falling(period20, smaDirSpan) ? -1 : 0
direction50 = rising(period50, smaDirSpan) ? +1 : falling(period50, smaDirSpan) ? -1 : 0
direction100 = rising(period100, smaDirSpan) ? +1 : falling(period100, smaDirSpan) ? -1 : 0
direction200 = rising(period200, smaDirSpan) ? +1 : falling(period200, smaDirSpan) ? -1 : 0

// conditions
// SMA Direction Trigger
dirUp = direction10 > 0 and direction20 > 0 and direction100 > 0 and direction200 > 0
dirDn = direction10 < 0 and direction20 < 0 and direction100 < 0 and direction200 < 0

longCond = (period10>period20) and (period20>period50) and (period50>period100) and  dirUp//and (close > period10) and (period50>period100) //and (period100>period200)
shortCond = (period10<period20) and (period20<period50) and dirDn//and (period50<period100) and (period100>period200)

longExit = crossunder(zlemaFast, zlemaSlow) or crossunder(period10, period20)
shortExit = crossover(zlemaFast, zlemaSlow) or crossover(period10, period20)


// entries and exits
startTimeOk() =>
    // get our input time together
    inputTime   = timestamp(syminfo.timezone, startYear, startMonth, startDay, startHour, startMinute)
    // check the current time is greater than the input time and assign true or false
    timeOk      = time > inputTime ? true : false
    // last line is the return value, we want the strategy to execute if..
    // ..we are using the limiter, and the time is ok -OR- we are not using the limiter
    r = (useTimeLimit and timeOk) or not useTimeLimit


if( true )
    // entries
    strategy.entry("long", strategy.long, when = longCond)
    strategy.entry("short", strategy.short, when = shortCond)

        
    // trailing stop
    if (useStop)
        strategy.exit("XL", from_entry = "long", trail_points = slPoints, trail_offset = slOffset)
        strategy.exit("XS", from_entry = "short", trail_points = slPoints, trail_offset = slOffset)

    // exits
    strategy.close("long", when = longExit)
    strategy.close("short", when = shortExit)
// === /STRATEGY ===

더 많은