Golden Cross Keltner Canal Tendência Seguindo a Estratégia

Autora:ChaoZhang, Data: 2023-11-02 14:31:10
Tags:

img

Resumo

O Golden Cross Keltner Channel Trend Following Strategy é uma estratégia que negocia apenas na direção da tendência.

Princípio

Esta estratégia usa duas médias móveis, uma média móvel de curto prazo e uma média móvel de longo prazo, para formar cruzes de ouro e cruzes de morte para determinar a direção da tendência.

Especificamente, a estratégia verifica primeiro se a média móvel de longo prazo está acima da média móvel de curto prazo, indicando uma cruz de ouro e uma tendência ascendente.

Com base na determinação da tendência, se o preço quebra acima do trilho superior, um sinal longo é gerado. Se o preço quebra abaixo do trilho inferior, um sinal curto é gerado.

Após a entrada, a estratégia usa múltiplos ATR definidos pelo usuário para take-profit e stop-loss.

Análise das vantagens

Esta estratégia combina as vantagens do seguimento de tendências e das rupturas de canais, permitindo uma identificação eficaz das tendências e a captura de oportunidades.

  1. A cruz de ouro filtra sinais falsos não alinhados com a tendência principal.

  2. A ruptura do canal com a direcção da tendência melhora a precisão de entrada.

  3. O "take profit" e o "stop loss" preservam os lucros e controlam os riscos.

  4. Ajustes flexíveis de parâmetros adequam-se a diferentes produtos e ambientes.

  5. Vai tanto para o longo quanto para o curto, expandindo a aplicabilidade.

Análise de riscos

Apesar das vantagens, alguns riscos requerem atenção:

  1. Perder oportunidades de reversão.

  2. As alterações de tendência podem conduzir a perdas.

  3. Os parâmetros inadequados podem provocar uma troca excessiva ou escassa.

  4. Existe o risco de uma noite.

  5. Risco de ajustamento da curva.

As soluções incluem a otimização de parâmetros, o ajuste oportuno do período de MA e o controle do dimensionamento da posição.

Orientações de otimização

Há ainda espaço para melhorias:

  1. Adicionar mais indicadores para construir um modelo multifator e melhorar a precisão.

  2. Optimização de parâmetros através de aprendizagem de máquina para adaptabilidade ao mercado.

  3. Regras dinâmicas de take-profit e stop-loss para equilibrar a rentabilidade e a recompensa.

  4. A classificação dinâmica das posições baseada na volatilidade.

  5. Pesquisar parâmetros ótimos para diferentes produtos.

  6. Reduzir a frequência de negociação para minimizar as taxas.

Conclusão

O Golden Cross Keltner Channel Trend Following Strategy é geralmente um sistema estável e confiável de tendência. Combinando filtragem de tendência e rupturas de canal, ele identifica oportunidades de alta probabilidade alinhadas com a direção da tendência.


