Pine script 我试图使用“添加条件”;更改“;功能

Pine script 我试图使用“添加条件”;更改“;功能,pine-script,Pine Script,我试图为购买添加一个条件,条件是CMF应该高于之前的标准 我现在使用的代码在上一个栏较低时也会设置警报。 我似乎不明白为什么 代码是: len = input(20, minval=1, title="Length") mas = input(title="Aggregation", defval="SUM", options=["SUM", "EMA", "WMA"]) e = input(10.0, title="Volume Exponent (0-10 reduces & 10+

我试图为购买添加一个条件,条件是CMF应该高于之前的标准

我现在使用的代码在上一个栏较低时也会设置警报。 我似乎不明白为什么

代码是:

len = input(20, minval=1, title="Length")
mas = input(title="Aggregation", defval="SUM", options=["SUM", "EMA", "WMA"])
e = input(10.0, title="Volume Exponent (0-10 reduces & 10+ increases volume effect)")
p = input(false, title="Show in Percentage")
mvs = input(false, "Factor in Price (Money Volume)")
src=input(hlc3, title="Source for price factor")
trl = min(low,close[1]), trh = max(high,close[1]) // 'true range' fixes issues caused by gaps in price
wv = pow(volume,e/10.0)*(mvs ? src : 1)
ad = (trh==trl ? 0 : (2*close-(trh+trl))/tr(true))*wv
cmf = mas=="SUM" ? sum(ad, len)/sum(wv, len) : mas=="EMA" ? ema(ad, len)/ema(wv, len) : mas=="WMA" ? wma(ad, len)/wma(wv, len) : na
cmf_p  = if p
    50*cmf+50
else
    cmf
b = p ? 50 : 0

// CMF condition 
CMFPchg = change( cmf,2)
CMFCOND = CMFPchg >= 0.02

如果您执行
CMFPchg=cmf-nz(cmf[2])
,您是否仍然存在相同的问题?注意:如果只想处理正数,您可能需要使用
abs()
。这就解决了!非常感谢。