简体   繁体   English

我如何指定在 pinescript 中迭代哪个数组?

[英]how do i specify which array to iterate in pinescript?

let's pretend that the for loop evaluate if the symbol(s) in the list is in uptrend or downtrend, "i > 0" means uptrend and " i < 0" means downtrend让我们假设 for 循环评估列表中的符号是上升趋势还是下降趋势,“i > 0”表示上升趋势,“i < 0”表示下降趋势

for example if i want to iterate throught a list in python i would do it this way:例如,如果我想遍历 python 中的一个列表,我会这样做:

uptrend = 0
downtrend = 0

list = ["AXP", "APPL", "MMM", "TSLA", "FB", "AMZN"]

for i in list:
    if i > 0:
        uptrend += 1

    else:
        downtrend += 1

how do i achieve this same code in pinescript?我如何在 pinescript 中实现相同的代码?

so far what i did in pinescript is this:到目前为止,我在 pinescript 中所做的是:

uptrend = 0
downtrend = 0

string[] list = array.from("AXP", "APPL", "MMM", "TSLA", "FB", "AMZN")

but i am stuck on the for loop part because i cannot specify which array the i is from, in python i use (for i in list), what do i use in the place of "in" in pinescript?但我被困在 for 循环部分,因为我无法指定我来自哪个数组,在我使用的 python 中(对于列表中的我),我在 pinescript 中使用什么来代替“in”?

pinescript also supports for.. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM