//@version=4 strategy("Estrategia Bollinger Bands + RSI", overlay=true) // Parámetros de las Bandas de Bollinger length = input(20, minval=1, title="Longitud") mult = input(2.0, minval=0.1, title="Multiplicador") // Cálculo de las Bandas de Bollinger smaValue = sma(close, length) stdDev = mult * stdev(close, length) upperBand = smaValue + stdDev lowerBand = smaValue - stdDev // Parámetros del RSI rsiLength = input(14, minval=1, title="Longitud RSI") overbought = input(70, title="Sobrecompra") oversold = input(30, title="Sobreventa") // Cálculo del RSI rsiValue = rsi(close, rsiLength) // Señales de entrada y salida enterLong = crossover(close, upperBand) and rsiValue < oversold enterShort = crossunder(close, lowerBand) and rsiValue > overbought exitLong = crossunder(close, smaValue) exitShort = crossover(close, smaValue) // Colores de las Bandas de Bollinger bandColor = enterLong ? color.green : enterShort ? color.red : color.blue // Dibujo de las Bandas de Bollinger plot(upperBand, color=bandColor, title="Banda Superior", linewidth=2) plot(lowerBand, color=bandColor, title="Banda Inferior", linewidth=2) // Dibujo del RSI plot(rsiValue, color=color.orange, title="RSI", linewidth=2) // Condiciones de entrada y salida if (enterLong) strategy.entry("Long", strategy.long) if (enterShort) strategy.entry("Short", strategy.short) if (exitLong) strategy.close("Long") if (exitShort) strategy.close("Short")