如何使 security_lower_tf 在较短的时间内工作而不出现问题?

问题描述 投票:0回答:1

我有一个 pinescript V5 代码,它在 Daily 中运行良好

代码

//@version=5
indicator(title='test', shorttitle='test', overlay=true)


/////////////// Start security_lower_tf Daily close ///////////////
array<float> close_values = request.security_lower_tf(syminfo.tickerid, "D", close)
var float element = na

array_size = array.size(close_values)

if array_size
    last_element_index = array_size - 1
    element := array.get(close_values, last_element_index)

// shorter version
// element := array_size ? array.get(close_values, array_size-1) : na

plot (element, color=color.red)
/////////////// End security_lower_tf Daily close ///////////////



/////// Start Moving Average /////// 
fastAverage = ta.sma(close, 10)
slowAverage = ta.sma(close, 50)

plot(fastAverage, color=color.navy)
plot(slowAverage, color=color.fuchsia)

,但该指标无法在低于每日的时间范围内工作

并显示此消息

Study Error 
The chart's timeframe must be greater or
equal to the 'D' timeframe used with
'request.security_lower_tf()'.

如何修复此问题以仅在低于每日的时间范围内显示(移动平均线)?

pine-script pine-script-v5 trading forex
1个回答
0
投票

request.security_lower_tf
函数将较低的时间范围数据放入数组中。在您的示例中,您在请求中请求每日收盘价,因此您需要处于每日时间范围或更高时间范围内,否则您将使用常规
request.security
调用来获取更高时间范围数据。

将您的请求更改为较短的时间范围,下面的示例会将 5 分钟收盘价放入数组中。如果您在 30 分钟图表上,每个条形数组将有 6 个值。 (6 5 分钟收盘价为 30 分钟蜡烛)

request.security_lower_tf(syminfo.tickerid, "5", close)
© www.soinside.com 2019 - 2024. All rights reserved.