Pinescript:无法使用函数执行数组
我正在尝试编写一个脚本,其中需要输入日期,然后将数组中的数字添加到该日期,并使用所有数组项的结果日期绘制背景。但是出现“无法呼叫操作员”之类的错误 请寻求帮助。
//@version=5
indicator("My script")
starttime1 = input.time(timestamp("01 Nov 2021 00:00"), "Start Time")
starttime2 = input.time(timestamp("01 Nov 2021 00:00"), "Start Time2")
event_days1 = array.from(27,39,47,55,61,77,82,99,109,125,137,159,164,191,203,219,246,258,273,301,328,354)
post_days = input.int(5)
fDays(src) =>
pre_ts = starttime1 - 86400000
post_start_ts = starttime1 + 86400000 * src
post_end_ts = starttime1 + 86400000 * (src + post_days)
pre_range = time >= pre_ts and time < starttime1
post_range = time >= post_start_ts and time < post_end_ts
pre_range
pre_range1 = fDays(event_days1)
bgcolor(pre_range1 ? #0000FF : na)
I am trying to code a script, where it takes a input date, then adds numbers from an array to that date and plots the background with the resultant date for all the array items. However getting error like "cannot call operator"
Seeking help pls.
//@version=5
indicator("My script")
starttime1 = input.time(timestamp("01 Nov 2021 00:00"), "Start Time")
starttime2 = input.time(timestamp("01 Nov 2021 00:00"), "Start Time2")
event_days1 = array.from(27,39,47,55,61,77,82,99,109,125,137,159,164,191,203,219,246,258,273,301,328,354)
post_days = input.int(5)
fDays(src) =>
pre_ts = starttime1 - 86400000
post_start_ts = starttime1 + 86400000 * src
post_end_ts = starttime1 + 86400000 * (src + post_days)
pre_range = time >= pre_ts and time < starttime1
post_range = time >= post_start_ts and time < post_end_ts
pre_range
pre_range1 = fDays(event_days1)
bgcolor(pre_range1 ? #0000FF : na)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
event_days1 应该是一个整数数组,对吧?尝试更明确地声明变量并习惯 var/varip 前缀,请参阅下面的 pine 参考链接。
或者使用 input.string 轻松确认/更改值。首先在 event_days1_stringarray 中设置值,然后在脚本中使用 event_days1_integerarray。
仅在此输入字段中使用数字和逗号字符,无空格或"。
它是否按预期运行?
https://www.tradingview.com/pine-script-docs/en/v5/language/Variable_declarations.html#declaration-modes
event_days1 is supposed to be an integer array, right? Try to be more explicit in declaring variables and get used to var/varip prefix, see pine reference link below.
Or with input.string to easily confirm/change values. This sets values in event_days1_stringarray first then use event_days1_integerarray in your script.
Use numeric and comma characters only in this input field no space nor ".
Does it run as expected?
https://www.tradingview.com/pine-script-docs/en/v5/language/Variable_declarations.html#declaration-modes