繁体   English   中英

当随机指标中的线条相互碰撞时,pine 脚本会发出警报

[英]pine script send an alert when the lines bumping into each other in stochastic indicator

当随机指标的两条线相互碰撞时,我想发送警报。
我写了一个警报条件,但它没有给出任何警报。

//@version=5
indicator(title="Stochastic", shorttitle="Stoch", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
periodK = input.int(14, title="%K Length", minval=1)
smoothK = input.int(1, 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)

// My alert condition
alertcondition(k == d, 'Collision happened', 'Collision happened')

h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

不太可能满足您的条件:k == d
您应该测试该值是否刚刚越过:

justcrossed = false
if (k > d and k[1] < d[1]) or (k < d and k[1] > d[1]
    justcrossed := true
alertcondition(justcrossed, 'Collision happened', 'Collision happened')

此外,不要忘记在图表上激活警报以创建它(请参阅https://www.tradingview.com/pine-script-reference/v5/#fun_alertcondition

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM