表单元的条件颜色

发布于 2025-01-26 06:10:21 字数 1419 浏览 2 评论 0 原文

我希望为我的TradingView设置一个参考表。我的目的是比较5个股票股票,即Apple(AAPL),Microsoft(MSFT),Amazon(AMZN),Google(Googl)和Tesla(TSLA)。数据是当前的价格,价格变化(从昨天)和百分比变化。

这是表

https://prnt.sc/xzan3fjjjwuzz

我接下来要做什么是什么,根据正变化或负变化为细胞着色。因此,如果更改是正的,则细胞背景将变为绿色,如果为阴性,则变为红色。

我尝试使用有条件的逻辑,但我遇到了错误:使用了“系列颜色”类型的参数,但期望“系列int” 我搜索了此主题中的stackoverflow中只能找到两个问题:

  1. 将系列整数转换为pinescript中的整数

但是,我无法理解如何将他们的答案与我的案件联系起来。

是我用来计算值的代码段

pr_x2 = request.security(x1,"D", close[1])
pr_x1 = request.security(x1,"", close)
pr_diff = (pr_x1 - pr_x2)
pr_pct = truncate(((pr_diff1/pr_x2)*100),2)

这 pr_x2->前一天关闭 pr -x1 - >当前价值

我正在尝试将此条件用于单元格中的背景:

table.cell(panel, 0, 1, str.tostring(pr_diff) + "\nChg: " + str.tostring(pr_pct1) + " %", bgcolor = (pr_diff>0)?color.green:color.red, text_color=color.white)

但是后来我得到了上面提到的错误。

我在讨论论坛中读到,将系列整数转换为Pinescript中的整数。我的案子有解决方法吗?

I am looking to have a reference table of sorts for my tradingview set up. My aim is to compare 5 stock tickers, namely apple(AAPL), microsoft(MSFT), Amazon(AMZN), Google(GOOGL) and Tesla(TSLA). The data is current price, price change(from yesterday's) and percentage change.

Here is the screengrab of the table

https://prnt.sc/XzaN3fJjwuZz

What I am doing to do next is to color the cells based on the positive or negative changes. So if a change has been positive, the cell background becomes green, if negative, then red.

I tried using conditional logic but I am getting error: An argument of 'series color' type was used but a 'series int' is expected
I searched and could find only two questions in stackoverflow on this topic:

  1. pine script error- An argument of 'series string' type was used but a 'const string' is expected
  2. Converting series integer to integer in pinescript

However, I was not able to understand as to how to relate their answers to my case.

Here is the code snippet I am using to calculate the values:

pr_x2 = request.security(x1,"D", close[1])
pr_x1 = request.security(x1,"", close)
pr_diff = (pr_x1 - pr_x2)
pr_pct = truncate(((pr_diff1/pr_x2)*100),2)

where
pr_x2 -> previous day close
pr-x1 -> current value

I'm trying to use this condition for background in the cell:

table.cell(panel, 0, 1, str.tostring(pr_diff) + "\nChg: " + str.tostring(pr_pct1) + " %", bgcolor = (pr_diff>0)?color.green:color.red, text_color=color.white)

but then I get the error I have mentioned above.

I read in the discussions forum that converting series integer to integer in pinescript cannot be done. Is there a workaround for my case?

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

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

发布评论

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

评论(1

风吹短裙飘 2025-02-02 06:10:21

您正在尝试在单元格上,尝试在数组上应用。

var = array.get(id) conditions ? Color.green : 
      array.get(id) conditions? Color.red

You are trying on the cell, try applying on the array.

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