简体   繁体   English

Pine 脚本中的历史引用 arrays

[英]History referencing in Pine Script arrays

I have been trying to use array feature, which recently has been introduced in PineScript 4, but it seams that either I'm not aware of its limitations, or, possibly the implementation is still buggy.我一直在尝试使用最近在 PineScript 4 中引入的数组功能,但它接缝表明我没有意识到它的局限性,或者可能实现仍然有问题。 The problem I'm faced with is illustrated by the following very simple script:以下非常简单的脚本说明了我面临的问题:

//@version=4

study("TEST")

// A is basically the same as bar_index+1, and it is plotted as expected
A=0
A:=nz(A[1])+1

// the same thing implemented using arrays nevertheless doesn't work as expected
B=array.new_float(1,0)
array.set(B,0,nz(array.get(B,0)[1])+1)

plot(A,color=color.red)
plot(array.get(B,0),color=color.yellow)

According to my understanding both A and the first element of B array must produce identical graphs.根据我的理解, AB数组的第一个元素都必须生成相同的图形。 Nevertheless plot of B simply gives 1 on all bars.尽管如此, B的 plot 只是在所有柱上给出 1。 The problem is definitely related to the usage of history referencing operator [].问题肯定与历史引用运算符 [] 的使用有关。 Does anybody know how to overcome this kind of issue?有谁知道如何克服这种问题?

Note : I've made this script as simple as possible in order to get to the guts of the problem.注意:为了深入了解问题的本质,我已使此脚本尽可能简单。 The script I'm working on is much more complex, and it uses arrays inside for-loops in various ways, including the one that has been just illustrated (ie history referencing op), so using simple variables in place of array simply doesn't work for me.我正在处理的脚本要复杂得多,它以各种方式在 for 循环中使用 arrays,包括刚刚说明的那个(即历史引用操作),所以使用简单变量代替数组根本不会'不适合我。

  1. Past instances of array id's or elements cannot be referenced directly using Pine's [ ] history-referencing operator ( https://www.tradingview.com/pine-script-docs/en/v4/essential/Arrays.html?highlight=array#history-referencing )不能使用 Pine 的 [ ] 历史引用运算符直接引用数组 ID 或元素的过去实例 ( https://www.tradingview.com/pine-script-docs/en/v4/essential/Arrays.html?highlight=array#历史参考
  2. Fixed version of your example:您的示例的固定版本:
//@version=4

study("TEST")

// A is basically the same as bar_index+1, and it is plotted as expected
A=0
A:=nz(A[1])+1

// the same thing implemented using arrays nevertheless doesn't work as expected
var B=array.new_float(1,0)
array.set(B,0,nz(array.get(B,0))+1)

plot(A,color=color.red)
plot(array.get(B,0),color=color.yellow)

I totally agree with you.我完全同意你的看法。 I have problem with array historical refrencing too, which never solve by replacing of [].我也有数组历史引用的问题,无法通过替换 [] 来解决。 I rewrote my script without array and it's worked perfectly.我在没有数组的情况下重写了我的脚本,它运行得很好。 Alas that was too long script but worked correctly.唉,那是太长的脚本,但工作正常。 I think Pine staff should revise on arrays codes.我认为 Pine 工作人员应该修改 arrays 代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM