查找过去几支蜡烛中是否越过移动平均

发布于 2025-01-19 05:04:21 字数 590 浏览 1 评论 0原文

目前我手动交易并使用交易量作为额外的汇合。如果过去的几个成交量柱中的任何一个超过了移动平均线,并且同时(长时间)形成了一根红色蜡烛,那么这是一个积极的信号。

我正在尝试在 pinescript 中重新创建它,但它没有做我希望的事情

这就是我到目前为止所拥有的:

volume_cross(lookbackLength, maLength) =>
    for offset = 0 to lookbackLength - 1
        volumeMa=ta.sma(volume[offset],maLength)
        if ta.crossover(volumeMa,volume[offset]) and close[offset]<open[offset]
            true

plotchar(volume_cross(5,20), title="volume_cross")

我是 pinescript 的新手,我之前没有编写过函数,甚至没有编写过循环!

它不仅没有做我希望的事情,而且我收到警告,应该在每次计算时调用 ta 函数,所以我认为有更好的方法来做到这一点

任何帮助将不胜感激

Currently I trade manually and use volume as an extra confluence. If any of the past few volume bars have gone over the moving average and at the same time (for a long) printed a red candle then that's a positive.

I'm trying to recreate this in pinescript, but it's not doing what i'd hope

This is what I have so far:

volume_cross(lookbackLength, maLength) =>
    for offset = 0 to lookbackLength - 1
        volumeMa=ta.sma(volume[offset],maLength)
        if ta.crossover(volumeMa,volume[offset]) and close[offset]<open[offset]
            true

plotchar(volume_cross(5,20), title="volume_cross")

I'm new to pinescript and i've not written a function or even a loop in this before!

Not only is it not doing what I hope but i'm getting warnings that the ta functions should be called on each calculation, so I assume there's a better way to do this

Any help would be appreciated

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

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

发布评论

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

评论(1

带刺的爱情 2025-01-26 05:04:21

您可以使用ta.barss()来弄清楚自音量平均移动平均值以来的最后一次。

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius

//@version=5
indicator("My script")

vol_ema = ta.ema(volume, 20)
vol_ema_cross = ta.crossover(volume, vol_ema)
bars_since_cross = ta.barssince(vol_ema_cross)
plot(bars_since_cross)

You can use ta.barssince() to figure out when was the last time since volume has crossed moving average.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius

//@version=5
indicator("My script")

vol_ema = ta.ema(volume, 20)
vol_ema_cross = ta.crossover(volume, vol_ema)
bars_since_cross = ta.barssince(vol_ema_cross)
plot(bars_since_cross)

enter image description here

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