[英]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 中(对于列表中的我),我在 pinescript 中使用什么来代替“in”?
pinescript
还支持 for..in 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.