Hull Fisher Adaptativa Inteligente Estratégia Multifator

Autora:ChaoZhang, Data: 2024-01-16 15:10:06
Tags:

img

Resumo

Esta estratégia combina a média móvel de Hull, o indicador Fisher Transform e o índice de canal de commodities numa estratégia multifator adaptativa, capaz de identificar de forma inteligente tendências, ajustar automaticamente parâmetros e adaptar-se a diferentes produtos e ciclos.

Estratégia lógica

O indicador Fisher Transform combina as vantagens das médias móveis e osciladores para julgar com mais precisão os pontos de virada.

A estratégia calcula primeiro o indicador de média móvel de Hull e o indicador de transformação de Fisher. Em seguida, com a ajuda do índice de canal de commodities, forme as condições de entrada. Quando o indicador de transformação de Fisher cruza para cima abaixo da linha zero ou cruza para fora da faixa de parâmetros definida, é definido como uma condição de cruz dourada para formar um sinal longo; quando a transformação de Fisher cruza para baixo acima da linha zero ou fora da faixa de parâmetros, é definido como uma condição de cruz morta para formar um sinal curto.

As condições de saída são opostas, as ordens longas abertas em cruzes douradas são fechadas em cruzes mortas; as ordens curtas abertas em cruzes mortas são fechadas em cruzes douradas.

Análise das vantagens

A maior vantagem desta estratégia é o multifator adaptativo. Ele aproveita as médias móveis, osciladores e indicadores de tendência para ter um bom desempenho em mercados em queda e em ascensão. Os parâmetros também podem ser ajustados de acordo com a variedade e o ciclo para alcançar adaptabilidade.

Além disso, a estratégia incorpora um mecanismo automático de stop loss. Quando o preço retorna acima da média móvel do casco, ele irá automaticamente parar a perda para sair. Isso reduz muito o risco de perda para a estratégia.

Riscos e soluções

O maior risco desta estratégia são os sinais de erro entre os indicadores. Quando o preço se move para o lado, os indicadores podem produzir alguns cruzes desnecessários. Isso levará a entrada desnecessária e stop loss.

A solução é ajustar adequadamente os parâmetros do indicador para filtrar alguns sinais pequenos. ou combinar mais indicadores auxiliares para confirmação. por exemplo, adicionar um indicador de volume para determinar sinais verdadeiros.

Orientações de otimização

A estratégia pode ser otimizada nas seguintes direcções:

  1. Adicionar algoritmos de aprendizado de máquina para obter otimização automática de parâmetros.

  2. Adicionar mais indicadores para pontuação, adotar estratégia de decisão por maioria e melhorar a precisão da decisão.

  3. Adicionar um mecanismo de confirmação de ruptura que utilize níveis de preço e canais importantes para confirmação novamente para evitar falhas de operação.

  4. Adicionar um módulo de avaliação de risco que possa ajustar automaticamente o tamanho da posição e a faixa de stop loss com base nas condições de mercado.

Conclusão

No geral, esta é uma estrutura multifator adaptativa muito boa. Ela combina o julgamento da tendência das médias móveis, os julgamentos de sobrecompra e sobrevenda dos osciladores e a aplicação de cruzes de indicadores, formando um mecanismo completo de entrada e saída. Se puder ser otimizado e aumentar os componentes adaptativos e inteligentes, se tornará um produto de estratégia com valor comercial extremamente alto.


