松文字?理解

发布于 2025-01-27 14:04:20 字数 336 浏览 2 评论 0 原文

有人可以确认我正在正确阅读本文,因为我对pinescript的新手很陌生,

vcolor= Oo > Cc ? color.red : up > down? color.green:color.red 

这本质上是确定颜色的陈述吗?

因此,我的理解是

if its Oo > Cc 
    vcolor = red
else if up > down 
    vcolor = green

最后的颜色是什么意思。为什么如果这是含义的话,为什么要在if语句中使用它?

提前致谢

Could someone confirm I am reading this correctly as I am quite new to pinescript

vcolor= Oo > Cc ? color.red : up > down? color.green:color.red 

Is this essentially an if statement to determine color?

So my understanding would be

if its Oo > Cc 
    vcolor = red
else if up > down 
    vcolor = green

What does the last color.red mean and why would you use this over an if statement if that's what it means?

Thanks in advance

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

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

发布评论

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

评论(1

小镇女孩 2025-02-03 14:04:20

?:被称为

您可以将该语句写为:

vcolor = if (Oo > Cc)
    color.red
else if (up > down)
    color.green
else
    color.red

因此,最后一个 color.red 是如果这些语句都不是 true

至于为什么您可能想使用此功能只是个人喜好。我喜欢它,因为它允许我一行写下这些陈述。

?: is called Ternary operator.

You can write that statement as:

vcolor = if (Oo > Cc)
    color.red
else if (up > down)
    color.green
else
    color.red

So, the last color.red is if none of those statements are true.

As to why you may want to use this is just personal preference. I personnaly like it because it allows me to write those statements in one line.

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