我是新手。我有一个松树脚本代码。
功能问题:
input.timeframe('D')
我需要脚本调用一个比实时使用的更高的资产公式时间。
我使用一个函数:
request.security()
使用可变变量调用字符串时出错:
input.timeframe(VAR)
返回错误:
An argument of 'simple string' type was used but a 'const string' is expected.
调用与实际用户时间框架不同的时间框架的资产。
当我使用时刻表时。指示函数应该调用上一时间,即天= 'D‘。
或
当实时是'D‘时。指示函数应该调用上一时间(星期= 'W‘)。
我要自动时间搜索功能。
此外,用户还可以手动选择时间框架。
代码示例如下:
//@version=5
indicator(title="My Indicator", shorttitle="My Indicator", overlay=true, timeframe="", timeframe_gaps=true)
timeframe_automatic = (timeframe.isintraday ? 'D' : timeframe.isdaily ? 'W' : timeframe.isweekly ? 'M' : na)
timeframe_options = input.timeframe((timeframe_automatic), "Resolution Big", options=['D', 'W', 'M'])
timeframe_called = (request.security(syminfo.tickerid, (timeframe_options), close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off))
松树脚本编译器需要input.timeframe( 'D‘)和’D‘的'String’。
在使用可变的“简单字符串”进行自动搜索时拒绝。
line xxx: Cannot call 'input.timeframe' with argument 'defval'='timeframe_options'. An argument of 'simple string' type was used but a 'const string' is expected.
我在文档中找不到合适的函数来解决这个问题。
谢谢你的帮助。
发布于 2022-05-11 06:56:37
你已经有了。在您的安全呼叫中使用timeframe_automatic
。
timeframe_called = (request.security(syminfo.tickerid, timeframe_automatic, close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off))
发布于 2022-05-12 02:32:51
问题是让用户决定是将其保留为自动模式还是将其置于手动模式。
timeframe_automatic = is a mutable variable.
input.timeframe(timeframe_automatic)
不接受可变变量,而只接受一个const字符串。
但是,request.security()
接受周期可变变量,并要求它是const字符串。
我找到的解决方案是将决定分为3种不同的代码。
在第一段代码中,我必须添加一个手动选择器来在自动代码和手动代码之间进行选择。
还有第二个决定代码。
最后,第三个代码进行函数调用。
代码如下所示,示例:
//@version=5
indicator(title="My Indicator", shorttitle="My Indicator", overlay=true, timeframe="", timeframe_gaps=true)
timeframe_selector = input.string(title = "Timeframe Big", defval = "Automatic", options=["Automatic", "Manual"])
timeframe_automatic = (timeframe.isintraday ? 'D' : timeframe.isdaily ? 'W' : timeframe.isweekly ? 'M' : timeframe.ismonthly ? '12M': na)
timeframe_manual = input.timeframe('D', "Resolution Big", options=['D', 'W', 'M', '12M'])
timeframe_decision = (timeframe_selector == "Automatic") ? timeframe_automatic : (timeframe_selector == "Manual") ? timeframe_manual : na
timeframe_called = (request.security(syminfo.tickerid, (timeframe_decision), close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off))
好了,现在!
https://stackoverflow.com/questions/72193537
复制相似问题