Variable initialization and Backtesting

Questions about MultiCharts and user contributed studies.
HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Variable initialization and Backtesting

Postby HummerH1 » 17 Dec 2011

Hello,

When declaring a variable I initialize it let say to be 0.
My indicator is active in the chart. So when compiling it applies it automatically. And it computes the values one month back.

Then I use the backtesting features, so I go back in time and run it.
But even if i go back just ten days in time, it will always do the calculation one month back so as my variable is not initialized just at the date Ive chose.

Is it the way it should work?
I personnally expect it to be reinitialized to 0 because at the date Ive chose...

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

Re: Variable initialization and Backtesting

Postby TJ » 17 Dec 2011

Hello,

When declaring a variable I initialize it let say to be 0.
My indicator is active in the chart. So when compiling it applies it automatically. And it computes the values one month back.

Then I use the backtesting features, so I go back in time and run it.
But even if i go back just ten days in time, it will always do the calculation one month back so as my variable is not initialized just at the date Ive chose.

Is it the way it should work?
I personnally expect it to be reinitialized to 0 because at the date Ive chose...
Initial value is just that --- initial value.
ie initial value at the beginning of the time in memorial.

when you say "backtest", do you mean playback?

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: Variable initialization and Backtesting

Postby HummerH1 » 17 Dec 2011

Yes, playback
And it initializes the values again when im doing that, except that it's always looking 1 month back

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

Re: Variable initialization and Backtesting

Postby TJ » 17 Dec 2011

Yes, playback
And it initializes the values again when im doing that, except that it's always looking 1 month back
in playback, the variable will not be reset to initial value,
instead, it will be whatever the value be at that moment in time.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Variable initialization and Backtesting

Postby arjfca » 18 Dec 2011

My two cents comments. I had a similar problem

You may need to use Intrabarpersist to declare some your variables. EX:

Code: Select all

intrabarpersist value2 (0),
This declaration mode allow the variable to be sustained after each running pass. Otherwise, values are re-evaluated and assigned to the original value declared in your initialization

EX:

Var: value2 (3) ; will always have 3 value for each bars that you run your code on. Even if it is modified during your process

Var: intrabarpersist Value2 (3); Will start your running code with 3, then keep any value after being modified for your next bar evaluation ( running the code to the bar)

Hope I'm clear enough

Martin


Return to “MultiCharts”