查找绘图线的第一个值

发布于 2025-01-16 23:09:04 字数 384 浏览 0 评论 0原文

我有这样的情节:

//@version=4
study(title="Line", shorttitle="Line", overlay=true)

theline(src, len) => wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))

Line = theline(close, 9)

plot(Line, title='Line', color=#0066ff, linewidth=3)

该线将根据收盘价向上或向下移动。

当新柱出现时,当第一个收盘==开盘时,如何找到该行的第一个值。

我需要比较该值,以查看当前行是否高于或低于第一个值。

谢谢你帮助我。

I have the plot:

//@version=4
study(title="Line", shorttitle="Line", overlay=true)

theline(src, len) => wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))

Line = theline(close, 9)

plot(Line, title='Line', color=#0066ff, linewidth=3)

That line will move up or down depending on the close value.

How do I find the first value of that line, when the new bar appears, when the first close==open.

I need that value to compare, to see if the current line is above or under that first value.

Thank you for helping me.

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

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

发布评论

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

评论(2

有木有妳兜一样 2025-01-23 23:09:04

答案与上一个问题的原理相同,您必须重构 wma 方程,才能正常获得前 n-1 个值的总和,并替换使用开盘而不是收盘计算的第 n 个值(当前柱的值)。

//@version=5
indicator("hull open", overlay = true)

len = input.int(9)

f_wma_open(_close, _open, _len) =>
    float _wtd_sum = 0.0
    int _denom = 0

    for i = 1 to _len - 1
        _wt = _len - i
        _wtd_sum += _close[i] * _wt
        _denom += _wt

    _wtd_sum += _open * _len
    _denom += _len

    _wma_open = _wtd_sum / _denom
    _wma_open


f_hull_open(_close, _open, _len) =>
    _a = 2 * ta.wma(_close, _len / 2) - ta.wma(_close, _len)
    _b = 2 * f_wma_open(_close, _open, _len / 2) - f_wma_open(_close, _open, _len)
    _slen = math.round(math.sqrt(_len))
    
    float _wtd_sum = 0.0
    float _denom = 0.0
    for i = 1 to _slen - 1    
        _wt = _slen - i
        _wtd_sum += _a[i] * _wt
        _denom += _wt
    
    _wtd_sum += _b * _slen
    _denom += _slen
    
    _hull_open = _wtd_sum / _denom
    _hull_open


f_hull(_src, _len) =>
    ta.wma(2 * ta.wma(_src, _len / 2) - ta.wma(_src, _len), math.round(math.sqrt(_len)))
    
hull = f_hull(close, len)
hull_open = f_hull_open(close, open, len)


plot(hull, color = color.gray)
plot(hull_open, color = color.yellow)

The answer is the same principle as your last question, you have to refactor the wma equation in order to obtain the sum of the first n-1 values as normal and replace the nth value (current bar's value) calculated using open instead of close.

//@version=5
indicator("hull open", overlay = true)

len = input.int(9)

f_wma_open(_close, _open, _len) =>
    float _wtd_sum = 0.0
    int _denom = 0

    for i = 1 to _len - 1
        _wt = _len - i
        _wtd_sum += _close[i] * _wt
        _denom += _wt

    _wtd_sum += _open * _len
    _denom += _len

    _wma_open = _wtd_sum / _denom
    _wma_open


f_hull_open(_close, _open, _len) =>
    _a = 2 * ta.wma(_close, _len / 2) - ta.wma(_close, _len)
    _b = 2 * f_wma_open(_close, _open, _len / 2) - f_wma_open(_close, _open, _len)
    _slen = math.round(math.sqrt(_len))
    
    float _wtd_sum = 0.0
    float _denom = 0.0
    for i = 1 to _slen - 1    
        _wt = _slen - i
        _wtd_sum += _a[i] * _wt
        _denom += _wt
    
    _wtd_sum += _b * _slen
    _denom += _slen
    
    _hull_open = _wtd_sum / _denom
    _hull_open


f_hull(_src, _len) =>
    ta.wma(2 * ta.wma(_src, _len / 2) - ta.wma(_src, _len), math.round(math.sqrt(_len)))
    
hull = f_hull(close, len)
hull_open = f_hull_open(close, open, len)


plot(hull, color = color.gray)
plot(hull_open, color = color.yellow)
╰つ倒转 2025-01-23 23:09:04

您可以使用 varip 冻结并保存实时值并有条件地更新它们。我为您编写了一个自定义函数,它将冻结 wma 线的实时打开值。请注意,这仅适用于实时或警报。如果您正在实时观看开盘,它只会冻结开盘,并且警报将在添加到图表后的第一个开盘上开始工作。

//@version=4
study(title="Line", shorttitle="Line", overlay=true)

theline(src, len) => wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))

openVal(src) =>
    varip float lineOpen = na
    if barstate.isnew
        lineOpen := src
    result = barstate.islastconfirmedhistory[1] or barstate.isconfirmed ? src : lineOpen

Line = theline(close, 5)

Line2 = openVal(Line)

plot(Line, title='Line', color=#0066ff, linewidth=4)
plot(Line2, title='Alt Line', color=color.white)

干杯,祝你好运

You can use varip to freeze and hold real time values and update them conditionally. I wrote a custom function for you that will freeze the real time open value of the wma line. Please note this will only work in real time or for alerts. It will only freeze the open if you are watching the open live, and alerts will begin working on the first open after adding to the chart.

//@version=4
study(title="Line", shorttitle="Line", overlay=true)

theline(src, len) => wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))

openVal(src) =>
    varip float lineOpen = na
    if barstate.isnew
        lineOpen := src
    result = barstate.islastconfirmedhistory[1] or barstate.isconfirmed ? src : lineOpen

Line = theline(close, 5)

Line2 = openVal(Line)

plot(Line, title='Line', color=#0066ff, linewidth=4)
plot(Line2, title='Alt Line', color=color.white)

cheers and best of luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文