【问题标题】:can't extract value from Function无法从函数中提取值
【发布时间】:2022-11-24 17:49:04
【问题描述】:

函数以 rsi 为例,从为我声明的历史柱 1 到 12 中找到 rsi 的最大值(整数或“00,0”)。

//@version=5
indicator("loop", shorttitle="loop")
len = input.int(14, title="RSI Length")
src = input.source(close, "RSI Source")

Rsi = ta.rsi(src, len)
plot(Rsi*10, "RSI", color=#673ed8)
hline(65,linestyle= hline.style_dashed , color=color.new(color.red, 0))

minF = 1, maxF = 12, RsiFunction = Rsi
ff_loopMax(RsiFunction,minF, maxF) =>
    var float Max = na
    var float MaxOdpCena = na
    var int MaxNrBar = na
    for i=minF to maxF       
        if i == minF
            Max := RsiFunction[i]
            //MaxOdpCena := high[i]
            //MaxNrBar := i
        else
            //MaxOdpCena := Max > RsiFunction[i] ? MaxOdpCena : high[i]
            //MaxNrBar := Max > RsiFunction[i] ? MaxNrBar : i
            Max := math.max(Max,RsiFunction[i])
    

// I want Max result from function

plot(Max,         "rsiMax", color=#b63253)
Result = ff_loopMax(Rsi,5,15)

从函数中提取的代码应该单独工作。但我无法应付功能。

【问题讨论】:

    标签: function pine-script


    【解决方案1】:

    pine 脚本中的函数返回最后一个表达式的值。在你的例子中,最后一个表达式是Max,但你不能直接访问它。您调用该函数,并将此返回值设置为一个变量。

    您应该将最后两行更改为:

    Result = ff_loopMax(Rsi,5,15)       // Result is now equal to Max
    plot(Result, "rsiMax", color=#b63253)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      相关资源
      最近更新 更多