PINE脚本:添加两个股票音量值

发布于 2025-01-20 19:18:14 字数 624 浏览 2 评论 0原文

我正在尝试计算两只股票的总成交量并绘制它。其中一只于 2022 年开始交易,另一只于 2021 年开始交易。我注意到情节从 2022 年开始,跳过了 2021 年第一支股票的交易量。

indicator("tasi_p1", overlay=false,format=format.volume)

src  = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)

src := src + 
 request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)

palette = close[1] > close ? color.red : color.green

plot(src,style=plot.style_histogram,color = palette)

我的主要目标是绘制相关股票组/行业的交易量并将其用于我的策略。

另外,我注意到在 TradingView 中添加股票代码(例如“4164 + 2082”)时,TradingView 中也有相同的行为,它会跳过 2021 年部分,甚至在蜡烛图中。

有错误还是我遗漏了什么?

I am trying to take the total volume of two stocks and plot it. One of them started trading in 2022 and the other in 2021. I noticed the plot starts from 2022 skipping the volume for first stock in 2021.

indicator("tasi_p1", overlay=false,format=format.volume)

src  = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)

src := src + 
 request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)

palette = close[1] > close ? color.red : color.green

plot(src,style=plot.style_histogram,color = palette)

My main goal is to plot the volume of group/sector of related stocks and use it in my strategy.

Also, I noticed same behavior in TradingView when adding the stock symbols in Symbol Search text field like "4164 + 2082" it skips 2021 part even the in candle chart.

Is there a bug or am I missing something?

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

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

发布评论

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

评论(1

笑梦风尘 2025-01-27 19:18:14

嗯,因为 4164 将在开始交易之前返回 NaN 作为其交易量。然后您尝试在计算中使用此 NaN 值,但您不应该这样做。

将您的 src 包装到 nz() 中,它将用零替换 NaN

//@version=5
indicator("tasi_p1", overlay=false,format=format.volume)

src  = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)

src := nz(src) + 
 request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)

palette = close[1] > close ? color.red : color.green

plot(src,style=plot.style_histogram,color = palette)

Well, because 4164 will return NaN as its volume before it started trading. Then you are trying to use this NaN value in your calculations which you shouldn't do.

Wrap your src into nz() and it will replace NaN with zeros.

//@version=5
indicator("tasi_p1", overlay=false,format=format.volume)

src  = request.security("TADAWUL:4164",timeframe.period,volume, barmerge.gaps_off)

src := nz(src) + 
 request.security("TADAWUL:2082",timeframe.period,volume, barmerge.gaps_off)

palette = close[1] > close ? color.red : color.green

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