Miscellaneous Functions - Pritesh-Mhatre/amibroker-library GitHub Wiki
Miscellaneous utility functions for AmiBroker. These functions are available in misc-util.afl. To use these functions, add following line at the top of your afl:
#include <misc-util.afl>
Functions
amiStaticVarSet
Stores numeric value in static variable by preparing a unique chart & symbol specific key. AmiBroker provides a built-in function StaticVarSet for storing data in static variables. However these variables are shared across charts. So value saved by one chart can be read/modified by another chart. This causes a lot of problems when users run same strategy code that stores data in static variable across many symbols. This is where amiStaticVarSet function comes to rescue, it automatically adds a prefix to variable name. That prefix is made using chart symbol and chart id. It makes variable name unique, and hence safe from multiple executions of same strategy code.
Example
amiStaticVarSet("ORDER_COUNT", 1);
// Saves a value of 1 in a static variable whose name is prefixed with chart symbol and chart id.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | key or name for static variable |
value | number | the numeric value to be stored in static variable |
amiStaticVarGet
Retrieves numeric value stored in a static variable; whose value was saved using amiStaticVarSet function.
Example
orderCount = amiStaticVarGet("ORDER_COUNT");
// Returns the static value stored by key "ORDER_COUNT"
Parameters
Parameter | Type | Description |
---|---|---|
key | string | key or name of static variable |
amiStaticVarSetText
Stores text value in static variable by preparing a unique chart & symbol specific key. AmiBroker provides a built-in function StaticVarSetText for storing data in static variables. However these variables are shared across charts. So value saved by one chart can be read/modified by another chart. This causes a lot of problems when users run same strategy code that stores data in static variable across many symbols. This is where amiStaticVarSetText function comes to rescue, it automatically adds a prefix to variable name. That prefix is made using chart symbol and chart id. It makes variable name unique, and hence safe from multiple executions of same strategy code.
Example
amiStaticVarSetText("TRADING_ACCOUNT", "ABC123");
// Saves a value of "ABC123" in a static variable whose name is prefixed with chart symbol and chart id.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | key or name for static variable |
value | string | the text value to be stored in static variable |
amiStaticVarGetText
Retrieves text value stored in a static variable; whose value was saved using amiStaticVarSetText function.
Example
tradingAccount = amiStaticVarGetText("TRADING_ACCOUNT");
// Returns the static value stored by key "TRADING_ACCOUNT"
Parameters
Parameter | Type | Description |
---|---|---|
key | string | key or name of static variable |