Estratégia de avanço do RSI duplo rápido

Autora:ChaoZhang, Data: 2023-11-07 16:56:39
Tags:

img

Resumo

Esta estratégia utiliza múltiplos indicadores RSI para implementar avanços de preços para gerar sinais de entrada e saída mais precisos.

Estratégia lógica

A estratégia define dois grupos de parâmetros do RSI, um com período de 7 e limite de 25, o outro com período de 14 e limite de 25.

A estratégia primeiro calcula os valores dos dois indicadores do RSI, depois julga se o preço quebra o limite superior ou inferior do RSI. Se ele quebra o limite superior, um sinal longo é gerado. Se ele quebra o limite inferior, um sinal curto é gerado.

Se já tiver uma posição, ele continua a julgar se o RSI atual está dentro da faixa normal.

A estratégia também usa o sistema Martingale. O tamanho da ordem duplica após cada perda.

Análise das vantagens

  • O uso de dois indicadores RSI pode avaliar melhor os sinais de ruptura e evitar falsos sinais.

  • Além disso, a verificação do avanço do corpo evita trocas erradas durante a consolidação.

  • Martingale ajuda a parar a perda rapidamente após as perdas.

  • Parâmetros de RSI personalizáveis otimizam as oportunidades de entrada.

  • As sessões de negociação podem ser limitadas para evitar o impacto de grandes eventos.

Análise de riscos

  • O RSI duplo não pode evitar completamente o falso avanço.

  • Martingale aumenta a posição depois de perdas, arrisca-se a explodir.

  • O custo de negociação não é considerado.

  • Muitos parâmetros otimizáveis exigem muitos testes para encontrar a melhor combinação.

Pode definir stop loss para limitar perdas; otimizar parâmetros RSI; adicionar consideração de custos; relaxar critérios de avanço.

Orientações de otimização

  • Adicionar stop loss para limitar a perda máxima.

  • Otimizar os parâmetros do RSI para reduzir os falsos sinais.

  • Considerar o impacto dos custos de negociação para evitar o excesso de negociação.

  • Relaxa os critérios de avanço do corpo para mais oportunidades.

  • Adicione mais filtros para não ficar preso.

Resumo

Esta estratégia usa o RSI duplo para determinar o avanço do preço, adiciona o filtro de avanço do corpo para evitar whipssaws. Também usa a Martingale para cortar rapidamente as perdas. A estratégia pode ser melhorada otimizando parâmetros e adicionando filtros para sinais mais precisos.


/*backtest
start: 2023-10-30 00:00:00
end: 2023-11-06 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Fast RSI Strategy v2.0", shorttitle = "Fast RSI str 2.0", overlay = true)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usemar = input(false, defval = false, title = "Use Martingale")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
usersi1 = input(true, defval = true, title = "Use RSI #1")
rsiperiod1 = input(7, defval = 7, minval = 2, maxval = 50, title = "#1 RSI Period")
rsilimit1 = input(25, defval = 25, minval = 1, maxval = 100, title = "#1 RSI limit")
usersi2 = input(true, defval = true, title = "Use RSI #2")
rsiperiod2 = input(14, defval = 14, minval = 2, maxval = 50, title = "#2 RSI Period")
rsilimit2 = input(25, defval = 25, minval = 1, maxval = 100, title = "#2 RSI limit")
showarr = input(false, defval = false, title = "Show Arrows")
fromyear = input(2018, defval = 2018, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//RSI #1
uprsi1 = rma(max(change(close), 0), rsiperiod1)
dnrsi1 = rma(-min(change(close), 0), rsiperiod1)
rsi1 = dnrsi1 == 0 ? 100 : uprsi1 == 0 ? 0 : 100 - (100 / (1 + uprsi1 / dnrsi1))
uplimit1 = 100 - rsilimit1
dnlimit1 = rsilimit1

//RSI #2
uprsi2 = rma(max(change(close), 0), rsiperiod2)
dnrsi2 = rma(-min(change(close), 0), rsiperiod2)
rsi2 = dnrsi2 == 0 ? 100 : uprsi2 == 0 ? 0 : 100 - (100 / (1 + uprsi2 / dnrsi2))
uplimit2 = 100 - rsilimit2
dnlimit2 = rsilimit2

//Body
body = abs(close - open)
abody = sma(body, 10)

//Signals
bar = close > open ? 1 : close < open ? -1 : 0
up1 = bar == -1 and (strategy.position_size == 0 or close < strategy.position_avg_price) and rsi1 < dnlimit1 and body > abody / 5 and usersi1
dn1 = bar == 1 and (strategy.position_size == 0 or close > strategy.position_avg_price) and rsi1 > uplimit1 and body > abody / 5 and usersi1
up2 = bar == -1 and (strategy.position_size == 0 or close < strategy.position_avg_price) and rsi2 < dnlimit2 and body > abody / 5 and usersi2
dn2 = bar == 1 and (strategy.position_size == 0 or close > strategy.position_avg_price) and rsi2 > uplimit2 and body > abody / 5 and usersi2
norma = rsi1 > dnlimit1 and rsi1 < uplimit1 and rsi2 > dnlimit2 and rsi2 < uplimit2
exit = (((strategy.position_size > 0 and bar == 1 and norma) or (strategy.position_size < 0 and bar == -1 and norma)) and body > abody / 2)

//Arrows
col = exit ? black : up1 or dn1 ? blue : up2 or dn2 ? red : na
needup = up1 or up2
needdn = dn1 or dn2
needexitup = exit and strategy.position_size < 0
needexitdn = exit and strategy.position_size > 0
plotarrow(showarr and needup ? 1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(showarr and needdn ? -1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(showarr and needexitup ? 1 : na, colorup = black, colordown = black, transp = 0)
plotarrow(showarr and needexitdn ? -1 : na, colorup = black, colordown = black, transp = 0)

//Trading
profit = exit ? ((strategy.position_size > 0 and close > strategy.position_avg_price) or (strategy.position_size < 0 and close < strategy.position_avg_price)) ? 1 : -1 : profit[1]
mult = usemar ? exit ? profit == -1 ? mult[1] * 2 : 1 : mult[1] : 1
lot = strategy.position_size == 0 ? strategy.equity / close * capital / 100 * mult : lot[1]

if up1 or up2
    if strategy.position_size < 0
        strategy.close_all()
        
    strategy.entry("Long", strategy.long, needlong == false ? 0 : lot)

if dn1 or dn2
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot)
    
if  exit
    strategy.close_all()

Mais.