
A estratégia combina os benefícios dos indicadores de volume dinâmico e das médias móveis para acompanhar a tendência do preço das ações a médio prazo e obter ganhos estáveis.
A estratégia baseia-se principalmente em três variantes de Hull Moving Average, incluindo a Hull Moving Average ((HMA), a Hull Moving Average ((WHMA) e a Hull Moving Average ((EHMA). De acordo com o código, a estratégia permite que o usuário altere entre os três tipos de Hull MA.
A fórmula de cálculo do HMA é:
HMA = WMA(2*WMA(close,n/2)-WMA(close,n),sqrt(n))
Dentre eles, o WMA representa uma média móvel ponderada e o n representa um parâmetro de ciclo. O HMA responde mais rapidamente às mudanças de preço do que o SMA (média móvel simples).
As fórmulas de cálculo para WHMA e EHMA são semelhantes às do HMA. A política tem HMA como opção padrão.
Depois de calcular o HMA, a estratégia usa o valor da linha média do HMA como sinal de negociação. Quando o preço atravessa a linha média do HMA, faz uma entrada maior; Quando o preço atravessa a linha média do HMA, sai da posição zero. Assim, usa a linha média do HMA para acompanhar a tendência do preço a médio prazo e obter lucro.
Em comparação com a estratégia de média móvel tradicional, a estratégia tem as seguintes vantagens:
A estratégia também apresenta alguns riscos:
Resposta:
A estratégia também pode ser melhorada em:
Esta estratégia de negociação de média móvel dinâmica integra os benefícios de resposta rápida do Hull MA, que pode acompanhar de forma eficaz a tendência do preço da ação a médio prazo, abrir mais posições no momento certo e parar de perder, o histórico de retrospectiva é bom. A estratégia pode obter um excedente de lucro mais estável por meio de configurações de parâmetros e seleção de ações.
/*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)