[英](Tradingview - Pine Script) Convert iff Function to v5 error
[英]Inconsistent overload behaviour in TradingView's Pine Script v5
我遇到了一个问题,我似乎在 Tradingview 的 pine 脚本 v5 中发现了一个关于重载功能的错误。
代码示例:
//@version=5
indicator("Overload recognition from within custom functions not working consistently")
mult(array<float> x1, string x2) =>
[x1, x2]
mult(array<string> x1, string x2) =>
array.push(x1, x2)
x1
mult(bool x1, string x2) =>
[x1, x2]
myFn(y1) => // workaround: must define parameter type for the overload to work successfully
mult(y1, "Overload NOT recognized (unless used previously or type is defined explicitly before function parameter")
var stringArray = array.new_string(0,na)
// mult(stringArray, "Overload working as expected")
// mult(true, "Overload working as expected")
myFn(stringArray)
plot(1, "Overload recognition from within custom functions not working consistently")
Add to Chart operation failed, reason: line 16: Cannot call 'mult' with argument 'x1'='y1'. An argument of 'string[]' type was used but a 'float[]' is expected
.
问题是,如果我使用对之前创建的字符串数组的y1
引用并从myFn(y1)
中调用mult(y1, "...")
function ,编译器将无法识别我的参数的引用类型并识别对应 function 过载,响应第一个匹配 。
myFn(array<string> y1) =>
提供类型定义,我实际上不想这样做,则找到正确的重载mult(stringArray, "Overload working as expected")
在我的 function 调用之前,触发一些与我相应的重载有关的重载的内部逻辑,在我的 fn 调用中也会发现重载 - 实际上甚至没有一种解决方法......而只是一个事实截至今天( 2022-08-08 ),TradingView Pine团队确认了该错误,并打开了一项任务来修复它。 希望我们能尽快得到电视更新来解决这个问题。
进一步研究:到目前为止,除了问题中建议的解决方法之外,没有其他解决方法。 没有数组操作有助于类型引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.