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 example if i want to iterate throught a list in python i would do it this way:
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?
so far what i did in pinescript is this:
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?
pinescript
also supports 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.