如何在EMA开放时找到第一个值,SMA
我有图:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在历史栏上,脚本在关闭时执行,因此除了
open
外,从栏的开头开始没有值。您可以随时使用在最后一个栏上计算出的值,例如e [1]
,但这不一定等于在栏的开放式上获得的值,当新的bar打开新的bar时价格与以前的酒吧的收盘价不同,也是因为您不会使用相同的34或14个值来计算MAS。在实时条上,您可以使用
varip
pine Script™V5中引入的变量: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 withE[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: