Is there a way to define multiple variables at once in one line?

in python, I can say:

A, B = 1, 2

Is there a way to do this in Amibroker?

Thank you for the help

Sure, but AFL is not Python. If you want to use any analogies you should start from C or Javascript.
So it would be

A = B = 1; // two variables at once

that of course is giving them same value.

If you want different values, you can use:

B = 1 + A = 1; // creative but NOT recommended way

But really, why not use the simplest most obvious way:

A = 1; B = 2;

Thank you for your reply. Depending what you are trying to do, sometimes the simplest and most obvious way is to write:

(A,B) = (1,2);

instead of
A=1; B=2;

I am actually NOT trying to write (A, B) = (1, 2); this is just an example for simplicity. I am using "iif" statements to define certain parameters which are individual to each instrument in a list.

For example:

Instead of writing:
A =
iif(Name() == "XYZ" , 20,
iif(Name() == "ABC" , 21,
27));

B =
iif(Name() == "XYZ" , 5,
iif(Name() == "ABC" , 6,
8));

I would like to write:

(A, B) =
iif(Name() == "XYZ" , (20, 5),
iif(Name() == "ABC" , (21, 6),
(27,8)));

Since in this situation it is the simplest most obvious way to do it. I am inferring that this is not possible in Amibroker?

Thank you for your patience and helpful assistance even though it must sometimes be frustrating interacting with lowly peasants asking silly questions.

Instead of thinking up some weird constructs, you need to learn existing ones.

You should use switch statement instead.

switch( Name() )
{
   case "XYZ": A = 20; B = 5; break;
   case "ABC": A = 21; B = 6; break;
}

The other solution is obviously if-else statement (NOT to be confused with IIF function that you used in your formula)

if( Name() == "XYZ" ) { A = 20; B = 5; }
if( Name() == "ABC" ) { A = 21; B = 6; }

For large number of cases switch statement is preferred way.

1 Like

Why do you believe this type of language is appropriate?

This (and many other examples from some of your previous posts) is exactly why forum members don't reply to your requests for assistance!

How do you not see that?

1 Like

Thank you for setting me straight @TrendSurfer

Thank you @tomasz! Much appreciated.

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