英文:
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, "text")
The plots for the 2 ma's are not straight forward, so I have failed to incorporate them into the alert condition.
Any ideas will be appreciated - Thanks
indicator(title='TBA Test', shorttitle='TBA')
src = close
rsi_length = input(14, title='RSI Length')
rsi_mom_length = input(30, title='RSI Momentum Length')
rsi_ma_length = input(9, title='RSI MA Length')
ma_length = input(6, title='SMA Length')
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.max
和math.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_alert
和sell_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 > sma_max)
sell_alert = (s < sma_max)
Then use buy_alert
and sell_alert
in your alertcondition
call.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论