OK, guys I see you don’t get it.
This functionality will likely be hidden in next release because I am tired explaining that over and over.
I wrote about this already TWICE.
Declared static variable is READ from global (shared) memory at the declaration time and written back to global memory when your formula finishes.
Inside the formula you are operating on copy.
In contrast to that StaticVar* functions operate directly on global memory.
// here you tell that _myvar will be static
// what it really does is read "my_prefix_myvar" static variable
// and put it in _myvar variable (let us say it is 0)
// from now on _myvar is basically "normal" variable from execution point of view
_myvar++; // you are modifying _myvar which is local copy of the variable, will be 1
// (it is marked as "dirty") internally
StaticVarGet("my_prefix_myvar"); // this would access GLOBAL memory, NOT the local copy, so it will get 0 (not 1)
StaticVarRemove( "my_prefix_myvar" ); // you are removing from GLOBAL memory
// but you are NOT touching _myvar at all because it is treated as normal variable
// then we arrive at the end of the formula
// and AmiBroker would write BACK the local copy _myvar to GLOBAL memory
// so it will store 1 into "my_prefix_myvar"
StaticVar* functions operate on GLOBAL memory. But any declared static variable is WRITTEN
to global memory when formula execution FINISHES. So basically the fact that you removed from global store does not matter because it will write back modified values anyway.
Moral story is:
DO NOT MIX / DO NOT CALL StaticVar functions on declared static variables within SAME formula, as they are operating on different memories*
If you want to reset declared static variable do NOT call StaticVarRemove. Just assign 0 (or Null) instead:
_x = Null; // THIS should be done instead of StaticVarRemove
_x = 0; // Or this
Use StaticVar** functions on variables that were NOT declared WITHIN given formula.