
A estratégia é um sistema de negociação complexo que combina um índice aleatório relativamente fraco (Stochastic RSI) e um padrão gráfico. O sistema analisa os níveis de sobrecompra e sobrevenda do indicador SRSI, com a confirmação gráfica do movimento dos preços, para a geração de sinais de negociação totalmente automatizados. A estratégia usa um método de combinação de indicadores tecnológicos avançados, que combina as características de acompanhamento de tendências e inversão de negociação, com uma forte adaptabilidade ao mercado.
A lógica central da estratégia é baseada nos seguintes elementos-chave:
A estratégia, combinando o indicador de RSI aleatório e o padrão de gráfico, constrói um sistema de negociação robusto. O sistema, ao mesmo tempo em que mantém a simplicidade de operação, permite um melhor controle de risco. Através de uma otimização razoável de parâmetros e filtragem de sinais, a estratégia é capaz de se adaptar a diferentes ambientes de mercado.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Stochastic RSI Strategy with Candlestick Confirmation", overlay=true)
// Input parameters for Stochastic RSI
rsiPeriod = input.int(14, title="RSI Period")
stochRsiPeriod = input.int(14, title="Stochastic RSI Period")
kPeriod = input.int(3, title="K Period")
dPeriod = input.int(3, title="D Period")
// Overbought and Oversold levels
overboughtLevel = input.int(80, title="Overbought Level", minval=50, maxval=100)
oversoldLevel = input.int(20, title="Oversold Level", minval=0, maxval=50)
// Calculate RSI
rsi = ta.rsi(close, rsiPeriod)
// Calculate Stochastic RSI
stochRSI = ta.stoch(rsi, rsi, rsi, stochRsiPeriod) // Stochastic RSI calculation using the RSI values
// Apply smoothing to StochRSI K and D lines
k = ta.sma(stochRSI, kPeriod)
d = ta.sma(k, dPeriod)
// Plot Stochastic RSI on separate panel
plot(k, title="StochRSI K", color=color.green, linewidth=2)
plot(d, title="StochRSI D", color=color.red, linewidth=2)
hline(overboughtLevel, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed)
// Buy and Sell Signals based on both Stochastic RSI and Candlestick patterns
buySignal = ta.crossover(k, oversoldLevel) and close > open // Buy when K crosses above oversold level and close > open (bullish candle)
sellSignal = ta.crossunder(k, overboughtLevel) and close < open // Sell when K crosses below overbought level and close < open (bearish candle)
// Plot Buy/Sell signals as shapes on the chart
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", size=size.small)
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", size=size.small)
// Background color shading for overbought/oversold conditions
bgcolor(k > overboughtLevel ? color.new(color.red, 90) : na)
bgcolor(k < oversoldLevel ? color.new(color.green, 90) : na)
// Place actual orders with Stochastic RSI + candlestick pattern confirmation
if (buySignal)
strategy.entry("Long", strategy.long)
if (sellSignal)
strategy.entry("Short", strategy.short)
// Optionally, you can add exit conditions for closing long/short positions
// Close long if K crosses above the overbought level
if (ta.crossunder(k, overboughtLevel))
strategy.close("Long")
// Close short if K crosses below the oversold level
if (ta.crossover(k, oversoldLevel))
strategy.close("Short")