首页 > 解决方案 > 第 102 行:不能用 'expr1'=input integer 调用 'operator =='。参数的类型应该是: const string;

问题描述

我收到以下代码的上述错误消息,但我不明白为什么,请帮忙。它用于 mtf 指标。参数是一个字符串,因为引号在那里。这真的很令人困惑。

有人可以帮忙吗?

    res(Resolution) =>
        if Resolution == "00 Current"
            timeframe.period
        else
            if Resolution == "01 1m"
                "1"
            else
                if Resolution == "02 3m"
                    "3"
                else
                    if Resolution == "03 5m"
                        "5"
                    else
                        if Resolution == "04 15m"
                            "15"
                        else
                            if Resolution == "05 30m"
                                "30"
                            else
                                if Resolution == "06 45m"
                                    "45"
                                else
                                    if Resolution == "07 1h"
                                        "60"
                                    else
                                        if Resolution == "08 2h"
                                            "120"
                                        else
                                            if Resolution == "09 3h"
                                                "180"
                                            else
                                                if Resolution == "10 4h"
                                                    "240"
                                                else
                                                    if Resolution == "11 1D"
                                                        "1D"
                                                    else
                                                        if Resolution == "12 1W"
                                                            "1W"
                                                        else
                                                            if Resolution == "13 1M"
                                                                "1M"

标签: pine-script

解决方案


https://www.tradingview.com/pine-script-reference/v4/#op_==

似乎您在函数中传递了输入整数类型。您不能将整数与字符串进行比较。在 res() 调用中使用 tosting() 或 str.format() 函数解析数据。

x = input(01)
m = "1m"
res(tosting(x) + m)

推荐阅读