[英]Alert condition that only contains extreme values. Pinescript v5
当我 plot "HMAefi" 时,您会看到这些值通常接近于零。 当“HMAefi”不接近于零时,我希望变量“w”仅为 1 或 -1。 由于它是数量,因此数量会根据股票而变化,我想要一个适用于所有股票的代码。 变量“w”用于查找“HMAefi”的顶部/底部。 我希望有人能帮助我。
//@version=5
indicator("delete", format=format.volume)
w=0
ValdLangd = input.int(25, minval=1, maxval=2000, title="Längd")
//Elders force index
efi = ta.ema(ta.change(close) * volume, ValdLangd)
HMAefi = ta.hma(efi, ValdLangd)
if HMAefi < 0 and HMAefi[1] > HMAefi[2]
w:=1
if HMAefi > 0 and HMAefi[1] < HMAefi[2]
w:=-1
plot(HMAefi, color=#F44336, title="Elders Force Index")
hline(0, color=#787B86, title="Zero")
如果您想要适用于所有事物的东西,则需要用户输入。 因为,你如何定义“接近于零”? 1 接近于零吗? 10 接近于零吗?
有一个用户输入来定义这个距离。 然后检查HMAefi
是否大于该阈值。
in_threshold = input.int(100)
is_greater_than_threshold = math.abs(HMAefi - in_threshold) > 0
if (HMAefi < 0 and HMAefi[1] > HMAefi[2]) and is_greater_than_threshold
w:=1
if (HMAefi > 0 and HMAefi[1] < HMAefi[2]) and is_greater_than_threshold
w:=-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.