簡體   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