【问题标题】:How to access actual numbers within a series[float] in pinescript如何在pinescript中访问系列[float]中的实际数字
【发布时间】:2021-07-25 21:09:52
【问题描述】:

好吧,我想要实现的目标听起来相当简单:回顾过去的每周高点和低点(所以每个星期天美国东部标准时间晚上 8 点),并将这些水平绘制为水平线。我想在过去 12 周左右这样做

但是,当我尝试这样做时,我似乎无法仅从系列对象中获取实际值。到目前为止,这是我的代码,试图仅绘制其中一个级别:

allLows = security(syminfo.tickerid, "W", low)
allHighs = security(syminfo.tickerid, "W", high)

h = allHighs[1]
l = allLows[1]

plot(h, "High (sell zone)", color.red)
plot(l, "Low (buy zone)", color.green)

这是我得到的图像:

这里有一些更接近我真正想要的东西(手动绘制):

理想情况下,我只想获取 allHighsallLows 系列中的实际值并绘制它们,但我一生无法弄清楚如何

【问题讨论】:

    标签: pine-script tradingview-api


    【解决方案1】:
    //@version=4
    study("", overlay = true, max_lines_count = 24)
    
    interval = input("W")
    
    new_interval = change(time(interval)) != 0
    
    var float hh = na
    var int hh_index = na
    var float ll = na
    var int ll_index = na
    
    if new_interval
        line.new(x1 = hh_index, y1 = hh, x2 = hh_index + 1, y2 = hh, color = color.red, extend = extend.right)
        line.new(x1 = ll_index, y1 = ll, x2 = ll_index + 1, y2 = ll, color = color.green, extend = extend.right)
        hh := high
        ll := low
        hh_index := bar_index
        ll_index := bar_index
    else
        if high > hh
            hh := high
            hh_index := bar_index
        if low < ll
            ll := low
            ll_index := bar_index
    

    注意max_lines_count。它将限制多少历史行。还有许多其他方法可以做到。为了更轻松地引用值或更好地控制行,请使用 var 数组和 var 行数组来存储值。

    【讨论】:

    • 谢谢!我想我通过尝试使用security 使其过于复杂
    • 我确保在 tradeview btw @rumpypumpydumpy 上感谢您
    • 谢谢,你真好。您可以使用安全性来获取价格值,但您必须这样做才能获得正确的 bar_index 来定位行的开头。
    猜你喜欢
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多