동적 이동 평균에 기초한 트렌드 거래 전략

저자:차오장, 날짜: 2023-12-21 11:33:50
태그:

img

전반적인 설명

이 전략은 동적 이동 평균에 기반한 거래 신호를 생성하여 주식 가격이 상승할 때 장기간 거래하고 가격이 하락할 때 포지션을 닫습니다. 모멘텀 지표와 이동 평균의 장점을 결합함으로써 안정적인 이익을 위해 중장기 가격 추세를 추적하는 것을 목표로합니다.

원칙

이 전략은 주로 Hull Moving Average (HMA) 의 세 가지 변종에 의존합니다. 규칙적인 HMA, 가중된 HMA (WHMA) 및 기하급수적 HMA (EHMA). 코드가 보여주는 바와 같이 사용자는 세 개의 Hull MA 사이에서 전환 할 수 있습니다.

HMA의 공식은 다음과 같습니다.

HMA = WMA ((2*WMA ((거기, n/2)-WMA ((거기, n), sqrt ((n))

여기서 WMA는 가중화 이동 평균이고 n는 기간 매개 변수입니다. SMA와 비교하면 HMA는 가격 변화에 더 빠르게 반응합니다.

WHMA와 EHMA의 공식은 비슷합니다. HMA는 기본 옵션으로 선택됩니다.

HMA를 계산한 후, 전략은 HMA의 중선 값을 거래 신호로 사용합니다. 가격이 HMA 중선을 넘어서면 긴 거리로 이동하고 가격이 수직선 아래로 떨어지면 포지션을 닫습니다. 따라서 이윤을 위해 HMA 중선을 사용하여 중장기 트렌드를 추적합니다.

장점

전통적인 MA 전략에 비해 이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 더 빠른 반응과 적절한 시간에 입력 및 중지에 대한 더 강한 트렌드 추적 능력
  2. 불필요한 거래 빈도를 줄이고, 급격한 상승과 정지 추격을 피합니다.
  3. 더 많은 시장 환경에 적응하기 위한 유연한 HMA 매개 변수
  4. 적용 가능성을 확장하기 위해 전환 가능한 HMA 변종

위험성

또한 몇 가지 위험이 있습니다.

  1. 범위를 제한하는 시장에서 여러 가지 잘못된 신호를 생성하고 거래 빈도와 미끄러짐 비용을 증가시킵니다.
  2. HMA 매개 변수가 제대로 설정되지 않으면 트렌드 반전 포인트가 없어지고 손실 위험이 커집니다.
  3. 유동성 낮은 주식을 거래할 때 유동성 위험과 큰 미끄러짐

해결책:

  1. 가장 좋은 값을 위해 HMA 매개 변수를 최적화
  2. 트렌드 반전 지점을 결정하기 위해 다른 지표를 추가합니다.
  3. 큰 평균 일일 양을 가진 유동 재고를 선택합니다.

개선

이 전략은 또한 다음과 같은 측면에서 향상 될 수 있습니다.

  1. 신호 신뢰성을 보장하기 위해 볼륨 또는 다른 필터를 추가
  2. MACD와 KDJ를 결합하여 더 나은 타이밍을 얻으며 승률을 향상시킵니다.
  3. 실제 무역 백테스트를 기반으로 HMA 기간을 조정합니다.
  4. WHMA 또는 EHMA로 전환합니다. 특정 조류에 가장 좋은 성과를 내는 조류입니다.
  5. 단일 거래 손실을 통제하기 위해 스톱 로스 메커니즘을 추가합니다.

요약

동적 MA 거래 전략은 HMA의 빠른 반응을 통합하여 중장기 가격 추세를 효과적으로 추적합니다. 적절한 타이밍과 폐쇄 중지에서 긴 포지션을 개설하여 좋은 백테스트 결과를 보여주었습니다. 매개 변수 조정 및 주식 필터링의 추가 개선은 더 안정적인 초과 수익을 초래할 것입니다. 구현이 쉽고 위험 제어 가능한 양적 전략입니다.


/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('Position Investing by SirSeff', overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0)
strat_dir_input = input.string(title='Strategy Direction', defval='long', options=['long', 'short', 'all'])
strat_dir_value = strat_dir_input == 'long' ? strategy.direction.long : strat_dir_input == 'short' ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)
//////////////////////////////////////////////////////////////////////
// Testing Start dates
testStartYear = input(2000, 'Backtest Start Year')
testStartMonth = input(1, 'Backtest Start Month')
testStartDay = input(1, 'Backtest Start Day')
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)
//Stop date if you want to use a specific range of dates
testStopYear = input(2030, 'Backtest Stop Year')
testStopMonth = input(12, 'Backtest Stop Month')
testStopDay = input(30, 'Backtest Stop Day')
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)


testPeriod() => true
// Component Code Stop
//////////////////////////////////////////////////////////////////////
//INPUT
src = input(close, title='Source')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])
length = input(55, title='Length(180-200 for floating S/R , 55 for swing entry)')
switchColor = input(true, 'Color Hull according to trend?')
candleCol = input(false, title='Color candles based on Hull\'s Trend?')
visualSwitch = input(true, title='Show as a Band?')
thicknesSwitch = input(1, title='Line Thickness')
transpSwitch = input.int(40, title='Band Transparency', step=5)

//FUNCTIONS
//HMA
HMA(_src, _length) =>
    ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
//EHMA    
EHMA(_src, _length) =>
    ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length)))
//THMA    
THMA(_src, _length) =>
    ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)

//SWITCH
Mode(modeSwitch, src, len) =>
    modeSwitch == 'Hma' ? HMA(src, len) : modeSwitch == 'Ehma' ? EHMA(src, len) : modeSwitch == 'Thma' ? THMA(src, len / 2) : na

//OUT
HULL = Mode(modeSwitch, src, length)
MHULL = HULL[0]
SHULL = HULL[2]

//COLOR
hullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800

//PLOT
///< Frame
Fi1 = plot(MHULL, title='MHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)
Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)
///< Ending Filler
fill(Fi1, Fi2, title='Band Filler', color=hullColor, transp=transpSwitch)
///BARCOLOR
barcolor(color=candleCol ? switchColor ? hullColor : na : na)


if HULL[0] > HULL[2] and testPeriod()
    strategy.entry('Invest', strategy.long)
if HULL[0] < HULL[2] and testPeriod()
    strategy.entry('Pause', strategy.short)



더 많은