如何将变量声明为 const int?
我正在尝试将计算的整数插入到平滑移动平均线的表达式中。
我有以下代码:
float timeframe = str.tonumber(timeframe.period)
float timeframefactor = 5/timeframe
int MA200Factor = math.round(200*timeframefactor)
int MA50Factor = math.round(50*timeframefactor)
int MA20Factor = math.round(20*timeframefactor)
然后我用 SMMA 行进行长度跟踪:
len200 = input.int(200, minval=1, title="200 SMMA", group = "Smoothed MA")
我希望用 MA200Factor
替换“200”。但是,当我执行此操作时,会出现错误,指出该值需要为 const int。我不知道该怎么做。
I am trying to insert a computed integer into an expression for a Smoothed Moving Average.
I have the following code:
float timeframe = str.tonumber(timeframe.period)
float timeframefactor = 5/timeframe
int MA200Factor = math.round(200*timeframefactor)
int MA50Factor = math.round(50*timeframefactor)
int MA20Factor = math.round(20*timeframefactor)
I then have followed this up with an SMMA line for length:
len200 = input.int(200, minval=1, title="200 SMMA", group = "Smoothed MA")
I would like the MA200Factor
to replace the "200". However, when I do this, it comes up with an error saying the value needs to be const int
. I don't know how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。
const int
意味着它的值必须在编译时已知。因此,您不能为该参数使用变量。You cannot.
const int
means its value must be known at compile time. Therefore you cannot use variables for that argument.