如果不久前发生,如何跳过活动?

发布于 2025-01-27 21:31:36 字数 503 浏览 2 评论 0原文

不工作的代码:

Event = Something and SomethingElse and (ta.barssince(Event) > 20)

当然,它行不通,因为第一次尚未声明event boolean变量。

也许问题应该是“ 如何检查变量是否定义”? (我试图找到答案。)

尝试失败(事件的所有信号消失了):

Event = Something and SomethingElse
Event := Something and SomethingElse and (ta.barssince(Event) > 20)

Event = false
Event := Something and SomethingElse and (ta.barssince(Event) > 20)

The not-working code:

Event = Something and SomethingElse and (ta.barssince(Event) > 20)

Of course, it won't work because at first time, the Event boolean variable is not declared yet.

Perhaps the question should be "How to check whether a variable is defined or not"? (I have tried to find the answer.)

Failed attempts (all the signals of the Event disappear):

Event = Something and SomethingElse
Event := Something and SomethingElse and (ta.barssince(Event) > 20)

and

Event = false
Event := Something and SomethingElse and (ta.barssince(Event) > 20)

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

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

发布评论

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

评论(1

水波映月 2025-02-03 21:31:36

您可以使用var计数器。当您的事件发生并增加否则,将其重置。

// 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", overlay=true)

n = input(2)

var bars_since_last_event = 0

is_green = (close > open) and (bars_since_last_event >= n)
bars_since_last_event := is_green ? 0 : bars_since_last_event + 1

plotshape(is_green)

You can use a var counter. Reset it when your event takes place and increase it otherwise.

// 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", overlay=true)

n = input(2)

var bars_since_last_event = 0

is_green = (close > open) and (bars_since_last_event >= n)
bars_since_last_event := is_green ? 0 : bars_since_last_event + 1

plotshape(is_green)

enter image description here

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