如何从系列中提取单个值?

发布于 2025-01-26 13:18:21 字数 392 浏览 2 评论 0原文

我想创建一个系列,其中每个值都标准化为系列中特定元素的值,例如最新值。

如果您尝试使用其他通用语言来使用的语法:

normalized_close = close / close[0]

结果将是1的数组,因为Pine相对于同一栏的收盘价(0偏移)的收盘价之间的比率。我想相对于最新栏的单个收盘价,在每个栏的收盘价之间获得比率。在伪代码中,它看起来像这样。

latest_close = get_value_at_index(close, 0)
normalized_close = close / latest_close

函数get_value_at_index(系列,索引)是我似乎找不到的功能。

I want to create a series in which every value is normalized to the value of a particular element in the series, for example the latest value.

If you try syntax that would work in other common languages:

normalized_close = close / close[0]

the result will be an array of 1's because Pine is taking the ratio between the closing price relative to the closing price of the same bar (0 offset). I want to get the ratio between the closing price in each bar relative to the single closing price of the latest bar. In pseudocode, it would look something like this.

latest_close = get_value_at_index(close, 0)
normalized_close = close / latest_close

Where the function get_value_at_index(series, index) is the function I can't seem to find.

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

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

发布评论

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

评论(1

天气好吗我好吗 2025-02-02 13:18:21

您可以创建array,用循环的设置其值,并在所需的任何索引中获取值。

这是一个以1000 关闭价格的索引的示例,并从3个bars获得结果:

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

// create new array
normalized_close_array = array.new_float(1000)

// append to that array
for i=1 to array.size(normalized_close_array) - 1
    array.set(normalized_close_array, i, close[i] / close)

// get the value at any index you want
value_we_want = array.get(normalized_close_array, 3)

plot(value_we_want)

You can create an array, set its values with a for loop and get the value at any index you want.

Here is an example with seeting an index with 1000 close prices and getting the result from 3 bars ago:

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

// create new array
normalized_close_array = array.new_float(1000)

// append to that array
for i=1 to array.size(normalized_close_array) - 1
    array.set(normalized_close_array, i, close[i] / close)

// get the value at any index you want
value_we_want = array.get(normalized_close_array, 3)

plot(value_we_want)

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