PineScript:基于输入的条形颜色

发布于 2025-01-19 15:05:27 字数 539 浏览 2 评论 0原文

完整的新手寻求帮助。

目前,我使用简单的代码为条上色。

barclr = input(false, title='(Off) Color2 or (On) Color1')
barcolor(barclr ? barcolor2 : barcolor1)

我现在只想在另一个切换说“是”时才为bar上色,

bar = input.string("Yes", title="Colored Bars", options=["Yes", "No"]) == "Yes" 

所以我想发生的事情是当bar下拉设置为“是” 然后颜色条,否则根本不着色。

另外,bar ==“是”然后使用barclr在两个选项之间切换。

(如果是一个切换或下拉列表,我不偏爱它,但仅仅是因为我尝试使用下拉菜单的差异化感。)

我不知道如何将其放在一起。请帮忙。

Complete newbie looking for help.

Currently I color my bars using a simple code.

barclr = input(false, title='(Off) Color2 or (On) Color1')
barcolor(barclr ? barcolor2 : barcolor1)

I now want to color bars only if another toggle says "Yes" and so I created,

bar = input.string("Yes", title="Colored Bars", options=["Yes", "No"]) == "Yes" 

So now what I want to happen is when the bar dropdown is set to "Yes" then color bars otherwise don't color bars at all.

Also while bar == "Yes" then use barclr to switch between two options.

(I don't have a preference if it's a toggle or dropdown but just for my limited sense of differentiation I tried using a dropdown.)

I don't know how to put this together. Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒七 2025-01-26 15:05:27

您几乎已经完成了一个目标,为 bar 输入添加新的三元检查,并将现有的三元条件嵌套在 barcolor() 函数中:

//@version=5
indicator("My script")

bar = input.string("Yes", title="Colored Bars", options=["Yes", "No"])
barclr = input(false, title='(Off) Color2 or (On) Color1')

barcolor1 = color.red
barcolor2 = color.green

barcolor(bar == "Yes" ? barclr ? barcolor1 : barcolor2 : na)

You have almost accomplished a goal, add a new ternary check for the bar input and nest the existing ternary condition inside barcolor() function:

//@version=5
indicator("My script")

bar = input.string("Yes", title="Colored Bars", options=["Yes", "No"])
barclr = input(false, title='(Off) Color2 or (On) Color1')

barcolor1 = color.red
barcolor2 = color.green

barcolor(bar == "Yes" ? barclr ? barcolor1 : barcolor2 : na)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文