Pinescript中的各种变量似乎都成为了一个Series。甚至就像方法内的局部变量一样。
虚拟代码
export type FooLib
int bar
string baz
export init(int bar, string baz) =>
FooLib.new(bar, baz)
a_getter_method(FooLib id) =>
id.bar == 0
export a_setter_method(FooLib id) =>
// result get's unintentionally a series
result = a_getter_method(id)
if result
id.baz := "whatever"
if barstate.islastconfirmedhistory
// i don't wan't this to be possible!
log.info("{0}", result[1])
使用示例
foo_lib = init()
a_setter_method(foo_lib)
问题是,我的真实代码有大量变量,有时是很长的数组。存储每个计算结果似乎是相当大的负担!
变量也可以制成
simple
或 const
。但大多数时候它不起作用。
这行不通
type Foo
int bar
simple Foo foo = Foo.new(0)
这个有效
simple array<int> arr = array.new<int>(10)