Estratégia de negociação de reversão de impulso

Autora:ChaoZhang
Tags:

img

Resumo

Estratégia lógica

Análise das vantagens

  • Mostrar a variação percentual desde o último sinal para avaliar a eficácia das reversões
  • Pode ser utilizado isoladamente ou em combinação com outros indicadores para melhorar a estratégia

Análise de riscos

  • Continuidade insuficiente da tendência após a inversão, poderiam ser correcções de curto prazo

Orientações de otimização

  • Adicionar stop loss para controlar a perda de uma única transação
  • Adicionar gestão de posições para crescimento exponencial de posições rentáveis

Resumo


/*backtest
start: 2023-01-19 00:00:00
end: 2024-01-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Improved RSI Strategy", overlay=true)

// Define RSI parameters
rsiLength = input(14, title="RSI Length")
rsiOversold = input(30, title="Oversold Threshold")
rsiOverbought = input(70, title="Overbought Threshold")

// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)

// Define entry conditions
longCondition = ta.crossover(rsiValue, rsiOversold)
shortCondition = ta.crossunder(rsiValue, rsiOverbought)

// Plot RSI and thresholds
plot(rsiValue, title="RSI", color=color.blue)
hline(rsiOversold, title="Oversold Threshold", color=color.red)
hline(rsiOverbought, title="Overbought Threshold", color=color.green)

// Calculate percentage change since last signal
var float percentageChange = na
lastCloseValue = ta.valuewhen(longCondition or shortCondition, close, 1)

if longCondition or shortCondition
    percentageChange := (close - lastCloseValue) / lastCloseValue * 100

plot(percentageChange, color=color.blue, style=plot.style_histogram, linewidth=1, title="% Change since last signal")

// Execute strategy
if longCondition
    strategy.entry("RSI Long", strategy.long)
    
if shortCondition
    strategy.entry("RSI Short", strategy.short)

// Plot shapes and text for buy/sell signals
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")


Mais.