如果最近发生在不久之前,如何跳过事件?
How to skip an Event if recently occurred not too long ago?
无效代码:
Event = Something and SomethingElse and (ta.barssince(Event) > 20)
当然,它不会起作用,因为第一次,Event
布尔变量还没有声明。
也许问题应该是“如何检查一个变量是否被定义”? (我试图找到答案。)
尝试失败(Event
的所有信号消失):
Event = Something and SomethingElse
Event := Something and SomethingElse and (ta.barssince(Event) > 20)
和
Event = false
Event := Something and SomethingElse and (ta.barssince(Event) > 20)
您可以使用 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)
无效代码:
Event = Something and SomethingElse and (ta.barssince(Event) > 20)
当然,它不会起作用,因为第一次,Event
布尔变量还没有声明。
也许问题应该是“如何检查一个变量是否被定义”? (我试图找到答案。)
尝试失败(Event
的所有信号消失):
Event = Something and SomethingElse
Event := Something and SomethingElse and (ta.barssince(Event) > 20)
和
Event = false
Event := Something and SomethingElse and (ta.barssince(Event) > 20)
您可以使用 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)