-
Notifications
You must be signed in to change notification settings - Fork 15
Miscellaneous Functions
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>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.
amiStaticVarSet("ORDER_COUNT", 1);
// Saves a value of 1 in a static variable whose name is prefixed with chart symbol and chart id.| Parameter | Type | Description |
|---|---|---|
| key | string | key or name for static variable |
| value | number | the numeric value to be stored in static variable |
Retrieves numeric value stored in a static variable; whose value was saved using amiStaticVarSet function.
orderCount = amiStaticVarGet("ORDER_COUNT");
// Returns the static value stored by key "ORDER_COUNT"| Parameter | Type | Description |
|---|---|---|
| key | string | key or name of static variable |
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.
amiStaticVarSetText("TRADING_ACCOUNT", "ABC123");
// Saves a value of "ABC123" in a static variable whose name is prefixed with chart symbol and chart id.| Parameter | Type | Description |
|---|---|---|
| key | string | key or name for static variable |
| value | string | the text value to be stored in static variable |
Retrieves text value stored in a static variable; whose value was saved using amiStaticVarSetText function.
tradingAccount = amiStaticVarGetText("TRADING_ACCOUNT");
// Returns the static value stored by key "TRADING_ACCOUNT"| Parameter | Type | Description |
|---|---|---|
| key | string | key or name of static variable |