[英]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.