Pine Script数组中的历史记录引用 [英] History referencing in Pine Script arrays

查看:103
本文介绍了Pine Script数组中的历史记录引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用数组功能,该功能最近已在PineScript 4中引入,但它可能表明我不知道它的局限性,或者实现可能仍然有问题.以下非常简单的脚本说明了我所面临的问题:

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

根据我的理解, A B 数组的第一个元素都必须产生相同的图.不过, B 的图仅在所有条形上给出1.该问题肯定与历史引用运算符[]的使用有关.有人知道如何克服这种问题吗?

According to my understanding both A and the first element of B array must produce identical graphs. Nevertheless plot of B simply gives 1 on all bars. The problem is definitely related to the usage of history referencing operator []. Does anybody know how to overcome this kind of issue?

注意:为了使问题更深刻,我使此脚本尽可能简单.我正在处理的脚本要复杂得多,它以各种方式在for循环内使用数组,包括刚刚说明的一种(即,历史记录引用了op),因此使用简单变量代替数组就不会了.为我工作.

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 (i.e. history referencing op), so using simple variables in place of array simply doesn't work for me.

推荐答案

  1. 不能使用Pine的[]历史参考操作符( https://www.tradingview.com/pine-script-docs/zh-CN/v4/essential/Arrays.html?highlight=array#history-referencing )
  2. 示例的固定版本:

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

这篇关于Pine Script数组中的历史记录引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