Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

A-Z Index | Category Index |

StaticVarSet
- sets the value of static variable

Miscellaneous functions
(AFL 2.60)


SYNTAX StaticVarSet( ''varname'', value )
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 now supported (version 5.30 and above).

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().

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:
a) static array variables store only as many bars as there are currently in use by given chart (so they do not affect QuickAFL in any way). This is different that AddToComposite that forces usage and store of all bars.
b) static array variables work best if you read them using the same interval as they were written to. I.e when you create static array variables using 5-minute chart, for best results read them in some other 5-minute chart. Reading in different intervals is possible, but subject to limitations of timestamping (see below)
c) when you read static variable in a different interval that it was originally stored, static variables perform padding/synchronization and time compression/decompression automatically in a similar way as foreign, however Foreign compresses data always from base-time interval, while static variables operate on previously stored interval, hence result may differ. For example, if previously stored data was in daily interval, and you read such static variable in intraday chart, you will see essentially flat lines for each day, representing static data from daily interval.
d) static array variables do not work well for non-time based intervals (tick/n-volume/n-tick) because timestamps in those intervals may not be unique (i.e. several bars may have same time stamp), so time synchronization is not reliable.
e) static array variables are little slower than normal AFL variables, so for best performance, use read-once, write-once paradigm, using temporary normal variable for any processing during formula execution, like this:

EXAMPLE // start of the formula:
temp =
StaticVarGet("mystaticarray" );

// now perform all necessary calculations using temp variable

temp =
Nz(temp) + C/2;
...

// at the end of the formula store to static
StaticVarSet("mystaticarray", temp );
SEE ALSO StaticVarSetText() function , StaticVarGet() function

References:

The StaticVarSet function is used in the following formulas in AFL on-line library:


 


About | Privacy | Terms of Use | Contact information
Copyright © 2003 AMIBROKER.COM