【问题标题】:Pinescript. Plotting conditional statement脚本。绘制条件语句
【发布时间】:2021-12-03 02:02:55
【问题描述】:

如果变量barup 为真,我希望它绘制一个系列;如果变量bardown 为真,我希望它绘制另一个系列值。

我当前的代码产生错误:不能使用“在本地范围内绘图”。

如何更改以下代码,以使指标根据当天的高点或低点显示低点高于 30 日均线或低于 30 日均线的天数。

这是我现在拥有的代码:

indicator("LandryLight")
bardown = high < ta.ema(close,30)
barup = low > ta.ema(close,30)
if barup
    plot(series=ta.barssince(barup)*-1, title="Consecutive Bars Down", color=color.red, style=plot.style_histogram, linewidth=2)
if bardown
    plot(series=ta.barssince(bardown), title="Consecutive Bars Up", color=color.green, style=plot.style_histogram, linewidth=2)
hline(10,title="Threshold", color=color.white, linestyle=hline.style_dashed, linewidth=1)

【问题讨论】:

    标签: if-statement plot conditional-statements pine-script


    【解决方案1】:

    第一次使用标签 [pine-script]

    尝试一步一步,然后剧情 我会这样做:

    //@version=5
    indicator("LandryLight")
    bardown = high < ta.ema(close,30)
    barup = low > ta.ema(close,30)
    
    barupCont = ta.barssince(barup)*-1
    bardownCont = ta.barssince(bardown)
    barupOK = barup ? barupCont : na
    bardownOK = bardown ? bardownCont : na
    
    plot(series= barupOK, title="Consecutive Bars Down", color=color.red, style=plot.style_histogram, linewidth=2)
    plot(series= bardownOK, title="Consecutive Bars Up", color=color.green, style=plot.style_histogram, linewidth=2)
    hline(10,title="Threshold", color=color.white, linestyle=hline.style_dashed, linewidth=1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 2014-06-25
      • 2016-12-22
      • 2013-01-29
      • 1970-01-01
      相关资源
      最近更新 更多