//@version=5
strategy("Estrategia Bandas de Bollinger", overlay=true)// Parámetros de las Bandas de Bollinger
length = input(20, "Longitud")
mult = input(2.0, "Multiplicador")
// Cálculo de las Bandas de Bollinger
sma = ta.sma(close, length)
stddev = ta.stdev(close, length)
upperBand = sma + mult * stddev
lowerBand = sma - mult * stddev
// Señales de entrada y salida
enterLong = ta.crossover(close, upperBand)
exitLong = ta.crossunder(close, sma) or ta.crossunder(close, lowerBand)
// Estrategia
strategy.entry("Long", strategy.long, when=enterLong)
strategy.close("Long", when=exitLong)
//@version=5 MODIFICADO
strategy("Estrategia Bandas de Bollinger", overlay=true)
// Parámetros de las Bandas de Bollinger
length = input(20, "Longitud")
mult = input(2.0, "Multiplicador")
// Cálculo de las Bandas de Bollinger
sma = ta.sma(close, length)
stddev = ta.stdev(close, length)
upperBand = sma + mult * stddev
lowerBand = sma - mult * stddev
// Señales de entrada y salida
enterLong = ta.crossover(close, upperBand)
exitLong = ta.crossunder(close, sma) or ta.crossunder(close, lowerBand)
// Estrategia
strategy.entry("Long", strategy.long, when=enterLong)
strategy.close("Long", when=exitLong)
//@version=5 NO FUNCIONA
strategy("Estrategia Bollinger y RSI", overlay=true)
// Parámetros de las Bandas de Bollinger
length = input(20, "Longitud")
mult = input(2.0, "Multiplicador")
// Parámetros del RSI
rsiLength = input(14, "Longitud del RSI")
rsiOversold = input(30, "Nivel de sobreventa del RSI")
rsiOverbought = input(70, "Nivel de sobrecompra del RSI")
// Cálculo de las Bandas de Bollinger
sma = ta.sma(close, length)
stdDev = ta.stdev(close, length)
upperBand = sma + mult * stdDev
lowerBand = sma - mult * stdDev
// Cálculo del RSI
rsi = ta.rsi(close, rsiLength)
// Condiciones de entrada y salida
longCondition = ta.crossover(close, upperBand) and rsi < rsiOversold
shortCondition = ta.crossunder(close, lowerBand) and rsi > rsiOverbought
exitCondition = ta.crossover(close, sma)
// Señales de entrada y salida
strategy.entry("Buy", strategy.long, when=longCondition)
strategy.entry("Sell", strategy.short, when=shortCondition)
strategy.exit("Exit", "Buy", when=exitCondition)
strategy.exit("Exit", "Sell", when=exitCondition)