/*backtest
start: 2023-01-09 00:00:00
end: 2024-01-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is free to copy/paste/use. no permission required. just do it!
// © @SeaSide420 
//@version=4
strategy(title="Hull Fisher",currency="USD",default_qty_type=strategy.percent_of_equity,default_qty_value=100,commission_type=strategy.commission.percent,commission_value=0.25)

//=================================== Inputs =========================================================
period =input(title="HullMA Length", type=input.integer, defval=14, minval=2)
length =input(9, minval=1, title="Signal Length")
line1 = input(5, minval=2, title="Top Line")
line5 = input(-5, maxval=-2, title="Bottom Line")
price = input(open, type=input.source, title="Price data")
entry1 =input(true,type=input.bool, title="Open when HullFisher crossover outside Lines")
entry2 =input(true,type=input.bool, title="Open when HullFisher past zero")
useHMA =input(true,type=input.bool, title="Include Hull_moving_average")
useCCI =input(true,type=input.bool, title="Include Commodity_channel_index")
fishclose=input(true,type=input.bool, title="Close order when Fisher crossover")
HMAclose=input(true,type=input.bool, title="Close order when Hull crossover")

//================================ Calculations ======================================================
HMA = hma(price,period)
HMA2 = HMA[1]
high_ = highest(HMA, length)
low_ = lowest(HMA, length)
round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
value = 0.0
value := round_(.66 * ((HMA - low_) / max(high_ - low_, .001) - .5) + .67 * nz(value[1]))
value1 = 0.0
value1 := .5 * log((1 + value) / max(1 - value, .001)) + .5 * nz(value1[1])
value2 = value1[1]
CCI1 = cci(price,period)
CCI2 = CCI1[1]
line2 = line1/2
line4 = line5/2

//================================ Draw Plots =======================================================
colorchange1 =CCI1>CCI2?color.lime:color.red
colorchange2 =value1>value2?color.lime:color.red
a =plot(line1,style=plot.style_line,color=color.red,transp=50,linewidth=2,title="Top Line")
b =plot(line2,style=plot.style_line,color=color.red,transp=50,linewidth=2,title="Upper Line")
c =plot(0,style=plot.style_line,color=color.black,transp=50,linewidth=2,title="Middle Line")
d =plot(line4,style=plot.style_line,color=color.lime,transp=50,linewidth=2,title="Lower Line")
e =plot(line5,style=plot.style_line,color=color.lime,transp=50,linewidth=2,title="Bottom Line")
f =plot(value1, color=color.black,transp=50,linewidth=2, title="Value 1")
g =plot(value2, color=color.black,transp=50,linewidth=2, title="Value 2")
h =plot(CCI1/50,style=plot.style_area, color=colorchange1,transp=50,linewidth=2, title="CCI")
fill(f,g,color=colorchange2,transp=20,title="Color fill")
plot(cross(value1, value2) ? value1 : na, style=plot.style_circles, color=color.black, linewidth=10)
plot(cross(value1, value2) ? value1 : na, style=plot.style_circles, color=color.white, linewidth=8)
plot(cross(value1, value2) ? value1 : na, style=plot.style_circles, color=colorchange2, linewidth=5)

//============================= Entry conditions ====================================================
// Outside Lines crossover or zero lines crossover
LongCondition1 = value1>value2 and value1<line5 and entry1 and not useCCI and not useHMA
ShortCondition1 = value1<value2 and value1>line1 and entry1 and not useCCI and not useHMA
LongCondition2 = value1>value2 and value1>0 and entry2 and not useCCI and not useHMA
ShortCondition2 = value1<value2 and value1<0 and entry2 and not useCCI and not useHMA

// Use CCI
LongCondition3 = value1>value2 and value1<line5 and CCI1>CCI2 and entry1 and useCCI and not useHMA
ShortCondition3 = value1<value2 and value1>line1 and CCI1<CCI2 and entry1 and useCCI and not useHMA
LongCondition4 = value1>value2 and value1>0 and CCI1>CCI2 and entry2 and useCCI and not useHMA
ShortCondition4 = value1<value2 and value1<0 and CCI1<CCI2 and entry2 and useCCI and not useHMA

// Use HMA
LongCondition5 = value1>value2 and value1<line5 and CCI1>CCI2 and HMA>HMA2 and entry1 and not useCCI and useHMA
ShortCondition5 = value1<value2 and value1>line1 and CCI1<CCI2 and HMA<HMA2 and entry1 and not useCCI and useHMA
LongCondition6 = value1>value2 and value1>0 and CCI1>CCI2 and HMA>HMA2 and entry2 and not useCCI and useHMA
ShortCondition6 = value1<value2 and value1<0 and CCI1<CCI2 and HMA<HMA2 and entry2 and not useCCI and useHMA

//Use CCI & HMA
LongCondition7 = value1>value2 and value1<line5 and CCI1>CCI2 and HMA>HMA2 and entry1 and useCCI and useHMA
ShortCondition7 = value1<value2 and value1>line1 and CCI1<CCI2 and HMA<HMA2 and entry1 and useCCI and useHMA
LongCondition8 = value1>value2 and value1>0 and CCI1>CCI2 and HMA>HMA2 and entry2 and useCCI and useHMA
ShortCondition8 = value1<value2 and value1<0 and CCI1<CCI2 and HMA<HMA2 and entry2 and useCCI and useHMA

//========================= Exit & Entry excecution =================================================
if HMAclose and fishclose and value1<value2 and HMA<HMA2
    strategy.close("BUY")
if HMAclose and fishclose and value1>value2 and HMA>HMA2
    strategy.close("SELL")
if HMAclose and HMA<HMA2
    strategy.close("BUY")
if HMAclose and HMA>HMA2
    strategy.close("SELL")
if fishclose and value1<value2
    strategy.close("BUY")
if fishclose and value1>value2
    strategy.close("SELL")    
if LongCondition1 or LongCondition2 or LongCondition3 or LongCondition4 or LongCondition5 or LongCondition6 or LongCondition7 or LongCondition8
    strategy.entry("BUY", strategy.long)
if ShortCondition1 or ShortCondition2 or ShortCondition3 or ShortCondition4 or ShortCondition5 or ShortCondition6 or ShortCondition7 or ShortCondition8
    strategy.entry("SELL", strategy.short)


Mais.