"Permanent" Variable

Is there any way to set a “permanent” or “global” variable which value will not be reset during execution?


  • Periodicity set to 1minute
  • Checking if close value meeting some criteria
  • If yes, this “global” variable will be added certain value (let’s say 1), then shown to the column
  • Off course as periodicity set to 1minute, this process will repeat itself until last minute of the trading day
  • So exploration will show minute line with this “global” variable (might add 1 for every minute criteria met)


Of course Jimmy. Take a look at StaticVarSet() and StaticVarSetText()

I quote:

Static variable - the variable has static duration (it is allocated when the program begins and deallocated when the program ends) and initializes it to Null unless another value is specified. Static variables allow to share values between various formulas. ARRAY static variables are supported from version 5.30 and MATRIX static variables are supported from version 6.10


Starting from version 5.80 there is a new parameter persist. If it is set to True then static variable will be stored in PersistVars.bin file when AmiBroker is closing and reloaded automatically on next startup, preserving the values of static variables between application runs). In addition to saving them automatically on exit, persistent static variables can be auto-saved at user-specified intervals using SetOption(“StaticVarAutoSave”, interval );

1 Like

Thanks Milosz, will try!

Gents, is there a way to manually clear/delete some of the static variables that were created during various AFL runs? I mean not from within the AFL code, but manually in the AB UI.

Hello @zaxxon
It is nice Question but NOT clear.

Maybe you will find the solution with your answer on the following question that I am asking below

You said “manually clear/delete some of the static variables”

How do you know, that you have some static variables that are running and you don’t need them?

My code saves lots of stuff in persistent variables as they are needed to restore state after a restart. There is a set of vars for each symbol.
Especially during the testing phase it would be nice to reset everything for a symbol and start from scratch, Hence the some, as for the others I might still want to keep the current values.

Hello @zaxxon
You can name all your Static variables beginning with some prefix, and later you will be able to easily remove some or all of your Static variables (selectively) using this prefix.

Prefix = “RsiStrategy”;

  • StaticVarSet(Prefix +name()+“Variable1”, something);
  • StaticVarSet(Prefix +name()+“Variable2”, something);
  • StaticVarSet(Prefix +name()+“Variable3”, something);

Example :
Delete/Remove only the second Variable2

StaticVarRemove(Prefix +name()+"Variable2" );

Delete/Remove all static that belong to this System

StaticVarRemove(Prefix +"*Variable*" );

Or you can Remove if the name is IBM

 If (name() == ibm)
   StaticVarRemove(Prefix +"*" );

As i know for backtesting they remove all static before the backtest start.
Please read also https://www.amibroker.com/guide/afl/staticvarinfo.html

Or as you ask for manual reset You can use parameters… why not?

if( ParamToggle(" Manual Remove specific StaticVars ?", "No|Yes" ) )
// write here all the list of the static to remove
StaticVarRemove(Prefix +"*" );
1 Like

restarting the amibroker will clear them all