无法避免使用变量'错误消息:security()。我做错了什么?

发布于 2025-01-27 09:12:26 字数 774 浏览 2 评论 0原文

我尝试从

下面,我包裹了一条太长的行(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所谓啦 2025-02-03 09:12:26

再次,所有内容与您突变的变量相关的所有内容都需要包裹在功能中。需要在此函数内部创建突变的变量并在此功能中进行突变。目的是使函数内部包含的变量在不同的符号上进行计算。在您的示例中,您从函数请求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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文