内置Stoch vs测试:

看起来似乎应用了另一个平滑。相同的设置:


请注意,我使用了(8,3,3),这里实际上没有使用或绘制D。
我使用的函数是内置的,不是WYSIWYG吗?
内置:
//@version=5
indicator(title="Stochastic", shorttitle="Stoch", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
periodK = input.int(8, title="%K Length", minval=1)
smoothK = input.int(3, title="%K Smoothing", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
plot(k, title="%K", color=#2962FF)
plot(d, title="%D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")我的:
//@version=4
study(title="test", overlay=false)
src = input(close, title="Index Source")
v2 = security("OANDA:USDJPY", timeframe.period, src)
h2 = security("OANDA:USDJPY", timeframe.period, high)
l2 = security("OANDA:USDJPY", timeframe.period, low)
Length = input (8, minval=1, title = "Stochastic Length")
k = input (3, minval=1, title = "Stochastic %K")
StoV2 = stoch (v2, highest(h2, Length), lowest(l2, Length), Length)
Kv2 = sma (StoV2, k)
plot (Kv2, title ="%K", color = color.blue, linewidth=2)记住使用USDJPY进行比较!
发布于 2021-11-18 20:40:31
是的,它们是不同的,因为你的代码做了一些与内置代码不同的事情。结果不同,因为您在stoch()调用中使用了最高()和最低()。如果您试图重现内置函数,则不需要它们。stoch()函数执行的等同于它的进程中已经存在的最高/最低值,所以您所拥有的等价物等同于执行最高值( you ())。您还可以通过在一个安全调用中执行操作来减少安全调用的数量,如下所示:
stoch_k = security("OANDA:USDJPY", timeframe.period, sma(stoch(src, high, low, Length), k))https://stackoverflow.com/questions/70026059
复制相似问题