Pine script 您能否使用pine脚本来提醒您,某个指标在几个月内首次超过了某个级别?

Pine script 您能否使用pine脚本来提醒您,某个指标在几个月内首次超过了某个级别?,pine-script,moving-average,trading,back-testing,Pine Script,Moving Average,Trading,Back Testing,因此,我试图写一个脚本,当威廉姆斯%r的sma超过-20或低于-80时,可以提醒我,这是一个月来的第一次。 这在pinescript中可能吗 提前感谢。虽然我了解您想要设计的是什么,所以我对移动平均交叉也做了同样的事情,但您可以看到红色背景,它显示了给定时间范围内的第一个交叉 您可以在设置中更改时间,输入以下代码 “ISTIMECHAGED”是不断跟踪变化的变量 // This source code is subject to the terms of the Mozilla Public

因此,我试图写一个脚本,当威廉姆斯%r的sma超过-20或低于-80时,可以提醒我,这是一个月来的第一次。 这在pinescript中可能吗


提前感谢。

虽然我了解您想要设计的是什么,所以我对移动平均交叉也做了同样的事情,但您可以看到红色背景,它显示了给定时间范围内的第一个交叉

您可以在设置中更改时间,输入以下代码

“ISTIMECHAGED”是不断跟踪变化的变量

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

//@version=4
study("1st time crossover alert in given time",overlay=true)

fastMA = sma(close, 10)
slowMA = sma(close, 50)

plot(fastMA,color=color.red)
plot(slowMA)

time_input=input("W",type=input.resolution)

isTimeChanged = false
isTimeChanged := nz(isTimeChanged[1], false)

if(change(time(time_input)) and not nz(isTimeChanged[1]))
    isTimeChanged := true
if crossover(fastMA,slowMA) and nz(isTimeChanged[1])
    isTimeChanged := false

bgcolor(not isTimeChanged and isTimeChanged[1]?color.red:na,transp=10)
alertcondition(not isTimeChanged and isTimeChanged[1],title = "crossover happened first time")