将脚本变量引用到输入字段中

发布于 2025-01-15 01:08:52 字数 231 浏览 2 评论 0原文

我有一个向我的机器人发送信号的策略。 我希望使用如图所示的符号 向机器人发送特定的获利和止损值,这些值是从我的脚本中动态获取的。我应该怎么做才能在输入字段中引用我的变量?

输入图片此处描述

I have a strategy sending signals to my bot.
I wish to use the notation as in picture
to send the bot specific take profit and stop loss values, dynamically taken from my script. What should I do to reference my variables inside the input fields?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

漫雪独思 2025-01-22 01:08:52

你不能那样做。输入字段需要一个const string,因此您不能在其中传递变量。

//@version=5
indicator("My script")

s = "Test "
i  = 10
t = s + str.tostring(i)
s_test = input.string(s)    // Fine
//s_test_2 = input.string(t)  / /Error

plot(close)

输入图片此处描述

该字段可能在那里,因此您可以为您的机器人输入特定命令(进入、退出等)。

如果您想在订单消息中使用变量,您应该使用 alert() 函数。

You cannot do that. Input field expects a const string so you cannot pass a variable there.

//@version=5
indicator("My script")

s = "Test "
i  = 10
t = s + str.tostring(i)
s_test = input.string(s)    // Fine
//s_test_2 = input.string(t)  / /Error

plot(close)

enter image description here

That field is probably there so you can enter specific commands for your bot (enter, exit etc.)

If you want to use variables in your order message, you should use the alert() function.

我只土不豪 2025-01-22 01:08:52

Nvm,我使用了str.replace()。
基本上,您获取输入变量(整个文本消息),并将其传递给 str.replace() n 倍的变量,每次都使用之前获得的新字符串。
就我而言,如果我想替换#LongSL#和#longTP#,我会写如下:

new_enterLong_msg = str.replace(original_enterLong_msg, "#LongTP#", str.tostring(LongTP), 0)
new2_enterLong_msg = str.replace(new_enterLong_msg, "#LongSL#", str.tostring(LongSL), 0)

Nvm, I used str.replace().
Basically you get the input variable (the whole text message) and pass it thru str.replace() n times as many variables you have to replace, each time using the previous obtained new string.
In my case, if I wish to replace #LongSL# and #longTP#, I will write as following:

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