如何检查大于当前时间范围的一个时间范围内的移动平均线

发布于 2025-01-13 06:28:30 字数 132 浏览 1 评论 0原文

我想检查 pine 脚本中大于当前图表时间范围的一个时间范围内的移动平均线 例如,如果图表在 m15 上,我想检查 m30 上的移动平均线,如果图表在 h1 上,则检查 h2 等等 它以某种方式自动获取当前图表时间范围并绘制大 1 个时间范围的 ma

I want to check moving averages on one time frame greater than the current chart time frame in pine script
For example if chart is on m15 I want to check moving averages on m30 if chart is on h1 it check on h2 and so on
Somehow it get current chart time frame automatically and plot ma for 1 time frame greater

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

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

发布评论

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

评论(1

遗弃M 2025-01-20 06:28:30

security() 函数就是您所需要的正在寻找。

//@version=4
study(title="High Time Frame MA", overlay=true)
src = close, len = 9
out = sma(src, len)
out1 = security(syminfo.tickerid, '30', out)
plot(out1)

编辑

没有下一个上限时间范围。时间范围可以是任何东西。 Tradingview 列出的是一些方便的值。

例如,您可以获取当前时间范围(以分钟为单位),并从 2 * 当前时间范围 请求数据。

//@version=5
indicator(title="High Time Frame MA", overlay=true)

f_resInMinutes() => 
    _resInMinutes = timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)

curr_tf_in_min = f_resInMinutes()
tf_2 = str.tostring(2 * curr_tf_in_min)
src = close, len = 9
out = ta.sma(src, len)
out1 = request.security(syminfo.tickerid, tf_2, out)
plot(out1)

The security() function is what you are looking for.

//@version=4
study(title="High Time Frame MA", overlay=true)
src = close, len = 9
out = sma(src, len)
out1 = security(syminfo.tickerid, '30', out)
plot(out1)

Edit

There is no next upper timeframe. Timeframe can be anything. What Tradingview lists are some convenient values.

You can get the current timeframe in minutes, and request data from 2 * current timeframe for example.

//@version=5
indicator(title="High Time Frame MA", overlay=true)

f_resInMinutes() => 
    _resInMinutes = timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)

curr_tf_in_min = f_resInMinutes()
tf_2 = str.tostring(2 * curr_tf_in_min)
src = close, len = 9
out = ta.sma(src, len)
out1 = request.security(syminfo.tickerid, tf_2, out)
plot(out1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文