Estratégia quantitativa usando indicador RSI e indicador de média móvel


Data de criação: 2024-01-24 14:31:01 última modificação: 2024-01-24 14:31:01
cópia: 0 Cliques: 715
1
focar em
1617
Seguidores

Estratégia quantitativa usando indicador RSI e indicador de média móvel

Visão geral

A estratégia de ruptura de linha de equilíbrio do RSI é uma estratégia quantitativa que usa o indicador RSI e o indicador da linha de equilíbrio para julgar o tempo de negociação. A idéia central da estratégia é usar a direção da linha de equilíbrio para filtrar os sinais e buscar pontos de ruptura de melhor qualidade para construir posições quando o indicador RSI atinge uma área de sobrevenda.

Princípio da estratégia

  1. O RSI e a SMA são calculados de acordo com os parâmetros definidos pelo usuário.

  2. Quando o RSI atravessa a linha de ultra-venda definida (default 30), um sinal de multi-cabeça é gerado se o preço estiver abaixo da linha média de saída LONG.

  3. Quando o RSI atravessa a linha de sobrevenda definida (default 70) abaixo, um sinal de cabeça-vazio é gerado se o preço estiver acima da linha média de saída SHORT.

  4. O usuário pode selecionar a linha média de filtragem, e o sinal é gerado quando o preço está acima da linha média de filtragem.

  5. A saída da posição é julgada de acordo com a linha média de saída LONG e a linha média de saída SHORT.

Análise de vantagens

  1. O design de dois indicadores, com referência a dois fatores de mercado, aumenta a precisão da tomada de decisão.

  2. Aproveite a característica de inversão do RSI para encontrar o momento da inversão.

  3. O filtro de linha média aumenta a rigoridade do julgamento e evita a perseguição de altos e baixos.

  4. Permite a personalização de parâmetros, que podem ser otimizados para diferentes variedades e ciclos.

  5. O design lógico é simples, fácil de entender e modificar.

Análise de Riscos

  1. O indicador RSI é propenso a produzir linhas verticais, o indicador de densidade pode reduzir esse problema.

  2. O RSI em grandes períodos é fácil de falhar, pode reduzir a otimização de parâmetros ou auxiliar outros indicadores.

  3. A linha média tem um atraso e pode ser apropriadamente reduzida para comprimento da linha média ou auxiliar indicadores como MACD.

  4. A simplificação dos critérios de avaliação permite a introdução de mais indicadores para garantir a eficácia dos sinais de negociação.

Direção de otimização

  1. Otimizar os parâmetros do RSI ou introduzir um indicador de densidade reduz a probabilidade de falso sinal.

  2. Combinação de tendências e indicadores de flutuação como DMI, BOLL para determinar tendências e suportes.

  3. A introdução de indicadores como MACD para substituir ou colaborar com o julgamento de equilíbrio.

  4. Aumentar a lógica das condições de abertura de posição para evitar sinais de ruptura indesejáveis.

Resumir

A estratégia de ruptura de linha de equilíbrio de RSI dupla usa o método integrado do indicador RSI para determinar a tendência de compra e venda excessiva e de avaliação de linha de equilíbrio. Em teoria, é possível aproveitar efetivamente a oportunidade de reversão. A estratégia é flexível e simples, fácil de usar, mas também adequada para a otimização de diferentes variedades.

Código-fonte da estratégia
/*backtest
start: 2024-01-16 00:00:00
end: 2024-01-23 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Global Market Signals: RSI Strategy.
//@version=4
strategy("GMS: RSI Strategy", overlay=true)

LongShort = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"])
RSILength = input(title="RSI Length", type = input.integer ,defval=14)
RSIUpper = input(title="Upper Threshold", type = input.float ,defval=70)
RSILower = input(title="Lower Threshold", type = input.float ,defval=30)
LongExit = input(title="Long Exit SMA Length", type = input.integer ,defval=5)
ShortExit = input(title="Short Exit SMA Length", type = input.integer ,defval=5)
AboveBelow = input(title="Trend SMA Filter?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"])
TrendLength = input(title="Trend SMA Length", type = input.integer ,defval=200)


//Long Side

if LongShort =="Long Only" and AboveBelow == "Above"
    strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,LongExit))
    
if LongShort =="Long Only" and AboveBelow == "Below"
    strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close<sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,LongExit))
    
if LongShort =="Long Only" and AboveBelow == "Don't Include"
    strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit))
    strategy.close("LONG", when = close>sma(close,LongExit))
    
if LongShort =="Both" and AboveBelow == "Above"
    strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,LongExit))
    
if LongShort =="Both" and AboveBelow == "Below"
    strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close<sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,LongExit))
    
if LongShort =="Both" and AboveBelow == "Don't Include"
    strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit))
    strategy.close("LONG", when = close>sma(close,LongExit))
    
    
//SHORT SIDE

if LongShort =="Short Only" and AboveBelow == "Above"
    strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,ShortExit))
    
if LongShort =="Short Only" and AboveBelow == "Below"
    strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close<sma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,ShortExit))
    
if LongShort =="Short Only" and AboveBelow == "Don't Include"
    strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit))
    strategy.close("SHORT", when = close<sma(close,ShortExit))
    
if LongShort =="Both" and AboveBelow == "Above"
    strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,ShortExit))
    
if LongShort =="Both" and AboveBelow == "Below"
    strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close<sma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,ShortExit))
    
if LongShort =="Both" and AboveBelow == "Don't Include"
    strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit))
    strategy.close("SHORT", when = close<sma(close,ShortExit))