
La estrategia es un sistema de negociación de retorno al promedio que combina bandas de Bollinger y un indicador relativamente débil, el RSI. La estrategia identifica los extremos en los que los precios se desvían del promedio y combina la señal de venta por encima del RSI para determinar el momento de negociar.
La lógica central de la estrategia se basa en la característica de la regresión de la media de los mercados financieros. En la implementación concreta, se utiliza el promedio móvil simple de 20 días (SMA) como referencia de la media, y se calcula el ancho de banda de Brin con un factor de diferencia estándar de 2.0. Al mismo tiempo, se introduce el RSI de 14 días como indicador auxiliar, estableciendo 70 y 30 como umbrales de sobreventa y sobreventa. La estrategia solo activa una señal de negociación cuando el precio rompe la banda de Brin y el RSI alcanza un máximo.
La estrategia utiliza la sinergia de la banda de Brin y el RSI para construir un sistema de negociación de retorno a la media robusto. La estrategia está diseñada de manera razonable y tiene una buena escalabilidad y adaptabilidad.
/*backtest
start: 2024-11-19 00:00:00
end: 2024-12-18 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Mean Reversion Strategy", overlay=true)
// User Inputs
length = input.int(20, title="SMA Length") // Moving Average length
stdDev = input.float(2.0, title="Standard Deviation Multiplier") // Bollinger Band deviation
rsiLength = input.int(14, title="RSI Length") // RSI calculation length
rsiOverbought = input.int(70, title="RSI Overbought Level") // RSI overbought threshold
rsiOversold = input.int(30, title="RSI Oversold Level") // RSI oversold threshold
// Bollinger Bands
sma = ta.sma(close, length) // Calculate the SMA
stdDevValue = ta.stdev(close, length) // Calculate Standard Deviation
upperBand = sma + stdDev * stdDevValue // Upper Bollinger Band
lowerBand = sma - stdDev * stdDevValue // Lower Bollinger Band
// RSI
rsi = ta.rsi(close, rsiLength) // Calculate RSI
// Plot Bollinger Bands
plot(sma, color=color.orange, title="SMA") // Plot SMA
plot(upperBand, color=color.red, title="Upper Bollinger Band") // Plot Upper Band
plot(lowerBand, color=color.green, title="Lower Bollinger Band") // Plot Lower Band
// Plot RSI Levels (Optional)
hline(rsiOverbought, "Overbought Level", color=color.red, linestyle=hline.style_dotted)
hline(rsiOversold, "Oversold Level", color=color.green, linestyle=hline.style_dotted)
// Buy and Sell Conditions
buyCondition = (close < lowerBand) and (rsi < rsiOversold) // Price below Lower Band and RSI Oversold
sellCondition = (close > upperBand) and (rsi > rsiOverbought) // Price above Upper Band and RSI Overbought
// Execute Strategy
if (buyCondition)
strategy.entry("Buy", strategy.long)
if (sellCondition)
strategy.entry("Sell", strategy.short)
// Optional: Plot Buy/Sell Signals
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")