Pine Script 5版本中为何无法找到ta.sqrt函数?
Pine Script 5中ta.sqrt函数找不到的解决方法
问题原因
Pine Script 5对内置函数做了命名空间归类调整,平方根计算函数sqrt不再隶属于ta(技术分析)命名空间,而是被划分到了math(数学运算)命名空间下,因此调用ta.sqrt会触发函数未找到的错误,即便导入ta库也无法解决。
修复方案
将代码中的ta.sqrt替换为math.sqrt即可,Pine Script 5默认支持直接调用math命名空间下的函数,无需额外导入。
修改后的完整代码
//@version=5 indicator("Trend Extractor", overlay=false) src=input(close, title="Source") smooth = input.int(1, title="Smoothing", minval=1) length = input.int(50, title="Lookback", minval=1) offset = input.float(0.85, title= "ALMA Offset", step=0.01) sigma = input.float(6, title= "ALMA Sigma", minval=0) bmult = input.float(1.0, "Band Multiplier") cblen = input.bool(false, "Custom Band Length ? (Else same as Lookback)") blen = input.int(20, "Custom Band Length") highlight=input.bool(true) fill=input.bool(true) barcol=input.bool(false, "Bar Color") pch = ta.change(src, smooth)/src * 100 avpch = ta.alma(pch, length, offset, sigma) blength = cblen ? blen : length rms = bmult*math.sqrt(ta.sma(avpch*avpch, blength))
内容的提问来源于stack exchange,提问作者kris Lec
相关产品推荐
相关产品推荐

