Estratégia quantitativa baseada em canais de Keltner e indicador CCI

Autora:ChaoZhang, Data: 2024-02-27 15:47:20
Tags:

img

Resumo

Esta estratégia combina os canais de Keltner, o indicador CCI e o indicador RSI com condições de volume de negociação para criar uma estratégia de negociação quantitativa de filtragem de tendência relativamente completa.

Estratégia lógica

A estratégia toma decisões de negociação fundamentalmente com base nos seguintes indicadores e condições:

  1. Canais de Keltner: Calcular as faixas superior e inferior com base no preço típico e no ATR durante um período para determinar se o preço está dentro do canal.

  2. Indicador CCI: Utilizado para determinar se o preço está sobrecomprado ou sobrevendido.

  3. Indicador RSI: Ajuda a avaliar os níveis de sobrecompra/supervenda.

  4. Volume de negociação: Requer uma ruptura de determinado valor da média móvel.

  5. Filtro de tendência com MAs: utilizar SMA, EMA etc. para determinar a direcção geral da tendência.

Com a condição de direção da tendência satisfeita, os sinais de compra e venda são gerados quando os preços quebram as bandas do canal de Keltner, o CCI e o RSI dão sinais e o volume de negociação aumenta.

Vantagens

A estratégia combina múltiplos indicadores e condições para filtrar sinais incertos e tornar as decisões mais fiáveis:

  1. O filtro de tendências evita mercados voláteis pouco claros.

  2. Os canais de Keltner identificam níveis de fuga.

  3. Os sinais CCI e RSI são relativamente precisos.

  4. O aumento de volume ajuda a prevenir alguns falhos.

Riscos

Principais riscos:

  1. O julgamento de tendências inadequado pode deixar passar tendências mais fortes.

  2. Parâmetros de indicador errados podem causar sinais perdidos ou falsos.

  3. Uma ampliação de volume ineficaz deixa certos riscos de falha.

Orientações de otimização

Direcções de otimização potenciais:

  1. Teste diferentes tipos e comprimentos de MA para obter um melhor filtro de tendência.

  2. Otimizar os parâmetros dos canais de Keltner, CCI, RSI para sinais mais precisos.

  3. Teste diferentes multiplicadores de volume para encontrar o nível ideal.

  4. Considere adicionar stop loss para limitar a perda máxima por negociação.

Conclusão

Em geral, esta estratégia combina os canais de Keltner, CCI, indicadores RSI e condições de volume de negociação para criar uma estratégia de negociação quantitativa de filtragem de tendências relativamente completa. Tem vantagens como evitar mercados voláteis pouco claros, identificar breakouts principais, obter sinais de sobrecompra / sobrevenda relativamente precisos e evitar alguns breakouts falsos. Existem riscos em aspectos como configurações de parâmetros inadequadas e ampliação de volume ineficaz.


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

//@version=4
strategy("Custom Keltner CCI Strategy with Trend Filter", overlay=true )
// Input Parameters for allowing long and short trades
allowLong = input(true, title="Allow Long Trades")
allowShort = input(true, title="Allow Short Trades")
// Trend Filter Inputs
maType = input(title="MA Type", options=["OFF", "SMA", "EMA", "SMMA", "CMA", "TMA"], defval="OFF")
trendFilterMethod = input(title="Trend Filter Method", options=["OFF", "Normal", "Reversed"], defval="OFF")
maLength = input(14, title="MA Length")
// Other Input Parameters
lengthKC = input(30, title="Keltner Channels Length")
multKC = input(0.7, title="Keltner Channels Multiplier")
lengthCCI = input(5, title="CCI Length")
overboughtCCI = input(75, title="CCI Overbought Level")
oversoldCCI = input(-75, title="CCI Oversold Level")
rsiPeriod = input(30, title="RSI Period")
rsiOverbought = input(60, title="RSI Overbought Level")
rsiOversold = input(60, title="RSI Oversold Level")
volumeMultiplier = input(0, title="Volume Multiplier", type=input.float, step=0.1, minval=0)
// Define Moving Averages
var float maValue = na
if (maType == "SMA")
    maValue := sma(close, maLength)
else if (maType == "EMA")
    maValue := ema(close, maLength)
else if (maType == "SMMA")
    maValue := na(maValue[1]) ? sma(close, maLength) : (maValue[1] * (maLength - 1) + close) / maLength
else if (maType == "CMA")
    maValue := na(maValue[1]) ? sma(close, maLength) : (sma(close, maLength) + (sma(close, maLength) - maValue[1])) / 2
else if (maType == "TMA")
    maValue := sma(sma(close, round(maLength/2)), round(maLength/2)+1)
// Entry Conditions with Trend Filter
longCondition = allowLong and (trendFilterMethod == "OFF" or (trendFilterMethod == "Normal" and close > maValue) or (trendFilterMethod == "Reversed" and close < maValue))
shortCondition = allowShort and (trendFilterMethod == "OFF" or (trendFilterMethod == "Normal" and close < maValue) or (trendFilterMethod == "Reversed" and close > maValue))
// Keltner Channels
typicalPrice = hlc3
middleLine = sma(typicalPrice, lengthKC)
range = multKC * atr(lengthKC)
upperChannel = middleLine + range
lowerChannel = middleLine - range
// CCI
cci = cci(close, lengthCCI)
// RSI
rsi = rsi(close, rsiPeriod)
// Volume
volCondition = volume > sma(volume, 50) * volumeMultiplier
// Combined Entry Conditions with Trend Filter
longCondition := longCondition and cci < oversoldCCI and low < lowerChannel and rsi < rsiOversold and volCondition
shortCondition := shortCondition and cci > overboughtCCI and high > upperChannel and rsi > rsiOverbought and volCondition
// Execute orders at the open of the new bar after conditions are met
if (longCondition)
    strategy.entry("Long", strategy.long)
if (shortCondition)
    strategy.entry("Short", strategy.short)
// Exit Conditions
strategy.close("Long", when = cci > 0)
strategy.close("Short", when = cci < 0)
// Plotting
plot(upperChannel, color=color.red, linewidth=1)
plot(lowerChannel, color=color.green, linewidth=1)
hline(overboughtCCI, "Overbought", color=color.red)
hline(oversoldCCI, "Oversold", color=color.green)

Mais.