/*backtest
start: 2022-10-26 00:00:00
end: 2023-11-01 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OversoldPOS

//@version=5
// strategy("Keltner Channel Strategy by OversoldPOS", overlay=true,initial_capital = 100000,default_qty_type = strategy.percent_of_equity,default_qty_value = 10, commission_type = strategy.commission.cash_per_order, commission_value = 7)

// Parameters
length = input(21, title="MA Length")
Entrymult = input(1, title="Entry ATR")
profit_mult = input(4, title="Profit Taker")
exit_mult = input(-1, title="Exit ATR")

// Moving Average Type Input
ma_type = input.string("SMA", title="Moving Average Type", options=["SMA", "EMA", "WMA"])

// Calculate Keltner Channels for different ATR multiples
atr_value = ta.atr(length)

basis = switch ma_type
    "SMA" => ta.sma(close, length)
    "EMA" => ta.ema(close, length)
    "WMA" => ta.wma(close, length)
 

//
EntryKeltLong = basis + Entrymult * ta.atr(10)
EntryKeltShort = basis - Entrymult * ta.atr(10)
upper_channel1 = basis + 1 * ta.atr(10)
lower_channel1 = basis - 1 * ta.atr(10)
upper_channel2 = basis + 2 * ta.atr(10)
lower_channel2 = basis - 2 * ta.atr(10)
upper_channel3 = basis + 3 * ta.atr(10)
lower_channel3 = basis - 3 * ta.atr(10)
upper_channel4 = basis + 4 * ta.atr(10)
lower_channel4 = basis - 4 * ta.atr(10)

// Entry condition parameters
long_entry_condition = input(true, title="Long Positions")
short_entry_condition = input(true, title="Enable Short Positions")

// Additional conditions for long and short entries
is_long_entry = ta.ema(close, 20) > ta.ema(close, 50)
is_short_entry = ta.ema(close, 20) < ta.ema(close, 50)

// Additional conditions for long and short entries
MAShort =  input(50, title="Short MA for Golden Cross")
MALong =  input(200, title="Long MA for Golden Cross")
is_long_entry2 = ta.ema(close, MAShort) > ta.ema(close, MALong)
is_short_entry2 = ta.ema(close, MAShort) < ta.ema(close, MALong)

// Exit condition parameters
long_exit_condition1_enabled = input(true, title="Enable Long Profit Taker")
long_exit_condition2_enabled = input(true, title="Enable Long Stop")
short_exit_condition1_enabled = input(true, title="Enable Short Profit Taker")
short_exit_condition2_enabled = input(true, title="Enable Short Stop")

// Take Profit condition parameters
take_profit_enabled = input(true, title="Enable Take Profit Condition")

Takeprofit = basis + profit_mult * atr_value
STakeprofit = basis - profit_mult * atr_value

// Long entry condition
long_condition = long_entry_condition and ta.crossover(close, EntryKeltLong) and is_long_entry2

// Short entry condition
short_condition = short_entry_condition and ta.crossunder(close, EntryKeltShort) and is_short_entry2

// Exit conditions
long_exit_condition1 = long_exit_condition1_enabled and close > Takeprofit
long_exit_condition2 = long_exit_condition2_enabled and close < basis + exit_mult * atr_value
short_exit_condition1 = short_exit_condition1_enabled and close < STakeprofit
short_exit_condition2 = short_exit_condition2_enabled and close > basis - exit_mult * atr_value

// Strategy logic
if (long_condition)
    strategy.entry("Long", strategy.long)
if (short_condition)
    strategy.entry("Short", strategy.short)

if (long_exit_condition1 or long_exit_condition2)
    strategy.close("Long")

if (short_exit_condition1 or short_exit_condition2)
    strategy.close("Short")

// Moving Averages
var float MA1 = na
var float MA2 = na

if (ma_type == "SMA")
    MA1 := ta.sma(close, MAShort)
    MA2 := ta.sma(close, MALong)
else if (ma_type == "EMA")
    MA1 := ta.ema(close, MAShort)
    MA2 := ta.ema(close, MALong)
else if (ma_type == "WMA")
    MA1 := ta.wma(close, MAShort)
    MA2 := ta.wma(close, MALong)

// Plotting Keltner Channels with adjusted transparency
transparentColor = color.rgb(255, 255, 255, 56)

plot(upper_channel1, color=transparentColor, title="Upper Channel 1")
plot(lower_channel1, color=transparentColor, title="Lower Channel 1")
plot(upper_channel2, color=transparentColor, title="Upper Channel 2")
plot(lower_channel2, color=transparentColor, title="Lower Channel 2")
plot(upper_channel3, color=transparentColor, title="Upper Channel 3")
plot(lower_channel3, color=transparentColor, title="Lower Channel 3")
plot(upper_channel4, color=transparentColor, title="Upper Channel 4")
plot(lower_channel4, color=transparentColor, title="Lower Channel 4")
plot(basis, color=color.white, title="Basis")
plot(MA1, color=color.rgb(4, 248, 216), linewidth=2, title="Middle MA")
plot(MA2, color=color.rgb(220, 7, 248), linewidth=2, title="Long MA")


Mais.