RSI e estratégia de ruptura da média móvel

Autora:ChaoZhang, Data: 2024-01-24 14:31:01
Tags:

img

Resumo

A estratégia de ruptura do RSI e da média móvel é uma estratégia quantitativa que utiliza tanto o indicador do RSI quanto as linhas médias móveis para determinar oportunidades de negociação.

Estratégia lógica

  1. Calcular o indicador RSI e as linhas da média móvel simples com base em parâmetros definidos pelo utilizador.

  2. Quando o RSI cruza acima da linha de sobrevenda (default 30), um sinal longo é gerado se o preço estiver abaixo da média móvel de saída LONG.

  3. Quando o RSI cruza abaixo da linha de sobrecompra (default 70), um sinal curto é gerado se o preço estiver acima da média móvel de saída curta.

  4. Os usuários podem escolher filtrar sinais com base em uma linha de média móvel de tendência.

  5. As saídas são determinadas pelas linhas de saída LONG e SHORT Moving Average.

Análise das vantagens

  1. A concepção de indicadores duplos melhora a precisão ao incorporar dois factores de mercado importantes.

  2. Utiliza a característica de reversão média do RSI de forma eficaz para localizar pontos de virada.

  3. Filtro adicional com médias móveis aumenta o rigor lógico para evitar perseguir tops e bottoms.

  4. Parâmetros personalizáveis permitem otimizações em diferentes produtos e prazos.

  5. A lógica simples torna-a fácil de compreender e modificar.

Análise de riscos

  1. Os whipssaws são comuns com RSI, o indicador de densidade pode ajudar.

  2. O RSI tende a falhar em prazos mais longos, os parâmetros podem ser ajustados ou indicadores adicionais podem ajudar.

  3. As médias móveis têm um efeito de atraso, os comprimentos podem ser encurtados ou indicadores como o MACD podem ajudar.

  4. Devem ser introduzidos mais indicadores para validar os sinais devido à lógica básica.

Orientações de otimização

  1. Otimizar os parâmetros do RSI ou introduzir um indicador de densidade para reduzir os falsos sinais.

  2. Incorporar indicadores de tendência e volatilidade como DMI e BOLL para localizar tendências e suporte.

  3. Introduzir o MACD para substituir ou complementar os julgamentos da média móvel.

  4. Adicionar mais condições lógicas em sinais de entrada para evitar fugas desfavoráveis.

Conclusão

A estratégia combina a detecção de sobrecompra e sobrevenda de RSI e determinação de tendência de médias móveis para capitalizar as oportunidades de reversão da média teoricamente. A estratégia é intuitiva e fácil de usar para iniciantes, e pode ser otimizada em diferentes produtos, tornando-se uma estratégia quantitativa inicial recomendada.


/*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))
    
    
    
    
    
    
   





Mais.