我如何指定在 pinescript 中迭代哪个数组?
how do i specify which array to iterate in pinescript?
让我们假设 for 循环评估列表中的符号是上升趋势还是下降趋势,“i > 0”表示上升趋势,“i < 0”表示下降趋势
例如,如果我想遍历 python 中的列表,我会这样做:
uptrend = 0
downtrend = 0
list = ["AXP", "APPL", "MMM", "TSLA", "FB", "AMZN"]
for i in list:
if i > 0:
uptrend += 1
else:
downtrend += 1
如何在 pinescript 中实现相同的代码?
到目前为止,我在 pinescript 中所做的是这样的:
uptrend = 0
downtrend = 0
string[] list = array.from("AXP", "APPL", "MMM", "TSLA", "FB", "AMZN")
但是我卡在了for循环部分,因为我无法指定我来自哪个数组,在python我使用(for i in list),我用什么代替“in " 在 pinescript 中?
pinescript
也支持for .. in
.
//@version=5
indicator("My script")
var string[] list = array.from("AXP", "APPL", "MMM", "TSLA", "FB", "AMZN")
string s = ""
for i in list
s := s + i + " "
var testTable = table.new(position = position.top_right, columns = 1, rows = 1, bgcolor = color.yellow, border_width = 1)
if barstate.islast
table.cell(table_id = testTable, column = 0, row = 0, text = s)
让我们假设 for 循环评估列表中的符号是上升趋势还是下降趋势,“i > 0”表示上升趋势,“i < 0”表示下降趋势
例如,如果我想遍历 python 中的列表,我会这样做:
uptrend = 0
downtrend = 0
list = ["AXP", "APPL", "MMM", "TSLA", "FB", "AMZN"]
for i in list:
if i > 0:
uptrend += 1
else:
downtrend += 1
如何在 pinescript 中实现相同的代码?
到目前为止,我在 pinescript 中所做的是这样的:
uptrend = 0
downtrend = 0
string[] list = array.from("AXP", "APPL", "MMM", "TSLA", "FB", "AMZN")
但是我卡在了for循环部分,因为我无法指定我来自哪个数组,在python我使用(for i in list),我用什么代替“in " 在 pinescript 中?
pinescript
也支持for .. in
.
//@version=5
indicator("My script")
var string[] list = array.from("AXP", "APPL", "MMM", "TSLA", "FB", "AMZN")
string s = ""
for i in list
s := s + i + " "
var testTable = table.new(position = position.top_right, columns = 1, rows = 1, bgcolor = color.yellow, border_width = 1)
if barstate.islast
table.cell(table_id = testTable, column = 0, row = 0, text = s)