Estratégia de fuga da bandeira de touro

Autora:ChaoZhang, Data: 2024-02-22 16:41:04
Tags:

img

Resumo

A estratégia de ruptura da bandeira de touro é uma estratégia de análise técnica que identifica padrões de gráfico de bandeira de touro e entra no ponto de ruptura, com o objetivo de capturar o início de uma tendência.

Estratégia lógica

As principais etapas desta estratégia são:

  1. Determine o mastro de bandeira: Requer novo alto no preço e ruptura do canal ATR.
  2. Determinar a altura do poste: medir a distância entre o topo do poste e a SMA anterior.
  3. Determinação da distância da bandeira: o fundo da bandeira é 33% da altura do poste como distância mínima.
  4. Identificar padrão de bandeira: julgar se as últimas 3 barras estão dentro do alcance da bandeira.
  5. Entrada: vá longo quando o padrão da bandeira emergir.
  6. Saída: posição de fechamento após fixação de 6 barras.

A estratégia usa o indicador ATR para determinar breakouts significativos e limita estritamente a altura da bandeira dentro de 33% da altura da bandeira para evitar sinais falsos excessivos.

Análise das vantagens

As principais vantagens desta estratégia incluem:

  1. O uso de padrões de bandeira para determinar o início da tendência é um método clássico de análise técnica com alta taxa de sucesso.
  2. ATR e restrições de alcance estritas evitam muitos sinais falsos e melhoram a precisão de entrada.
  3. Fixou fechaduras de saída de 6 bares em alguns lucros e evita riscos de reversão.
  4. Regras claras, fáceis de aplicar, compreender e seguir.
  5. Pode encontrar oportunidades em várias condições de mercado, flexível.

Análise de riscos

Os principais riscos desta estratégia são:

  1. As bandeiras não podem determinar completamente as tendências, as falhas ainda existem.
  2. A saída de 6 bar pode ser prematura e a saída demasiado cedo.
  3. Os mercados agitados podem facilmente produzir falsas bandeiras.
  4. Incapacidade de controlar eficazmente o montante da perda única.

Para lidar com os riscos acima, podemos definir stop losses, otimizar mecanismos de saída para bloquear lucros quando atingirmos uma certa proporção de lucro.

Orientações de otimização

Algumas orientações para otimizar a estratégia:

  1. Combine indicadores como MACD, KD para evitar sinais falsos em mercados agitados.
  2. Parametrizar o multiplicador ATR, período de saída baseado no regime de mercado para melhorar a adaptabilidade.
  3. Definição de um stop loss ou de uma taxa de recuperação de lucro para saídas dinâmicas.
  4. Tente abordagens de aprendizagem de máquina para encontrar melhores recursos para determinar a altura da bandeira.
  5. Avalie a taxa de ganhos e a taxa de lucro reais, ajuste dinamicamente o tamanho da posição.

Conclusão

Em conclusão, a estratégia de ruptura de bandeira de touro utiliza padrão técnico para determinar o início da tendência, um método bastante clássico, e as regras de entrada são de fato rigorosamente projetadas para filtrar muitos sinais falsos.


