Declaring Variables correctly - best practise

Questions about MultiCharts and user contributed studies.
champski
Posts: 71
Joined: 28 Jun 2011
Has thanked: 20 times
Been thanked: 1 time

Declaring Variables correctly - best practise

Postby champski » 28 Jun 2013

Hi,

I've got a couple of questions everyone. Any help would be much appreciated.

1. When using built-in variables is it best practise to declare them instead of just calling the built-in variable directly? e.g.

Code: Select all

mp = marketposition;
2. Also, keeping in mind my signals use

Code: Select all

[IntraBarOrderGeneration=true]
should I be using intrabarpersist for variables which MAY need to be updated every tick? I see this approach as 'keeping the variable honest'
e.g.

Code: Select all

intrabarpersist MP(0);
mp = marketposition;
In the past, some of the issues I've had with signals have been caused by NOT setting them like this.

Code: Select all

intrabarpersist MP(0);
mp = marketposition;
Any thoughts?

Cheers
Champski

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

Re: Declaring Variables correctly - best practise

Postby TJ » 28 Jun 2013

1. Where do you think "mp" gets its value from?

You are using one additional computing cycle when you duplicate the variable assignment. Not that it matters with today's powerful computer, but practically speaking, it is an additional cycle.

2. Please read up on the usage of "intrabarpersist". I can't comment on your situation because I have not read your code and do not know your intention. Just remember: The computer is dumb; GIGO, the proper application of logic will always yield your desired results.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Declaring Variables correctly - best practise

Postby Andrew MultiCharts » 02 Jul 2013

1. When using built-in variables is it best practise to declare them instead of just calling the built-in variable directly? e.g.

Code: Select all

mp = marketposition;
You are using one additional computing cycle when you duplicate the variable assignment. Not that it matters with today's powerful computer, but practically speaking, it is an additional cycle.
Though TJ is right, the benefit of declaring mp = marketposition; is the access to previous value. Example:

Code: Select all

mp = marketposition;
if mp[1] <> mp then begin ...
2. Also, keeping in mind my signals use

Code: Select all

[IntraBarOrderGeneration=true]
should I be using intrabarpersist for variables which MAY need to be updated every tick? I see this approach as 'keeping the variable honest'
e.g.

Code: Select all

intrabarpersist MP(0);
mp = marketposition;
If your goal is to update a variable on every tick and access is new values, it should be intrabarpersist variable.


Return to “MultiCharts”