如何自动更改输入。TimeFrame(TimeFrame(d')到比用户图表大的周期。 Pinescript V5

发布于 2025-01-28 07:12:56 字数 1366 浏览 2 评论 0原文

我是新手。我有一个Pine脚本代码。

功能问题:

input.timeframe('D')

我需要脚本来调用比实时使用的脚本时间高的资产公式时间。

我使用一个函数:

request.security()

带有Mutable变量的错误调用字符串:

input.timeframe(VAR)

返回错误:

An argument of 'simple string' type was used but a 'const string' is expected.

呼叫带有时间范围的资产与真实用户时间范围不同。

当我使用小时时间表时。 指示器函数应调用上层时间IE ='d'。

当实时是“ D”时。指示器功能应调用上班时间IE周='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))

Pine脚本编译器需要输入的“字符串const”。TimeFrame('d')以及“ D”。

并在使用可突出的“简单字符串”进行自动搜索时拒绝。:

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.

我找不到文档中适用于此的正确功能。

感谢您的帮助。

I'm newbie. I have a Pine script code.

Problem with function:

input.timeframe('D')

I need the script to call an asset formula time higher than the one used in real time.

I use a function:

request.security()

Error calling string with mutable variable:

input.timeframe(VAR)

Return error:

An argument of 'simple string' type was used but a 'const string' is expected.

To call up an asset with timeframe different from the real user timeframe.

When I use the HOURS time chart.
The indicator function should call the upper time ie days = 'D' .

Or

When real time is 'D'. The indicator function should call the upper time ie week = 'W' .

I want Automatic Time Search function.

And also that the user chooses timeframe manually in an Optional way.

The code EXAMPLE is as follows:

//@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))

The Pine Script compiler requires a 'String Const' for input.timeframe('D') as well as 'D'.

And refuses when using a mutable 'Simple String' for automatic search.:

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.

I can't find proper functions in the documentation to work around this.

Thanks for the help.

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

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

发布评论

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

评论(2

谎言月老 2025-02-04 07:12:56

你已经拥有了。在您的安全调用中使用timeframe_automatic

timeframe_called = (request.security(syminfo.tickerid, timeframe_automatic, close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off))

You already have it. Use timeframe_automatic in your security call.

timeframe_called = (request.security(syminfo.tickerid, timeframe_automatic, close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off))
最美不过初阳 2025-02-04 07:12:56

问题是要使用户决定将其置于自动模式或将其置于手动模式之间。

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))

现在好!

The problem was to make the user decide between leaving it in automatic mode or putting it in manual mode.

timeframe_automatic = is a mutable variable.

And input.timeframe(timeframe_automatic) does not accept a mutable variable but just a const string.

But, request.security() accepts period mutable variable with the requirement that it be const string.

The solution I found was to separate the decisions into 3 different codes.

The 1st code I had to add a manual selector to select between Automatic or Manual code.

And a 2nd code for making decisions.

And finally, the 3rd code makes the function call.

The code looks like this, Example:

//@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))

Ok now!

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