A estratégia de ruptura do RSI é uma estratégia quantitativa de negociação

Autora:ChaoZhang, Data: 22-12-2023 14:06:45
Tags:

img

Resumo

A estratégia de ruptura do RSI é uma estratégia quantitativa de negociação baseada no indicador Relative Strength Index (RSI). A estratégia gera sinais de negociação quando o RSI quebra os valores de limiar de sobrecompra e sobrevenda pré-estabelecidos, ou seja, vai longo quando o RSI está abaixo de 30 e vai curto quando o RSI está acima de 70.

Estratégia lógica

A ideia central da estratégia de ruptura do RSI é utilizar o indicador RSI para determinar as condições de sobrecompra e sobrevenda no mercado. O RSI calcula a relação de ganhos e perdas médios de preços ao longo de um período de tempo para refletir a força ou fraqueza recente de um estoque. Geralmente, o RSI abaixo de 30 é considerado sobrevendido e o RSI acima de 70 é considerado sobrecomprado.

A estratégia primeiro define os valores de limiar de sobrevenda e sobrecompra para o RSI, com valores padrão de 30 e 70. Em seguida, monitora a linha do RSI em tempo real. Quando o RSI cruza abaixo do limiar de 70 de cima para baixo, um sinal de venda é gerado. Isso indica que o mercado entrou na zona de sobrecompra e provavelmente reverterá para baixo, então uma posição curta é tomada. Por outro lado, quando o RSI quebra acima do limiar de 30, um sinal de compra é gerado, indicando que o mercado de sobrevenda provavelmente voltará a subir, então uma posição longa é tomada.

Desta forma, a estratégia tenta capturar pontos de reversão dos preços durante as flutuações das acções e ajustar as posições em conformidade para "comprar baixo e vender alto".

Vantagens

A estratégia de ruptura do RSI tem as seguintes vantagens:

  1. O indicador RSI é fácil de calcular e interpretar simplesmente observando se a linha do indicador quebra os valores de limiar.

  2. O RSI é um indicador de retorno de negócios que permite que os investimentos sejam gerados pelo indicador RSI sem interferência humana. Ao mesmo tempo, os sinais de sobrecompra e sobrevenda do RSI tendem a ser eficazes, levando a retornos de estratégia decentes nos retrotestes.

  3. Os traders podem ajustar com flexibilidade os parâmetros do RSI, como os limiares de sobrecompra/supervenda, para se adequarem a diferentes ações e dinâmicas de mercado.

Riscos

A estratégia de ruptura do RSI também traz alguns riscos:

  1. A frequente cruzamento dos valores limiares do indicador pode levar a negociações ineficazes excessivas, dificultando lucros constantes.

  2. O RSI é um indicador de tendência de mercado, que não produz sinais baseados em níveis de sobrecompra / sobrevenda sem julgar bem a tendência geral.

  3. Riscos elevados de retirada. O RSI geralmente exibe uma divergência de alta, onde o preço continua a subir enquanto o RSI tem tendências de queda.

Áreas de melhoria

A estratégia de ruptura do RSI pode ser reforçada das seguintes formas:

  1. Incorporar múltiplos indicadores para superar as limitações do RSI, por exemplo, médias móveis para determinar a tendência do mercado, indicadores de força e filtros de volume para confirmar os sinais.

  2. Otimizar os parâmetros do RSI para uma maior estabilidade, incluindo ajustar os limiares de sobrecompra / sobrevenda, definir o filtro de duração do sinal, etc. através de testes rigorosos.

  3. Implementar stop loss e take profit para controlar os riscos. Por exemplo, definir paradas percentuais ou pontuais. Evitar perdas individuais de grande porte sobre os lucros globais. Também considerar tendências e pontos técnicos para a tomada de lucro.

Conclusão

A estratégia de ruptura do RSI é uma estratégia quantitativa de reversão média baseada em sinais de sobrecompra e sobrevenda.


