StaticVarSet
|
Miscellaneous functions |
SYNTAX | StaticVarSet( ''varname'', value, persistent = False, compressionMode = cmDefault ) |
RETURNS | NUMBER |
FUNCTION | Sets the value of static variable. Returns 1 on success 0 on failure.
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 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(). Persistency 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 ); Compression Starting from version 6.10 there is a new parameter compressionMode that decides whenever given variable will be compressed or not.By default only persistent static variables will be compressed (cmDefault). You can turn it off completely compressionMode = cmNever, or turn it on for persitent and non-persistent variables using compressionMode = cmAlways Compression is done by removing repeated values from the sequence as repeated values are restored when doing StaticVarGet. Compression is NOT compatible with non-aligned mode of StaticVarGet. If compressed array is retrieved by StaticVarGet with align=False, then repeated values found in original array would not be retrieved. Turning compression on slows down StaticVarSet (as it needs to do some extra processing), but does not affect performance of other functions, so StaticVarGet is equally fast with or without compression.. Static variables vs composites Static arrays can be even 100 faster than AddToComposite/Foreign, however these two are not strictly equivalent. There are following limitations / differences of static arrays as compared to Foreign/AddToComposite:
|
EXAMPLE | //
start of the formula: |
SEE ALSO | StaticVarSetText() function , StaticVarGet() function |
The StaticVarSet function is used in the following formulas in AFL on-line library:
See updated/extended version on-line.