gpt4 book ai didi

pine-script - 在 Pine 脚本中将字符串转换为整数

转载 作者:行者123 更新时间:2023-12-05 06:47:54 30 4
gpt4 key购买 nike

我想将 input.resolution 转换为以小时表示的整数

input() 函数中捕获的函数参数 resolution

下面是自定义函数

f_getLookbackNumber(resolution) => 
resolutionHours = iff(resolution == "6H", 360, iff(resolution == "1D", 360*2, iff(resolution == "1W", 360*2*7, iff(resolution == "1M", 360*2*30, resolution))))

resolutionHours

编译时出现如下错误



line 12: Cannot call 'iff' with arguments (input bool, literal integer, input string); available overloads: iff(bool, bool, bool) => bool; iff(bool, integer, integer) => integer; iff(bool, float, float) => float; iff(bool, color, color) => color; iff(bool, series[float], series[float]) => series[float]; iff(bool, series[integer], series[integer]) => series[integer]; iff(bool, series[color], series[color]) => series[color]; iff(bool, string, string) => string; iff(input bool, input bool, input bool) => input bool; iff(input bool, input integer, input integer) => input integer; iff(input bool, input float, input float) => input float; iff(input bool, input string, input string) => input string; iff(input bool, input color, input color) => input color; iff(const bool, const bool, const bool) => const bool; iff(const bool, const integer, const integer) => const integer; iff(const bool, const float, const float) => const float; iff(const bool, const string, const string) => const string; iff(const bool, const color, const color) => const color; iff(series[bool], bool, bool) => series[bool]; iff(series[bool], integer, integer) => series[integer]; iff(series[bool], float, float) => series[float]; iff(series[bool], color, color) => series[color]; iff(series[bool], series[integer], series[integer]) => series[integer]; iff(series[bool], series[color], series[color]) => series[color]; iff(series[bool], series[bool], series[bool]) => series[bool]; iff(series[bool], series[float], series[float]) => series[float]; iff(series[bool], series[string], series[string]) => series[string]; iff(series[bool], series[line], series[line]) => series[line]; iff(series[bool], series[label], series[label]) => series[label]; iff(series[bool], array[<array_type>], array[<array_type>]) => array[<array_type>];

当我尝试用 iff(resolution == "1M", 360 *2*30, 0) 代码编译

这似乎表明分辨率的数据类型不可分配给 resolutionHours

有没有办法将字符串类型转换为整数?

最佳答案

最后一个 iff 应返回 360230(如果分辨率为“1M”)或 0 否则。
您不需要将字符串转换为整数。

关于pine-script - 在 Pine 脚本中将字符串转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66963822/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com