Newb question  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
joebone
Posts: 175
Joined: 05 Sep 2018
Has thanked: 53 times
Been thanked: 4 times

Newb question

Postby joebone » 14 May 2020

if a variable is initiated inside a Begin / End section of a script and that section never Begins...

Does that variable get initialized?

what value is in that variable if it never gets initialized?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Newb question

Postby JoshM » 15 May 2020

if a variable is initiated inside a Begin / End section of a script and that section never Begins...

Does that variable get initialized?

what value is in that variable if it never gets initialized?
It's not possible to make a variable without also initialising it at the same time.

To make a variable we use the `Variable`, `Variables`, `Var`, or `Vars` statement (they are are the same) like this:

Code: Select all

Variables: chartHigh(0);
This variable is initialised with a default value of `0`.

If we use `chartHigh` in a `once`-`begin` block, the variable still keeps its zero value.

In comparison with other programming languages, MultiCharts PowerLanguage doesn't have uninitialised variables.

User avatar
joebone
Posts: 175
Joined: 05 Sep 2018
Has thanked: 53 times
Been thanked: 4 times

Re: Newb question

Postby joebone » 15 May 2020

if a variable is initiated inside a Begin / End section of a script and that section never Begins...

Does that variable get initialized?

what value is in that variable if it never gets initialized?
It's not possible to make a variable without also initialising it at the same time.

To make a variable we use the `Variable`, `Variables`, `Var`, or `Vars` statement (they are are the same) like this:

Code: Select all

Variables: chartHigh(0);
This variable is initialised with a default value of `0`.

If we use `chartHigh` in a `once`-`begin` block, the variable still keeps its zero value.

In comparison with other programming languages, MultiCharts PowerLanguage doesn't have uninitialised variables.
Thanks very much

Mydesign
Posts: 177
Joined: 15 Feb 2017
Has thanked: 32 times
Been thanked: 39 times

Re: Newb question

Postby Mydesign » 20 May 2020

It's not possible to make a variable without also initialising it at the same time..
Except if you use "Value1", "Value2", etc. as variable name, then you don't need to declare them.

User avatar
joebone
Posts: 175
Joined: 05 Sep 2018
Has thanked: 53 times
Been thanked: 4 times

Re: Newb question

Postby joebone » 20 May 2020

It's not possible to make a variable without also initialising it at the same time.
Thanks for Reply

One Follow up,

Code: Select all

value1 = 0 if value1 = 1 then Begin Vars: Special_Index(0); Special_Index = 100; End;
This is kinda what I was thinking about. I had something like this in a script I was making and it seemed to be okay to use Special_Index in a calculation outside of the Begin/End even if the Begin End never triggered.

Just wanted to make sure that I was understanding right that when you initialize a variable even in a Begin section that never begins, It will be initialized.

Thanks

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Newb question

Postby TJ » 20 May 2020

When you compile a study, MultiCharts would parse the codes and collect all the declarations.
The variables are initialized at compilation, not when you run the indicator.

User avatar
joebone
Posts: 175
Joined: 05 Sep 2018
Has thanked: 53 times
Been thanked: 4 times

Re: Newb question  [SOLVED]

Postby joebone » 20 May 2020

When you compile a study, MultiCharts would parse the codes and collect all the declarations.
The variables are initialized at compilation, not when you run the indicator.
Awesome, Thanks TJ


Return to “MultiCharts”