【问题标题】:Condition only run ONCE (instead on all bars)条件只运行一次(而不是在所有柱上)
【发布时间】:2022-11-23 10:51:37
【问题描述】:

检查条件时差距(高-低)> 0.1%(多次遇到),标签只得到 呈现一次(而不是在 25 根柱回溯内的相关柱上)。
请提供解决方案。

代码 :
历史酒吧

//@version=5
indicator("PriceMomemtum",overlay = true,max_bars_back = 25)


gap = (math.abs(high - low)/low ) * 100 
//var gap = (math.abs(high - low)/low ) * 100 

if gap > 0.1
    var lbl = label.new(x = bar_index,y = na , text = na ,text_font_family = font.family_default ,xloc = xloc.bar_index,yloc =yloc.abovebar,style = label.style_arrowdown ,textcolor = color.white,size =size.small,textalign = text.align_left,tooltip = na)
    label.set_text(lbl,str.tostring(gap,"#.00")+"%")
    label.set_xy(lbl,bar_index,high )

实时柱

//@version=5

indicator("PriceMomemtum",overlay = true,max_bars_back = 25)


if barstate.isrealtime
    gap = (math.abs(high - low)/low ) * 100 
    //var gap = (math.abs(high - low)/low ) * 100 
    if gap > 0.1
        var lbl = label.new(x = bar_index,y = na , text = na ,text_font_family = font.family_default ,xloc = xloc.bar_index,yloc =yloc.abovebar,style = label.style_arrowdown ,textcolor = color.white,size =size.small,textalign = text.align_left,tooltip = na)
        label.set_text(lbl,str.tostring(gap,"#.00")+"%")
        label.set_xy(lbl,bar_index,high )

        alert(str.tostring(time(syminfo.timezone)) + "(PriceMomentum)", alert.freq_once_per_bar)

【问题讨论】:

    标签: pinescript-v5


    【解决方案1】:

    您是否尝试过在不使用“var”的情况下定义“lbl”变量?

    result

    【讨论】:

      猜你喜欢
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-08
      • 2018-06-29
      • 1970-01-01
      相关资源
      最近更新 更多