繁体   English   中英

满足条件时指示器中的背景颜色

[英]Background color in indicator when conditions are met

当此指标满足某些条件时,我一直在尝试添加背景 colors,该指标结合了 Walter Bresserts 双随机指标和 RSI。

我希望背景颜色在满足“长”条件时变为绿色,在满足“短”条件时变为红色:

long = ((rsi < 15 或 rsi[1] < 15 或 rsi[2] < 15) 和 (dds10 < 25))

短 = ((rsi > 85 或 rsi[1] > 85 或 rsi[2] > 85) 和 (dds10 > 85))

这里有人知道该怎么做吗?

提前致谢, 菲利普

//@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)

您可以在代码末尾添加类似的内容。 它使用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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM