英文:
Pinescript v5 - How to declare float series
问题
我声明如下:
type valutaType
string valuta
float level
var arrayValute = array.new<valutaType>()
我编写了以下方法:
getLevelFromCurrency(currency) =>
var levels = array.new_float()
for item in arrayValute
if item.valuta == currency
levels := item.level
我收到以下错误信息:
变量'levels'被声明为'float[]'类型,无法将其分配给'type 'series float'的表达式
如何在getLevelFromCurrency(currency)
中将levels
声明为浮点数系列(float series),而不是浮点数数组?
我尝试了以下方法:
array.new_float()
series
我添加了一个小型测试脚本:
//@version=5
indicator("testScriptV5", precision=2, overlay=true)
type valutaType
string valuta
float[] level
var arrayValute = array.new<valutaType>()
sma200 = ta.sma(close, 200)
array.push(arrayValute, valutaType.new("EUR", sma200))
levelssss = array.new_float()
for item in arrayValute
if item.valuta == "EUR"
levelssss := item.level
plot(levelssss)
英文:
I have declare:
type valutaType
string valuta
float level
var arrayValute = array.new<valutaType>()
Wrote down this method:
getLevelFromCurrency(currency) =>
var levels = array.new_float()
for item in arrayValute
if item.valuta == currency
levels := item.level
I receive this errors:
> Variable 'levels' was declared with 'float[]' type. Cannot assign it expression of type 'series float'
>
How to declare levels in getLevelFromCurrency(currency) as float series instead array of float?
I've tried:
- array.new_float()
- series
Added a tiny test-script:
//@version=5
indicator("testScriptV5", precision=2, overlay=true)
type valutaType
string valuta
float[] level
var arrayValute = array.new<valutaType>()
sma200 = ta.sma(close, 200)
array.push(arrayValute, valutaType.new("EUR", sma200))
levelssss = array.new_float()
for item in arrayValute
if item.valuta == "EUR"
levelssss := item.level
plot(levelssss)
答案1
得分: 1
你在这里将levels
声明为一个数组:var levels = array.new_float()
。
然后你尝试将item.level
分配给它,这是不正确的。item.level
的类型是float
。
levels := item.level
。
如果您想在条件为true
时存储item.level
,您可以将其推送到您的数组中。
getLevelFromCurrency(currency) =>
var levels = array.new_float()
for item in arrayValute
if item.valuta == currency
array.push(levels, item.level)
英文:
You declare levels
as an array here : var levels = array.new_float()
.
Then you try to assign item.level
to it which is not correct. item.level
is of type float
.
levels := item.level
.
If you want to store item.level
whenever your conditions is true
, you can just push it to your array.
getLevelFromCurrency(currency) =>
var levels = array.new_float()
for item in arrayValute
if item.valuta == currency
array.push(levels, item.level)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论