无法避免使用变量'错误消息:security()。我做错了什么?
我尝试从
下面,我包裹了一条太长的行(booleanvar =
),以避免溢出,以使其变得容易阅读。
MyFunction() =>
BooleanVar = //THE ERROR MESSAGE ADDRESSES THIS LINE
ta.barssince(request.security(syminfo.tickerid, "5", MutableVar1))
< ta.barssince(request.security(syminfo.tickerid, "5", MutableVar2)) // *
AnotherBooleanVar = MyFunction() and SomethingAlreadyCalculated
plotshape(AnotherBooleanVar ? ThingToPlot : na, text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=longColorConfirmed, textcolor=color.white)
奇怪的事情是,标记的行没有错误消息,直到我将另一个booleanvar
纳入plotchar()
函数。如果我从plotchar()
中删除该标准,则突然没有上述行的错误。
错误消息是,重复:无法将突变变量用作请求的参数。安全函数。
I tried to implement the example code from this useful answer but the 'mutable variable' error still remained. What did I do wrong?
Below, I wrapped a too long line (BooleanVar =
) to avoid overflow, for making it easy-readable.
MyFunction() =>
BooleanVar = //THE ERROR MESSAGE ADDRESSES THIS LINE
ta.barssince(request.security(syminfo.tickerid, "5", MutableVar1))
< ta.barssince(request.security(syminfo.tickerid, "5", MutableVar2)) // *
AnotherBooleanVar = MyFunction() and SomethingAlreadyCalculated
plotshape(AnotherBooleanVar ? ThingToPlot : na, text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=longColorConfirmed, textcolor=color.white)
The strange thing is, there's no error message for the marked line until I include that AnotherBooleanVar
into a plotchar()
function. If I remove that criterion from plotchar()
then suddenly no error for the line above.
Error message is, repeat: Cannot use a mutable variable as an argument of the request.security function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
再次,所有内容与您突变的变量相关的所有内容都需要包裹在功能中。需要在此函数内部创建突变的变量并在此功能中进行突变。目的是使函数内部包含的变量在不同的符号上进行计算。在您的示例中,您从函数请求
mutableVar1
,但是变量本身是在其他地方创建和突变的。Once again, everything related to the variable that you mutate needs to be wrapped in a function. The mutated variable needs to be created inside this function and mutated inside this function. The goal is to make the variable contained inside the function so that it is possible to calculate it on a different symbol. In your example, you request
MutableVar1
from a function, but the variable itself is both created and mutated elsewhere.