首页 > 解决方案 > 随机指标低时的最低图表低点

问题描述

当随机指标 K 低于 55 时,我想在图表上画出最低点。

到目前为止,我的代码是:

//@version=4
study(title="Lows", shorttitle="Low of low", overlay=true)

periodK = input(14, title="K", minval=1)

smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)

lowestInCycle(series) =>
    min=101.0
    if series < 55
        if series < min
            min := series
    else
        min:=na
    min != 101.0

plotshape(lowestInCycle(k), title="Test", location=location.belowbar, color=color.red, transp=0, style=shape.triangleup, text="L")

我还修改了随机指标,使其在低于 55 时显示交叉,并且在 K 上越来越低。这仅供参考。

我只想标记每个“低于 55 的随机集群”中的最低价格。

如何才能做到这一点?任何帮助表示赞赏。

PS。不用说我是初学者。自从我写了这篇文章以来,只要玩一下,我就可以让代码变得更好。

提前致谢

我得到的是这样的

标签: pine-script

解决方案


这使用标签来标识 55 岁以下周期中的最低 k,因此您只能看到最后 500 个周期的标签。当指标实时运行时,k 值最低的柱可以变化,直到 55 以下周期完成。最低 k 值的值与标签一起打印:

//@version=4
study(title="Lows", shorttitle="Low of low", overlay=true, max_labels_count = 500)

periodK = input(14, title="K", minval=1)

smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)

lowestInCycle(series) =>
    _xDn = crossunder(series, 55)
    _xUp = crossover(series, 55)
    var label _label = na
    var float _min = na
    if _xDn
        // We enter a cycle; create a new label (each cycle has its own label).
        _min := series
        _label := label.new(bar_index, close, tostring(_min, "#.##"), yloc = yloc.belowbar, color = color.red, textcolor = color.red, style = label.style_arrowup)
        // This is just so that all `if` blocks return a float, otherwise compiler complains.
        float(na)
    else if _xUp
        // We exit a cycle.
        _min := na
    else if not na(_min)
        // We are in a cycle; get new minimal value if there is one.
        _min := min(_min, series)
    if change(_min) < 0
        // We are in a cycle and a new minimum was found; update the cycle's label.
        label.set_x(_label, bar_index)
        label.set_text(_label, tostring(_min, "#.##"))

lowestInCycle(k)
// We need to  plot something, otherwise compiler complains.
plot(na)

这显示了正在运行的代码,下面的 Stoch 显示了带有红色背景的循环:

在此处输入图像描述


推荐阅读