【问题标题】:Could not find function or function reference normalize找不到函数或函数引用规范化
【发布时间】:2022-01-28 21:50:49
【问题描述】:

我试图在 Tradview 的 Pine 编辑器中将多个指标组合到一个脚本中。 因此我需要改变体积直方图的比例。

我认为 normalize 功能在我正在使用的 Pine 版本中不起作用,但如果此功能已更改名称,我无法在任何地方找到。

study("Stoch RSI Mom")

//RSI
plot(rsi(close, 14), color =red, title = "RSI")

//Stoch
plot(stoch(close, high, low, 14), color=orange, title = "Stoch")


//Momentum added 10 multiplier for scale
plot(mom(close, 10)*10, color =#2962FF, title="MOM")

//Volume
plot(normalize(volume, -100, 100), style=histogram, linewidth = 4, color=orange, transp=50)

我收到的错误消息:

Add to Chart operation failed, reason: Could not find function or function reference normalize

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    我认为没有名为 normalize 的 built-in 函数。

    看起来你想要的功能是这样的:

    // ————— When the scale of the signal to rescale is unknown (unbounded).
    // Min/Max of signal to rescale is determined by its historical low/high.
    normalize(_src, _min, _max) =>
        // Normalizes series with unknown min/max using historical min/max.
        // _src      : series to rescale.
        // _min, _min: min/max values of rescaled series.
        var _historicMin =  10e10
        var _historicMax = -10e10
        _historicMin := min(nz(_src, _historicMin), _historicMin)
        _historicMax := max(nz(_src, _historicMax), _historicMax)
        _min + (_max - _min) * (_src - _historicMin) / max(_historicMax - _historicMin, 10e-10)
    

    Source

    【讨论】:

    • 这确实有效,但是我必须将正确的版本添加到我的 pine 脚本中。在顶部它说:'//@version=2' 我将其更改为'//@version=4' 我使用@vituvius 建议的代码添加了规范化功能。我稍微清理了我的代码
    • 我确实有一个问题,是否有可能不对完整的历史最小值最大值进行标准化。例如去年还是 6 个月?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多