/*backtest
start: 2024-01-22 00:00:00
end: 2024-02-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// © smith26
//This strategy enters on a bull flag and closes position 6 bars later.  Average true range is used instead of a moving average.
//The reason for ATR instead of MA is because with volatile securities, the flagpole must stand up a noticable "distance" above the trading range---which you can't determine with a MA alone.
//This is broken up into multiple parts: Defining a flagpole, defining the pole height, and defining the flag, which will be constrained to the top third (33%) of the pole height to be considered a flag.
//@version=4
strategy("Bull Flag v1.00", overlay=true)

ATR = atr(10) //Average True Range over last 10 bars.

upperATR = ohlc4[1] + ATR[1]  //Open + High + Low + Close divided by 4, + prior ATR.  Just used here for visually plotting the ATR upper channel.
lowerATR = ohlc4[1] - ATR[1] //Open + High + Low + Close divided by 4, - prior ATR.  Just used here for visually plotting the ATR lower channel.

//uncomment these two lines to see ATR channels
plot(upperATR, color=color.orange)
plot (lowerATR, color=color.orange)

//Current close higher than previous close, and current close minus current open is greater than 3 times the previous ATR.  "3x ATR" is chosen because any less was not a noticeable distance above the trading range.
flagpole1 = close>close[1] and (close-open) > (ATR[1] * 3)
plotshape(flagpole1, text="flagpole1", style=shape.arrowdown, size=size.huge) //Plots an arrow for flagpole1 for QA testing

//Two consecutive close higer than their previous close, and current close minus PREVIOUS open is greater than 3 times the previous ATR.
flagpole2 = close>close[1] and close[1]>close[2] and (close-open[1]) > (ATR[1] * 3)
plotshape(flagpole2, text="flagpole2", style=shape.arrowdown, size=size.huge, color=color.yellow) //Plots an arrow for flagpole2 for QA testing

//Three consecutive close higer than their previous close, and current close minus open from 2 bars ago is greater than 3 times the previous ATR.
flagpole3 = close>close[1] and close[1]>close[2] and close[2]>close[3] and (close-open[2]) > (ATR[1] * 3)
plotshape(flagpole3, text="flagpole3", style=shape.arrowdown, size=size.huge, color=color.white) //Plots an arrow for flagpole3 for QA testing

//A flagpole can be any of the three definitions of flagpole.
flagpole = flagpole1 or flagpole2 or flagpole3

//This will return the number of bars since "flagpole" was true.  Not being used, but could be useful.
//since_flagpole = barssince(flagpole)

after_pole_1 = flagpole[1] //This marks the bar directly after a flagpole.  
//plotshape(after_pole_1, text="after_pole_1", style=shape.cross, size=size.large, color=color.white) //Plots a cross for after_pole_1 for QA testing
after_pole_2 = flagpole[2] //This marks the bar two bars after a flagpole.  
after_pole_3 = flagpole[3] //This marks the bar three bars after a flagpole.  

//This returns the price at the "top" of the flagpole (using close price) at the most recent occurence, 0.
pole_top = valuewhen(flagpole, close, 0)
//plot(pole_top, trackprice=true)  //plots a horizontal line at the most recent pole_top

//Measures the distance between last pole top and the previous SMA.
pole_height = pole_top - sma(close, 10)[1] 
//plot(pole_height)

//This marks 33% below the pole_top, which will be the lowest point a flag can be.
flag_bottom = pole_top - (.33 * pole_height)
//plot(flag_bottom)

//The first, second, and third bars after the pole are considered part of a flag when open and close are between the pole_top and flag_bottom
flag1 = after_pole_1 and (open >= flag_bottom) and (open <= pole_top) and (close >= flag_bottom) and (close <= pole_top)
//plotshape(flag1, text="flag1", style=shape.flag, size=size.large, color=color.teal)
flag2 = after_pole_2 and (open >= flag_bottom) and (open <= pole_top) and (close >= flag_bottom) and (close <= pole_top)
//plotshape(flag2, text="flag2", style=shape.flag, size=size.large, color=color.teal)
flag3 = after_pole_3 and (open >= flag_bottom) and (open <= pole_top) and (close >= flag_bottom) and (close <= pole_top)
//plotshape(flag3, text="flag3", style=shape.flag, size=size.large, color=color.teal)

//When all three bars after a flagpole are a flag, the criteria are met and we have a "bull_flag"
//Specifically, when current bar is flag3, previous bar is flag2, and 2 bars ago is flag1, we have a bull_flag.
bull_flag = flag3 and flag2[1] and flag1[2]
plotshape(bull_flag, text="bull_flag", style=shape.flag, size=size.large, color=color.white) //Plots a flag for bull_flag for QA testing


if (bull_flag)
    strategy.entry("Long", strategy.long)

if barssince(bull_flag) == 6 //close 6 bars after entry.
    strategy.close("Long")

Mais.