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...
Variable initialization and Backtesting
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Re: Variable initialization and Backtesting
Initial value is just that --- initial value.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...
ie initial value at the beginning of the time in memorial.
when you say "backtest", do you mean playback?
- TJ
- Posts: 7740
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2221 times
Re: Variable initialization and Backtesting
in playback, the variable will not be reset to initial value,Yes, playback
And it initializes the values again when im doing that, except that it's always looking 1 month back
instead, it will be whatever the value be at that moment in time.
Re: Variable initialization and Backtesting
My two cents comments. I had a similar problem
You may need to use Intrabarpersist to declare some your variables. EX:
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
You may need to use Intrabarpersist to declare some your variables. EX:
Code: Select all
intrabarpersist value2 (0),
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