我试图对第一个值 > 的情况发出警报或<其他

发布于 2025-01-09 04:35:33 字数 796 浏览 0 评论 0 原文

我对编码相对较新,正在尝试弄清楚如何告诉 Pine Script 获取 macD 行 > 的第一个实例。且<信号线发出警报。目前,它为每支蜡烛显示一个标签。

尝试在第一次迭代后使“长”为假,直到“短”为真。每次交叉仅发出一次警报。

感谢那些提供帮助的人。我会给解决这个问题的人 15 xrp。

long = macd > signal
short = macd < signal
alertcondition(long, "Macd Long open", "message")
alertcondition(short, "Macd short open", "message")
if(long)
    l = label.new(bar_index, high)
    label.set_text(l, "buy@\n" + str.tostring(close))
    label.set_color(l, color.green)
    label.set_yloc(l, yloc.belowbar)
    label.set_style(l, label.style_label_up)

if(short)
    l = label.new(bar_index, high)
    label.set_text(l, "sell@\n" + str.tostring(close))
    label.set_color(l, color.red)
    label.set_yloc(l, yloc.belowbar)
    label.set_style(l, label.style_label_down)

'''

Im relatively new to coding and am trying to figure out how to tell Pine Script to take the first instance the macD line is > and < the signal line to make an alert. Currently it shows a label every candle it is.

Trying to make "long" false after the first iteration, until "short" is true. To make only one alert per cross over.

Thank You to those who help. Ill give who ever solves this problem 15 xrp.

long = macd > signal
short = macd < signal
alertcondition(long, "Macd Long open", "message")
alertcondition(short, "Macd short open", "message")
if(long)
    l = label.new(bar_index, high)
    label.set_text(l, "buy@\n" + str.tostring(close))
    label.set_color(l, color.green)
    label.set_yloc(l, yloc.belowbar)
    label.set_style(l, label.style_label_up)

if(short)
    l = label.new(bar_index, high)
    label.set_text(l, "sell@\n" + str.tostring(close))
    label.set_color(l, color.red)
    label.set_yloc(l, yloc.belowbar)
    label.set_style(l, label.style_label_down)

'''

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你不解释 2025-01-16 04:35:33

你必须写出 MACD 计算公式,所以我创建了一个列表

[ma​​cdline, singalline, ma​​cdhist] = ta.macd(收盘, 12, 26, 9 )

基本等式是:

fast_length = input.int(title="Fast Length", defval=12)
slow_length = input.int(title="Slow Length", defval=26)
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)

// Calculating
fast_ma = ta.ema(fast_length)
slow_ma =ta.ema(slow_length)
macd = fast_ma - slow_ma
signal = ta.sma(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram")
plot(macd, title="MACD")
plot(signal, title="Signal")

我解决了你的代码问题

//@version=5
indicator("My script", overlay=true)


[macdline, singalline, macdhist] = ta.macd(close, 12, 26, 9)

long = macdline > singalline
short = macdline < singalline

if(long)
    l = label.new(bar_index, high)
    label.set_text(l, "buy@\n" + str.tostring(close))
    label.set_color(l, color.green)
    label.set_yloc(l, yloc.belowbar)
    label.set_style(l, label.style_label_up)

if(short)
    l = label.new(bar_index, high)
    label.set_text(l, "sell@\n" + str.tostring(close))
    label.set_color(l, color.red)
    label.set_yloc(l, yloc.abovebar)
    label.set_style(l, label.style_label_down)
    
alertcondition(long, "Macd Long open", "message")
alertcondition(short, "Macd short open", "message")    

You have to write the MACD calculation formula, so I create a list

[macdline, singalline, macdhist] = ta.macd(close, 12, 26, 9)

The basic equation is:

fast_length = input.int(title="Fast Length", defval=12)
slow_length = input.int(title="Slow Length", defval=26)
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)

// Calculating
fast_ma = ta.ema(fast_length)
slow_ma =ta.ema(slow_length)
macd = fast_ma - slow_ma
signal = ta.sma(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram")
plot(macd, title="MACD")
plot(signal, title="Signal")

I solved your code problem

//@version=5
indicator("My script", overlay=true)


[macdline, singalline, macdhist] = ta.macd(close, 12, 26, 9)

long = macdline > singalline
short = macdline < singalline

if(long)
    l = label.new(bar_index, high)
    label.set_text(l, "buy@\n" + str.tostring(close))
    label.set_color(l, color.green)
    label.set_yloc(l, yloc.belowbar)
    label.set_style(l, label.style_label_up)

if(short)
    l = label.new(bar_index, high)
    label.set_text(l, "sell@\n" + str.tostring(close))
    label.set_color(l, color.red)
    label.set_yloc(l, yloc.abovebar)
    label.set_style(l, label.style_label_down)
    
alertcondition(long, "Macd Long open", "message")
alertcondition(short, "Macd short open", "message")    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文