Closing price of Tickers in adjacent Columns

Wondering if we can get Closing price of different tickers in adjacent columns. The following AFL code gives the values of ^NSEI in the third column, but not showing the same for the rest of the symbols. Any guidance will be helpful.

sym_list = "^NSEI, ^NSEBANK, RELIANCE.NS, ICICIBANK.NS, INFY.NS, ITC.NS";

Filter = 1;


for (i=0; (sym = StrExtract(sym_list, i, ','))!=""; i++) {
		
		AddColumn(Foreign(sym, "C"), sym);
	}

@cgshah, you need to remove the extra spaces!

"^NSEI,^NSEBANK,RELIANCE.NS,ICICIBANK.NS,INFY.NS,ITC.NS";

Alternatively, use the StrTrim() function

for( i = 0; (sym = StrExtract( sym_list, i, ',' ))  != ""; i++ )
{
	sym = StrTrim(sym, " ");
    AddColumn( Foreign( sym, "C" ), sym );
}
1 Like

Thank you very much @beppe. It is working well. I have modified the code to remove default columns and added separate column for date.

amibroker - tickers in adjacent columns 1

sym_list = "^NSEI, ^NSEBANK, RELIANCE.NS, ICICIBANK.NS, INFY.NS, ITC.NS";

Filter = 1;

SetOption("NoDefaultColumns", True);

AddColumn(DateTime(), "Date", formatDateTime);
for (i=0; (sym = StrExtract(sym_list, i, ','))!=""; i++) {
		sym = StrTrim(sym, " ");
		AddColumn(Foreign(sym, "C"), sym);
	}

Currently, the Filter selects from a watchlist having only one ticker. But is there any way to just run exploration on the tickers included in the AFL code?