오버레이 트렌드 신호 전략

저자:차오장, 날짜: 2024-02-18 10:00:22
태그:

img

전반적인 설명

이 전략은 방향 움직임 지표 (DMI) DI+와 DI-를 계산하여 평균 방향 지표 (ADX) 및 기하급수적인 이동 평균 (EMA) 와 함께 거래 신호를 생성합니다. DI+가 DI-와 ADX를 넘을 때 긴 신호를 트리거합니다. DI-가 DI+를 넘고 ADX가 30을 넘을 때 짧은 신호가 트리거됩니다.

전략 논리

  1. DI+, DI-, ADX를 계산합니다.

    • DI+, DI-, ADX를 계산하기 위해 ta.dmi() 를 사용
    • DI+/DI- 방향 가격 움직임을 측정합니다
    • ADX는 가격 움직임의 강도를 측정합니다.
  2. 기하급수적 이동평균을 계산합니다

    • EMA를 계산하기 위해 사용자 정의 my_ema() 함수를 사용하세요
    • EMA가 가격 데이터를 매끄럽게합니다.
  3. 거래 신호를 생성

    • 긴 신호: DI+가 DI-와 ADX > 20을 넘고 EMA > 근접합니다.
      • 상승 추세와 변동성이 증가하는 것을 나타냅니다
    • 짧은 신호: DI+와 ADX > 25 아래로 넘어가고 EMA < 근접
      • 하향 추세와 높은 변동성을 나타냅니다.
  4. 스톱 손실을 설정

    • 긴 스톱 손실: DI+와 ADX > 30 이상
      • 트렌드 전환을 나타냅니다.
    • 단기 스톱 손실: DI+가 DI-와 ADX > 30 이하로 넘는다
      • 트렌드 전환을 나타냅니다.

요약하자면 이 전략은 강력한 가격 추세가 나타나면 손실을 제한하기 위해 스톱 로스로 거래하기 위해 모멘텀 및 트렌드 분석 지표를 결합합니다.

이점 분석

  1. 듀얼 DI는 잘못된 신호를 피합니다.
    • 단일 DI는 잘못된 신호를 줄 수 있고, 이중 DI는 트렌드를 보장합니다.
  2. ADX 임계값은 변동성을 높여야 합니다.
    • 높은 변동성 움직임을 거래만, 범위에서 피합니다
  3. EMA는 DI를 보완합니다.
    • EMA는 중·장기 동향을 파악합니다.
  4. 엄격한 스톱 손실
    • 손실을 빠르게 줄여

위험 분석

  1. 빈번한 스톱 손실
    • 휘발성 변동은 빈번한 정지를 유발할 수 있습니다.
  2. 매개 변수 의존성
    • 최적의 DI 및 ADX 매개 변수를 찾아야 합니다.
  3. 낮은 거래 빈도
    • 엄격한 규칙은 무역을 감소시킵니다.

스톱 손실을 확장하고, 매개 변수를 조정하고, 주파수를 높이기 위해 필터를 추가함으로써 최적화 할 수 있습니다.

최적화 기회

  1. 매개 변수 최적화
    • DI 및 ADX 매개 변수를 최적화
  2. 필터를 추가합니다
    • 부피, 분차 등
  3. 스톱 로스를 넓혀
    • 주파수를 줄이기 위해 휴식 중지

결론

이 전략은 강력한 트렌드를 거래하기 위해 추진력과 트렌드 분석 지표를 결합하고 위험을 제어하기 위해 엄격한 정지점을 제공합니다. 매개 변수 최적화, 추가 필터 및 느린 정지점을 통해 성능을 더욱 향상시킬 수 있습니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tamil_FNO_Trader

//@version=5
strategy("Overlay Signals by TFOT", overlay=true)

// Calculate DMI
len = input.int(14, minval=1, title="DI Length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = ta.dmi(len, lensig)

// Get EMA
emalen = input.int(26, minval=1, title = "EMA Length")
emasrc = input.source(close, title = "EMA Source")

my_ema(src, length) =>
    alpha = 2 / (length + 1)
    sum = 0.0
    sum := na(sum[1]) ? src : alpha * src + (1 - alpha) * nz(sum[1])
EMA2 = my_ema(emasrc, emalen)

// Variables
var bool buycondition1 = false
var bool sellcondition1 = false

var int firstbuybar = na
var int firstsellbar = na

var int buyexitbar = na
var int sellexitbar = na

var bool buyexit1 = false
var bool sellexit1 = false

// Buy & Sell Conditions
buycondition1 := (ta.crossover(diplus, diminus)) and (adx > 20) and (close > EMA2) and na(firstbuybar)
sellcondition1 := (ta.crossover(diminus, diplus)) and (adx > 25) and (close < EMA2) and na(firstsellbar)

buyexit1 := ta.crossover(diminus, diplus) and (adx > 30) and na(buyexitbar)
sellexit1 := ta.crossover(diplus, diminus) and (adx > 30) and na(sellexitbar)

if buycondition1
    if(na(firstbuybar))
        firstbuybar := bar_index
        buyexitbar := na
        firstsellbar := na
        strategy.entry("Buy", strategy.long)

if sellcondition1
    if(na(firstsellbar))
        firstsellbar := bar_index
        sellexitbar := na
        firstbuybar := na
        strategy.entry("Sell", strategy.short)

if buyexit1 and not na(firstbuybar)
    if(na(buyexitbar))
        buyexitbar := bar_index
        firstbuybar := na
        firstsellbar := na
        strategy.close("Buy")

if sellexit1 and not na(firstsellbar)
    if(na(sellexitbar))
        sellexitbar := bar_index
        firstsellbar := na
        firstbuybar := na
        strategy.close("Sell")

// Plot signals on chart
hl = input.bool(defval = true, title = "Signal Labels")

plotshape(hl and buycondition1 and bar_index == firstbuybar ? true : na, "Buy", style = shape.labelup, location = location.belowbar, color = color.green, text = "Buy", textcolor = color.white, size = size.tiny)
plotshape(hl and sellcondition1 and bar_index == firstsellbar ? true : na, "Sell", style = shape.labeldown, location = location.abovebar, color = color.red, text = "Sell", textcolor = color.white, size = size.tiny)

plotshape(hl and buyexit1 and bar_index == buyexitbar ? true : na, "Buy Exit", style = shape.labelup, location = location.belowbar, color = color.red, text = "Buy X", textcolor = color.white, size = size.tiny)
plotshape(hl and sellexit1 and bar_index == sellexitbar ? true : na, "Sell Exit", style = shape.labeldown, location = location.abovebar, color = color.red, text = "Sell X", textcolor = color.white, size = size.tiny)



더 많은