Estratégia ADX + RSI


Data de criação: 2023-09-27 16:27:39 última modificação: 2023-09-27 16:27:39
cópia: 0 Cliques: 2077
1
focar em
1617
Seguidores

Visão geral

É uma estratégia de acompanhamento de tendências que combina os indicadores ADX e RSI. A estratégia usa o RSI para determinar os casos de sobrevenda e sobrevenda para emitir sinais de negociação, enquanto o ADX é usado para determinar a tendência do mercado e filtrar as negociações que não são evidentes, evitando efetivamente o colapso do mercado.

Princípio da estratégia

  1. O RSI de 7 ciclos é usado para determinar o excesso de compra e venda.
  • RSI abaixo de 30 é considerado um oversold
  • RSI acima de 70 é considerado supercomprado
  1. Usando o ADX para julgar tendências
  • ADX acima de 30 mostra tendência
  • ADX abaixo de 30 significa que a tendência não é visível
  1. Regras de entrada
  • Faça mais quando o RSI estiver abaixo de 30 e o ADX estiver acima de 30
  • Faça um short quando o RSI for superior a 70 e o ADX for superior a 30
  1. Parar de perder
  • Há uma opção de parada de parada, que pode ser selecionado para encerrar a parada de parada ou parada de parada de vibração
  • O método de parada de liquidação é baseado no preço de liquidação
  • O padrão de stop loss de oscilação é baseado no ponto mais alto ou mais baixo de uma flutuação de preço recente.

Análise de vantagens

  1. O RSI é um indicador eficaz para determinar pontos de sobrevenda e de sobrecompra, reduzindo as armadilhas de compra e venda.

  2. O ADX pode filtrar situações que não são claramente tendências, evitando ficar preso em situações de turbulência

  3. Opções de Stop Loss para um melhor controlo de riscos

  4. A estratégia é simples, clara, fácil de entender e apropriada para quem está começando.

  5. Optimizar os parâmetros da estratégia é amplo e pode ser feito ajustando os parâmetros do ciclo RSI, intervalo de sobrevenda e sobrevenda e ciclo de alinhamento do ADX.

Análise de Riscos

  1. Risco de retração do RSI, com sinais de sobrevenda e sobrevenda

  2. O ADX considera que a tendência está atrasada e pode ter perdido o ponto de viragem

  3. Estabelecer um ponto de parada irracional pode levar a perdas

  4. A estratégia é simples, com risco de otimização

  5. Optimização de parâmetros necessária para melhor efeito

Direção de otimização

  1. Para otimizar os parâmetros do RSI, ajustar o intervalo de sobrevenda e sobrevenda e encontrar a melhor combinação de parâmetros

  2. Teste o ADX em diferentes períodos para encontrar os melhores parâmetros para determinar a tendência

  3. Teste diferentes métodos de stop loss para encontrar a configuração mais adequada para a estratégia

  4. Pode ser adicionado um indicador de filtragem de tendências para evitar negociações contra-correntes

  5. Pode ser combinado com outros indicadores para tornar a estratégia mais eficaz

Resumir

Esta estratégia integra os benefícios dos dois indicadores clássicos RSI e ADX, para detectar tendências e evitar oscilações. É uma estratégia de acompanhamento de tendências simples e prática.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tweakerID

// This is a strategy that uses the 7 Period RSI to buy when the indicator is shown as oversold (OS) and sells when 
// the index marks overbought (OB). It also uses the ADX to determine whether the trend is ranging or trending
// and filters out the trending trades. Seems to work better for automated trading when the logic is inversed (buying OB 
// and selling the OS) wihout stop loss.

//@version=4
strategy("ADX + RSI Strat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value=0.04, calc_on_every_tick=false)

direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))


//SL & TP Inputs
i_SL=input(false, title="Use Swing Lo/Hi Stop Loss & Take Profit")
i_SwingLookback=input(20, title="Swing Lo/Hi Lookback")
i_SLExpander=input(defval=0, step=.2, title="SL Expander")
i_TPExpander=input(defval=0, step=.2, title="TP Expander")
i_reverse=input(true, title="Reverse Trades")

//SL & TP Calculations
SwingLow=lowest(i_SwingLookback)
SwingHigh=highest(i_SwingLookback)
bought=strategy.position_size != strategy.position_size[1]
LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0))*i_SLExpander)
SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0))*i_SLExpander)
lTP=strategy.position_avg_price + (strategy.position_avg_price-(valuewhen(bought, SwingLow, 0))+((valuewhen(bought, atr(14), 0))*i_TPExpander))
sTP=strategy.position_avg_price - (valuewhen(bought, SwingHigh, 0)-strategy.position_avg_price)-((valuewhen(bought, atr(14), 0))*i_TPExpander)
islong=strategy.position_size > 0
isshort=strategy.position_size < 0
SL= islong ? LSL : isshort ? SSL : na
TP= islong ? lTP : isshort ? sTP : na

//RSI Calculations
RSI=rsi(close, 7)
OS=input(30, step=5)
OB=input(80, step=5)

//ADX Calculations
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
	up = change(high)
	down = -change(low)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
	truerange = rma(tr, len)
	plus = fixnan(100 * rma(plusDM, len) / truerange)
	minus = fixnan(100 * rma(minusDM, len) / truerange)
	[plus, minus]
adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
adxlevel=input(30, step=5)


//Entry Logic
BUY = sig < adxlevel and (RSI < OS) 
SELL = sig < adxlevel and (RSI > OB) 

//Entries
strategy.entry("long", strategy.long, when=i_reverse?SELL:BUY)
strategy.entry("short", strategy.short, when=not i_reverse?SELL:BUY)
//Exits
if i_SL
    strategy.exit("longexit", "long", stop=SL, limit=TP)
    strategy.exit("shortexit", "short", stop=SL, limit=TP)

//Plots
plot(i_SL ? SL : na, color=color.red, style=plot.style_cross, title="SL")
plot(i_SL ? TP : na, color=color.green, style=plot.style_cross, title="TP")
plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.green, title="Bullish Setup")
plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup")