Estratégia de negociação de rastreamento de sinal perdido com base no RSI reverso


Data de criação: 2023-09-28 10:54:24 última modificação: 2023-09-28 10:54:24
cópia: 1 Cliques: 693
1
focar em
1617
Seguidores

Visão geral

Esta estratégia permite a realização de reversão de negociação através da busca de um sinal de overbought/oversold que foi perdido pelo RSI. Quando o RSI retrocede da área de overbought, ele gera um sinal de tracking do plus, e quando a área de overbought rebota, ele gera um sinal de tracking do zero para capturar a oportunidade de reversão.

Princípio da estratégia

- O sinal está definido.

O indicador RSI é usado para julgar o excesso de compra e venda. Quando o RSI cruza a linha de compra e venda definida, é um sinal de compra e venda, e quando o RSI cruza a linha de venda e venda.

overbought = rsi > uplimit 
oversold = rsi < dnlimit

Se um indicador anterior do K-line RSI estiver em um estado de sobrecompra, o indicador atual do K-line RSI sairá do estado de sobrecompra, gerando um sinal de seguimento do dólarup1Se um indicador anterior do K-line RSI estiver em oversold, o indicador atual do K-line RSI sairá do oversold, gerando um sinal de tracking shortdn1

up1 = bar == -1 and strategy.position_size == 0 and overbought[1] and overbought == false
dn1 = bar == 1 and strategy.position_size == 0 and oversold[1] and oversold == false 

Sair do julgamento

Um sinal de saída é gerado quando a direção da posição coincide com a direção da entidade na linha K e a entidade ultrapassa metade de sua média de 10 ciclos.

exit = (((strategy.position_size > 0 and bar == 1) or 
         (strategy.position_size < 0 and bar == -1)) and 
        body > abody / 2)

Vantagens estratégicas

  1. Seguir os sinais de inversão que o RSI perdeu para evitar a necessidade de capturar os pontos de sobrevenda e sobrecompra em tempo hábil.

  2. O indicador RSI usa a sua característica de inversão para capturar oportunidades de inversão.

  3. Para o julgamento de saída em combinação com a direção e o tamanho da entidade da linha K, evite o rastreamento após o rebote.

Riscos e soluções

  1. Risco de falsos sinais no RSI

    • Solução: Confirmar em combinação com outros indicadores para evitar erros.
  2. Quando se segue um sinal, o preço pode ter sofrido uma certa correção e o risco de perdas é grande.

    • Solução: reduzir a posição de entrada ou otimizar o tempo de entrada.
  3. A reversão parcial não pode ser lucrativa e corre o risco de emitir sinais de saída.

    • Solução: otimizar a lógica de decisão de saída e aumentar as chances de lucro das posições.

Otimização de ideias

  1. Parâmetros de otimização são definidos, como linha de compra e venda excessiva, ciclo de revisão, etc., ajustados para diferentes mercados.

  2. Ajustar o modo de gestão de posições, como a redução de posições no rastreamento de sinais.

  3. Otimizar o tempo de entrada, adicionando outras restrições baseadas em sinais de rastreamento.

  4. Otimizar as formas de saída para aumentar a probabilidade de lucro, como a introdução de paradas móveis.

  5. Optimizar a forma de parar e reduzir o risco de perdas, como a introdução de parar móvel, parar orifício, etc.

Resumir

Esta estratégia é baseada em um indicador RSI de overbought e oversold para conseguir um retorno de negociação. A estratégia tem a vantagem de seguir um sinal de retorno, mas também existe um certo risco de falso sinal e risco de perda. Com a otimização contínua, a estabilidade e a taxa de retorno da estratégia podem ser melhoradas.

Código-fonte da estratégia
/*backtest
start: 2023-09-20 00:00:00
end: 2023-09-27 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Anti RSI Strategy v1.0", shorttitle = "Anti RSI str 1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//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, %")
rsiperiod1 = input(14, defval = 14, minval = 2, maxval = 50, title = "RSI Period")
rsilimit1 = input(25, defval = 25, minval = 1, maxval = 100, title = "RSI limit")
showarr = input(false, defval = false, title = "Show Arrows")
fromyear = input(1900, defval = 1900, 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
uprsi1 = rma(max(change(close), 0), rsiperiod1)
dnrsi1 = rma(-min(change(close), 0), rsiperiod1)
rsi = dnrsi1 == 0 ? 100 : uprsi1 == 0 ? 0 : 100 - (100 / (1 + uprsi1 / dnrsi1))
uplimit = 100 - rsilimit1
dnlimit = rsilimit1

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

//Signals
bar = close > open ? 1 : close < open ? -1 : 0
overbought = rsi > uplimit
oversold = rsi < dnlimit

up1 = bar == -1 and strategy.position_size == 0 and overbought[1] and overbought == false
dn1 = bar == 1 and strategy.position_size == 0 and oversold[1] and oversold == false
up2 = bar == -1 and strategy.position_size > 0 and overbought == false
dn2 = bar == 1 and strategy.position_size < 0 and oversold == false

norma = overbought == false and oversold == false
exit = (((strategy.position_size > 0 and bar == 1) or (strategy.position_size < 0 and bar == -1)) and body > abody / 2)

//Arrows
col = exit ? black : up1 or dn1 or up2 or dn2 ? blue : 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, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

if dn1 or dn2
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    
if time > timestamp(toyear, tomonth, today, 23, 59) or exit
    strategy.close_all()