正确的方法是在 Pine脚本指标中添加警报。

huangapple go评论72阅读模式
英文:

What is the correct way to add alerts to a pine script indicator

问题

如何将警报添加到这个松树脚本(v5)中,例如购买/出售条件,警报是为购买或出售

buy = s > 2个MA的
sell = s < 2个MA的

alertcondition(buy或sell,"文本")

这两个MA的图表不太直接,所以我没有成功将它们纳入警报条件。

任何想法将不胜感激 - 谢谢

指示器(title='TBA Test',shorttitle='TBA')
src = close
rsi_length = input(14,title='RSI长度')
rsi_mom_length = input(30,title='RSI动量长度')
rsi_ma_length = input(9,title='RSI MA长度')
ma_length = input(6,title='SMA长度')
fastLength = input(23)
slowLength = input(50)

r = ta.rsi(src,rsi_length)
rsidelta = ta.mom(r,rsi_mom_length)
rsisma = ta.sma(ta.rsi(src,rsi_ma_length),ma_length)
s = rsidelta + rsisma

plot(s,color=color.new(#e7c7e7,0),linewidth=2)
plot(ta.sma(s,fastLength),linewidth=1,color=color.new(#FFFF00,0))
plot(ta.sma(s,slowLength),linewidth=1,color=color.new(#FF0000,0))


// 我尝试了交叉和< >,但松树不喜欢我描述两个SMA的方式。
英文:

How do I add alerts to this pine script (v5) eg. buy/sell conditions, with alert being for buy OR sell

buy = s > the 2 ma's
sell = s < the 2 ma's

alertcondition(buy or sell, &quot;text&quot;)

The plots for the 2 ma&#39;s are not straight forward, so I have failed to incorporate them into the alert condition.

Any ideas will be appreciated - Thanks

indicator(title=&#39;TBA Test&#39;, shorttitle=&#39;TBA&#39;)
src = close
rsi_length = input(14, title=&#39;RSI Length&#39;)
rsi_mom_length = input(30, title=&#39;RSI Momentum Length&#39;)
rsi_ma_length = input(9, title=&#39;RSI MA Length&#39;)
ma_length = input(6, title=&#39;SMA Length&#39;)
fastLength = input(23)
slowLength = input(50)

r = ta.rsi(src, rsi_length)
rsidelta = ta.mom(r, rsi_mom_length)
rsisma = ta.sma(ta.rsi(src, rsi_ma_length), ma_length)
s = rsidelta + rsisma

plot(s, color=color.new(#e7c7e7, 0), linewidth=2)
plot(ta.sma(s, fastLength), linewidth=1, color=color.new(#FFFF00, 0))
plot(ta.sma(s, slowLength), linewidth=1, color=color.new(#FF0000, 0))

// I have tried crossovers and < >, but pine does not like the way I am describing the two sma's.

答案1

得分: 0

使用math.maxmath.min函数来确定最高/最低的简单移动平均值(SMA)。

sma_max = math.max(sma1, sma2)
sma_min = math.min(sma1, sma2)

buy_alert = (s > sma_max)
sell_alert = (s < sma_max)

然后在你的alertcondition调用中使用buy_alertsell_alert

英文:

Use math.max and math.min functions to figure out the highest/lowest SMAs.

sma_max = math.max(sma1, sma2)
sma_min = math.min(sma1, sma2)

buy_alert = (s &gt; sma_max)
sell_alert = (s &lt; sma_max)

Then use buy_alert and sell_alert in your alertcondition call.

huangapple
  • 本文由 发表于 2023年3月31日 19:29:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75898032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定