Loop to add columns via list

Hi, I searched throughout the forum and couldn't find an answer to this question. How would I create a list of variables I'd like to create a column in an exploration and add all those variables to columns? I can figure out how to do it via a backtest using this for statement:

VariableCsv = "breakoutDirection,BuyLimitPrice";
        
for (item = 0; (metric = StrExtract(VariableCsv, item)) != ""; item++) {
}

But how should I do this for adding columns in an exploration to add the same variables as columns? I've come up with something like this but would need the eval funciton to read a string as a variable. And I try to avoid Eval.

for (item = 0; (metric = StrExtract(VariableCsv, item)) != ""; item++) 
{
	AddColumn ( VarGetText(metric), metric);
}

That above is obviously wrong but how would I do it? Thanks in advance for any help!

@finith, here is an example - I think you should use the VarGet() to retrieve the variables values:

// fill the arrays with some random values for the example
breakoutDirection = iif( random() < 0.5, 0, 1 );
BuyLimitPrice = random() * 100;

VariableCsv = "breakoutDirection,BuyLimitPrice";

Filter = 1;

for( item = 0; ( metric = StrExtract( VariableCsv, item ) ) != ""; item++ )
{
    label = metric;
    value = VarGet( label );
    AddColumn( value, label );
}
1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.