/*backtest
start: 2023-11-21 00:00:00
end: 2023-12-21 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Bunghole 2021

strategy(title="My New Strategy", initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0, currency = 'USD', overlay=true)

//// Stoploss and Take Profit Parameters
// Enable Long Strategy
enable_long_strategy = input(true, title="Enable Long Strategy", group="SL/TP For Long Strategy",inline="1")
long_stoploss_value = input(defval=50, title='Stoploss %', type=input.float, minval=0.1, group="SL/TP For Long Strategy",inline="2")
long_stoploss_percentage = (close * (long_stoploss_value / 100)) / syminfo.mintick
long_takeprofit_value = input(defval=50, title='Take Profit %', type=input.float, minval=0.1, group="SL/TP For Long Strategy",inline="2")
long_takeprofit_percentage = (close * (long_takeprofit_value / 100)) / syminfo.mintick

// Enable Short Strategy
enable_short_strategy = input(true, title="Enable Short Strategy", group="SL/TP For Short Strategy",inline="3")
short_stoploss_value = input(defval=50, title='Stoploss %', type=input.float, minval=0.1, group= "SL/TP For Short Strategy",inline="4")
short_stoploss_percentage = (close * (short_stoploss_value / 100)) / syminfo.mintick
short_takeprofit_value = input(defval=50, title='Take Profit %', type=input.float, minval=0.1, group="SL/TP For Short Strategy",inline="4")
short_takeprofit_percentage = (close * (short_takeprofit_value / 100)) / syminfo.mintick

// Plot Stoploss & Take Profit Levels
long_stoploss_price = strategy.position_avg_price * (1 - long_stoploss_value/100)
long_takeprofit_price = strategy.position_avg_price * (1 + long_takeprofit_value/100)
short_stoploss_price = strategy.position_avg_price * (1 + short_stoploss_value/100)
short_takeprofit_price = strategy.position_avg_price * (1 - short_takeprofit_value/100)
plot(enable_long_strategy and not enable_short_strategy ? long_stoploss_price: na, color=#ff0000, style=plot.style_linebr, linewidth=2, title="Long SL Level")
plot(enable_long_strategy and not enable_short_strategy ? long_takeprofit_price: na, color=#008000, style=plot.style_linebr, linewidth=2, title="Long TP Level")
plot(enable_short_strategy and not enable_long_strategy ? short_stoploss_price: na, color=#ff0000, style=plot.style_linebr, linewidth=2, title="Short SL Level")
plot(enable_short_strategy and not enable_long_strategy ? short_takeprofit_price: na, color=#008000, style=plot.style_linebr, linewidth=2, title="Short TP Level")

// Date Range
start_date = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31, group="Date Range")
start_month = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12, group="Date Range")
start_year = input(title="Start Year", type=input.integer, defval=1804, minval=1800, maxval=3000, group="Date Range")
end_date = input(title="End Date", type=input.integer, defval=1, minval=1, maxval=3, group="Date Range")
end_month = input(title="End Month", type=input.integer, defval=1, minval=1, maxval=12, group="Date Range")
end_year = input(title="End Year", type=input.integer, defval=2077, minval=1800, maxval=3000, group="Date Range")
in_date_range = (time >= timestamp(syminfo.timezone, start_year, start_month, start_date, 0, 0)) and (time < timestamp(syminfo.timezone, end_year, end_month, end_date, 0, 0))

//// Inputs   **This is where you enter your indicators for your strategy. For example, I added the RSI indicator.**
//RSI
rsi = rsi(close, 14)
rsi_over_sold = rsi < 30
rsi_over_bought = rsi > 70


//// Strategy  **This is where you create your strategy. For example, We have or buy and sell signals.**
// Creating Long and Short Strategy
buy_signal = rsi_over_sold
sell_signal = rsi_over_bought

// Long Strategy
if buy_signal and in_date_range and enable_long_strategy == true
    strategy.entry("Long", true, when=buy_signal, alert_message="Open Long Position")
    strategy.exit("Long  SL/TP", from_entry="Long", loss=long_stoploss_percentage, profit=long_takeprofit_percentage, alert_message="Your Long SL/TP Limit As Been Triggered.")
    strategy.close("Long", when=sell_signal, alert_message="Close Long Position")
    
// Short Strategy
if sell_signal and in_date_range and enable_short_strategy == true
    strategy.entry("Short", false, when = sell_signal, alert_message="Open Short Position")
    strategy.exit("Short SL/TP", from_entry="Short", loss=short_stoploss_percentage, profit=short_takeprofit_percentage, alert_message="Your Short SL/TP Limit As Been Triggered.")
    strategy.close("Short", when=buy_signal, alert_message="Close Short Position")


Mais.