No Result from BackTest due to a lot of StaticVarGet/StaticVarSet : is it possible?

Hi

I write code for backtesting, but I use plenty of static variables within code both StaticVarGet and StaticVarSet
In addition, I use lots of StaticVarGet in a custom backtest as well.

The figure below I show some part of my code with StaticVarGet/StaticVarSet along with user them in CBT.
staticVAr1

staticVAr2

The big problem is that I can often backtest successfully, but in many times my backtest appears no result despite the same code.

staticVAr3
My Workaround has a few ways.
For example I try to change robotname variable as above figure , Backtest is ok again but not every time.

The other way, I try to close program and reopen again and run backtest again. sometime is ok but sometime show no result.

In a strange case, I take a break 10-15 minute from Amibroker , after that I try clicking back test again , I can backtest, the result show absolutely.

However, I notice that If there is no StaticVarGet/StaticVarSet in alf code, I always run backtest correctly every time. this problem doesn't occure certainly.

I suspect that many StaticVarGet/StaticVarSet cause no result in backtest in many times.

What is the cause for this issue??

This problem is hardly driving me crazy because I don't have any solution to deal with it.

Thank you for any help.

Pongthorn.

Use StaticVarInfo("totalmemory") to find out... but anyway if you ran out of memory you would probably get crash.
More likely is that your code is written incorrectly so it depends on previous runs (due to incorrect initialization of static variables).

I will check my code.
I have 2 questions.

  1. how to deal with ran out of memory problem , for this case , is it possible for me in case I take a break 10-15 minute from Amibroker , after that I try clicking back test again , it can run back test .
  2. "written incorrectly so it depends on previous runs (due to incorrect initialization of static variables)." please clarify this recommendation.
    I am interested in the incorrect initialization of static variables issue.

First do the check and show the results you got. Also use the code below and see if that helps.

if( Status("stocknum") == 0 )
{  
 StaticVarRemove("*");
}
1 Like