如何在EMA开放时找到第一个值,SMA

发布于 2025-01-23 19:33:20 字数 152 浏览 1 评论 0原文

我有图:

E = ema(close, 34)

S = sma(close, 14)

当第一个关闭==打开时,我想获取上述2行的值(表示栏出现时,在时间范围的第一秒钟出现时)。

我该怎么做。请帮助我写2个功能。

I have the plots:

E = ema(close, 34)

S = sma(close, 14)

I would like to get the value of the 2 above lines when the first close == open (means when the bar appears, at the first second of the timeframe).

How can I do that. Please help me to write 2 functions.

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

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

发布评论

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

评论(1

徒留西风 2025-01-30 19:33:20

在历史栏上,脚本在关闭时执行,因此除了open外,从栏的开头开始没有值。您可以随时使用在最后一个栏上计算出的值,例如e [1],但这不一定等于在栏的开放式上获得的值,当新的bar打开新的bar时价格与以前的酒吧的收盘价不同,也是因为您不会使用相同的34或14个值来计算MAS。

在实时条上,您可以使用 varip pine Script™V5中引入的变量:

//@version=5
indicator("", "", true)
E = ta.ema(close, 34)
S = ta.sma(close, 14)

varip float eAtOpen = na
varip float sAtOpen = na
if barstate.isrealtime and barstate.isnew
    eAtOpen := E
    sAtOpen := S
plot(eAtOpen, "eAtOpen")
plot(sAtOpen, "sAtOpen", color.orange)

“在此处输入图像说明”

On historical bars, scripts execute on the close, so no values from the beginning of the bar are available, other than open. You could always use the values calculated on the last bar's close with E[1] for example, but that would not necessarily be equivalent to a value obtained at the open of the bar, when a new bar opens at a different price than the previous bar's close, and also because of the fact that you would not be using the same 34 or 14 values to calculate your MAs.

On realtime bars, you could achieve what you want using the varip variables introduced in Pine Script™ v5:

//@version=5
indicator("", "", true)
E = ta.ema(close, 34)
S = ta.sma(close, 14)

varip float eAtOpen = na
varip float sAtOpen = na
if barstate.isrealtime and barstate.isnew
    eAtOpen := E
    sAtOpen := S
plot(eAtOpen, "eAtOpen")
plot(sAtOpen, "sAtOpen", color.orange)

enter image description here

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