价格越过MA之后提醒,但请等待X金额$降低或上升

发布于 2025-01-21 06:44:02 字数 1435 浏览 1 评论 0原文

我是编码的新手,并且正在尝试编码一个警报,该警报会在价格上方的特定数量上移至MA交叉之后的特定数量上方。

我已经尝试了不同的事情,现在变得如此令人震惊,我迷路了。这是到目前为止最有效的方法,但并不是真的是因为在两个连续的Renko盒子关闭后,警报触发了,所以当不连续...任何想法时都无法工作吗?谢谢。 我目前正在使用跨界,上升和barsince的组合,但它不起作用。

    //@version=5  
    indicator('SMA21', overlay=true)  
    ma = ta.sma(close, 21)  
    maCrossUp = ta.crossover(close, ma)  
    maCrossDn = ta.crossunder(close, ma)  
   
    cond1= ta.rising(close,2)  
    cond2= ta.falling(close,2)  


    xUp = (ta.barssince(maCrossUp) == 1)  
    xDn = (ta.barssince(maCrossDn) == 1)  

    if xUp and cond1  
    // Trigger the alert the first time a cross occurs during the closed bar.  
    alert('Price (' + str.tostring(close) + ') crossed over MA ('  + str.tostring(ma) +').', alert.freq_once_per_bar_close)  
    
   
  

    if xDn and cond2  
    // Trigger the alert the first time a cross occurs during the closed bar.  
    alert('Price (' + str.tostring(close) + ') crossed under MA (' + str.tostring(ma) + ').', alert.freq_once_per_bar_close)  

    plot(ma)  
    plotshape(xUp and cond1, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), title='xUp')  
    plotshape(xDn and cond2, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), title='xDn')  

    //Trigger alert condition
    alertcondition(xUp and cond1 or xDn cond2, title='Alert Condition', message='Price crossed over MA')

I'm new to coding and I'm trying to code an alert that triggers when the price moves a specific amount of $ above or below after an MA cross.

I've tried different things, and now it's gotten so convoluted I'm lost. This is what works best so far but not really because the alert triggers after two consecutive Renko box closes, so doesn't work when not consecutive...any ideas?? Thanks.
I'm currently using a combination of crossover and rising and barssince but it doesn't work.

    //@version=5  
    indicator('SMA21', overlay=true)  
    ma = ta.sma(close, 21)  
    maCrossUp = ta.crossover(close, ma)  
    maCrossDn = ta.crossunder(close, ma)  
   
    cond1= ta.rising(close,2)  
    cond2= ta.falling(close,2)  


    xUp = (ta.barssince(maCrossUp) == 1)  
    xDn = (ta.barssince(maCrossDn) == 1)  

    if xUp and cond1  
    // Trigger the alert the first time a cross occurs during the closed bar.  
    alert('Price (' + str.tostring(close) + ') crossed over MA ('  + str.tostring(ma) +').', alert.freq_once_per_bar_close)  
    
   
  

    if xDn and cond2  
    // Trigger the alert the first time a cross occurs during the closed bar.  
    alert('Price (' + str.tostring(close) + ') crossed under MA (' + str.tostring(ma) + ').', alert.freq_once_per_bar_close)  

    plot(ma)  
    plotshape(xUp and cond1, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), title='xUp')  
    plotshape(xDn and cond2, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), title='xDn')  

    //Trigger alert condition
    alertcondition(xUp and cond1 or xDn cond2, title='Alert Condition', message='Price crossed over MA')

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文