When I run a simple backtest, not a custom backtest all my static variables are removed. What could be causing this? Something as simple as this is erasing my static variables, what am I missing? Thanks.
Please note that static array variable will consume 8 * (number_of_bars) bytes of memory and it won't be released until program is closed or variable is removed using StaticVarRemove().
So can i set a static variable in one afl then run a seperate afl and access the static variable created in first afl? If so, this static variable created should stay available until i exit amibroker or remove it with StaticVarRemove?
No, Backtest DOES NOT REMOVE any static variables.
Look elsewhere for your problem. Anything that happens on your side must be happening because you are doing it (and not realizing it)
Chances are you have some random code elsewhere (in some other formula, say in chart) that removes static variables.
Static variables are global (shared) and if you call StaticVarRemove ANYWHERE in ANY formula running in the background.
For example where if you have LEFTOVER of your code
staticvarset("Test",C);
in your PORTFOLIO EQUITY chart, it might REASSIGN values to static variable without you realizing what happens!
Or you might have such leftover code in your custom backtest code.
You might be also using "test" variable ELSEWHERE and assigning Null values to it, or assigning values in OTHER DATES, effectively removing the dates you are looking at in the analysis Window.
So:
CHECK all your formulas (CHARTS!) for any use of Static* functions - chances are you are overwriting in the background (use Find In Files tool to scan ALL FILES for Static word)
Make sure you are using some UNIQUE name not "test" to avoid conflict with existing code that you wrote.
StaticVarRemove was included in one of the report charts. Thank you! Since I was not running custombacktest I forgot or did not account for the fact that Report Charts were still running.