
이 전략은 동적 이동 평균을 계산하여 거래 신호로 삼아 주가가 상승할 때 더 많은 위치를 열고 주가가 떨어질 때 더 적은 위치를 차지합니다. 이 전략은 동적 지표와 이동 평균의 장점을 결합하여 주가 가격의 중기 경향을 추적하여 안정적인 수익을 달성합니다.
이 전략은 주로 세 가지의 변수인 Hull Moving Average, 즉 일반 Hull Moving Average ((HMA), 가중된 Hull Moving Average ((WHMA) 및 지수 Hull Moving Average ((EHMA) 를 기반으로 한다. 코드에 따라, 이 전략은 사용자가 세 가지 Hull MA 사이에서 전환할 수 있도록 한다.
HMA의 계산 공식은 다음과 같습니다.
HMA = WMA(2*WMA(close,n/2)-WMA(close,n),sqrt(n))
이 중, WMA는 중화 이동 평균을 나타내고, n은 주기 변수를 나타냅니다. HMA는 SMA (단순 이동 평균) 에 비해 가격 변화에 더 빠르게 반응합니다.
WHMA와 EHMA의 계산 공식은 HMA와 비슷하다. 정책은 HMA를 기본 옵션으로 한다.
HMA를 계산한 후, 이 전략은 HMA의 중선값을 거래 신호로 사용합니다. 가격이 HMA 중선을 넘었을 때, 더 많은 입장이 이루어집니다. 가격이 HMA 중선을 넘었을 때, 평소 입장이 이루어집니다. 따라서 HMA 중선을 사용하여 가격의 중기 경향을 추적하여 수익을 창출합니다.
전통적인 이동 평균 전략에 비해 이 전략은 다음과 같은 장점이 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
대책:
이 전략은 다음과 같은 측면에서 최적화될 수 있습니다.
이 동적 이동 평균 거래 전략은 Hull MA의 신속한 반응 장점을 통합하여 주식 가격의 중기 추세를 효과적으로 추적 할 수 있으며, 적절한 시간에 더 많은 입장을 열고 손실을 막고, 역사 재검토는 좋은 성과를 내고 있습니다. 추가로 파라미터 설정을 최적화하여 주식 범위를 선택하면 이 전략은 더 안정적인 초과 수익을 얻을 수 있습니다.
/*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)