DMI와 HMA 결합 전략

저자:차오장, 날짜: 2024-01-04 17:23:06
태그:

img

전반적인 설명

이 전략은 방향 이동 지수 (Directional Movement Index, DMI) 와 헬 이동 평균 (Hull Moving Average, HMA) 를 결합하여 DMI로 시장 방향을 파악하고 위험 관리 없이 HMA로 트렌드 강도를 확인합니다.

전략 논리

  1. 실제 범위, DIPlus, DIMinus 및 ADX를 계산합니다.

  2. 속도가 빨라지고 느린 Hull Moving Average (HMA) 를 계산합니다.

  3. DIPlus가 DIMinus를 통과하고 빠른 HMA가 느린 HMA를 통과할 때 긴 입력을 트리거합니다.

  4. DIMinus가 DIPlus 아래로 넘어가고 빠른 HMA가 느린 HMA 아래로 넘어가면 짧은 입력을 유발합니다.

  5. 엔트리 신호에 긴 / 짧은 명령을 배치.

이점 분석

트렌드 지표 DMI와 Hull MA의 이중 확인은 시장 트렌드를 정확하게 파악하는 것을 보장하고 위프사를 피합니다. 위험 관리의 부재는 거래 빈도를 줄이고 장기적으로 전반적인 수익성을 가져옵니다.

위험 분석

주요 위험은 스톱 로즈가 없다는 것, 엄청난 시장 변동이 발생했을 때 손실을 통제하지 못하는 것. 또한 제한된 조정 공간과 약한 적응력이 결함입니다.

가능한 해결책은 이동 스톱 손실을 추가하고 매개 변수 혼합을 최적화하는 등입니다.

최적화 방향

  1. True Range를 기준으로 ATR 후속 스톱 손실을 추가합니다.

  2. 가장 좋은 혼합을 찾기 위해 허크 기간을 최적화하십시오.

  3. 길고 짧은 신호의 동적 문턱

  4. 트렌드 연속성을 보장하기 위해 모멘텀 필터를 추가합니다.

요약

DMI와 HMA 조합은 단순성과 효율성을 가진 트렌드를 식별하는 데 탁월한 성능을 발휘합니다. 적절한 스톱 손실과 매개 변수 조정으로 훌륭한 트렌드 다음 시스템이 될 수 있습니다.


/*backtest
start: 2022-12-28 00:00:00
end: 2024-01-03 00:00:00
period: 1d
basePeriod: 1h
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/
// © Tuned_Official
//@version=4
strategy(title="DMI + HMA - No Risk Management", overlay = false, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.025)

//Inputs
hullLen1 = input(title="Hull 1 length", type=input.integer, defval=29)
hullLen2 = input(title="Hull 2 length", type=input.integer, defval=2)
len = input(title="Length for DI", type=input.integer, defval=76)

//Calculations
TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0

SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

//Indicators
fasthull = hma(close, hullLen1)
slowhull = hma(close, hullLen2)
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)

//Plots
plot(DIPlus, color=color.green, title="DI+")
plot(DIMinus, color=color.red, title="DI-")
plot(ADX, color=color.black, title="ADX")

//conditions
go_long = crossover(DIPlus, DIMinus) and fasthull > slowhull //crossover(fasthull, slowhull) and DIPlus > DIMinus
go_short = crossover(DIMinus, DIPlus) and fasthull < slowhull //crossunder(fasthull, slowhull) and DIMinus > DIPlus

//Entry
if strategy.position_size < 0 or strategy.position_size == 0
    strategy.order("long", strategy.long, when=go_long)

if strategy.position_size > 0 or strategy.position_size == 0
    strategy.order("Short", strategy.short, when=go_short)

더 많은