He estado tratando de agregar colores de fondo cuando se cumplen ciertas condiciones en este indicador que combina el doble estocástico de Walter Bressert y el RSI.
Quiero que el color de fondo se vuelva verde cuando se cumplan las condiciones "largas" y rojo cuando se cumplan las condiciones "cortas":
largo = ((rsi < 15 o rsi[1] < 15 o rsi[2] < 15) y (dds10 < 25))
corto = ((rsi > 85 o rsi[1] > 85 o rsi[2] > 85) y (dds10 > 85))
¿Alguien aquí sabe cómo hacer eso?
Gracias de antemano Felipe
//@version=5
indicator('RSI & DT Bressert')
HighlightBreaches = input(true, title='Highlight Oversold/Overbought?')
period = input.int(defval=13, title='Period', minval=1, maxval=16)
top = 85
bot = 25
len = input.int(2, minval=1, title='Length')
src = input(close, 'Source')
up = ta.rma(math.max(ta.change(src), 0), len)
down = ta.rma(-math.min(ta.change(src), 0), len)
rsi = down == 0? 100: up == 0? 0: 100 - 100 / (1 + up / down)
plot(rsi, 'RSI', color=color.new(#C0C0C0, 0))
period10 = input(title='Periodes', defval=10)
period5 = input(title='Periodes', defval=5)
stochastic10 = ta.ema((close - ta.lowest(low, period10)) / (ta.highest(high, period10) - ta.lowest(low, period10)) * 100, 3)
dds10 = ta.ema((stochastic10 - ta.lowest(stochastic10, period10)) / (ta.highest(stochastic10, period10) - ta.lowest(stochastic10, period10)) * 100, 3)
stochastic5 = ta.ema((close - ta.lowest(low, period5)) / (ta.highest(high, period5) - ta.lowest(low, period5)) * 100, 3)
dds5 = ta.ema((stochastic5 - ta.lowest(stochastic5, period5)) / (ta.highest(stochastic5, period5) - ta.lowest(stochastic5, period5)) * 100, 3)
hline(title='OB', price=top, color=color.black)
hline(title='OS', price=bot, color=color.black)
plot(series=dds10, color=dds10[1] < dds10? color.green: color.red, linewidth=2)
plot(series=dds5, color=dds5[1] < dds5? color.blue: color.navy, linewidth=2)
Solución del problema
Puede agregar algo como esto al final de su código. Utiliza bgcolor()
long = ((rsi < 15 or rsi[1] < 15 or rsi[2] < 15) and (dds10 < 25))
short = ((rsi > 85 or rsi[1] > 85 or rsi[2] > 85) and (dds10 > 85))
bgcolor(long? color.green: short? color.red: na)
No hay comentarios.:
Publicar un comentario