Docs / Standard Library
Standard Library
Math, array manipulation, string utilities, logging, type conversion, and indicator orchestration — all built into the language with no imports required.
Math.*
| Function / Property | Parameters | Returns | Description |
|---|
Math.Abs(x) | double x | double | Absolute value. |
Math.Sqrt(x) | double x | double | Square root. |
Math.Pow(base,exp) | double base, exp | double | base raised to the power of exp. |
Math.Log(x) | double x | double | Natural logarithm. |
Math.Exp(x) | double x | double | e raised to the power x. |
Math.Sin(x) | double x | double | Sine (radians). |
Math.Cos(x) | double x | double | Cosine (radians). |
Math.Floor(x) | double x | double | Largest integer ≤ x. |
Math.Ceil(x) | double x | double | Smallest integer ≥ x. |
Math.Round(x) | double x | double | Round to nearest integer. |
Math.Min(a,b) | double a, b | double | Minimum of two values. |
Math.Max(a,b) | double a, b | double | Maximum of two values. |
Math.Clamp(x,lo,hi) | double x, lo, hi | double | Constrain x to [lo, hi]. |
Array Functions
| Function / Property | Parameters | Returns | Description |
|---|
create_array(size) | int size | double[] | Create a zero-filled array. |
length(arr) | double[] arr | int | Number of elements. |
Array.Sum(arr) | double[] arr | double | Sum of all elements. |
Array.Avg(arr) | double[] arr | double | Average of all elements. |
Array.Min(arr) | double[] arr | double | Minimum element. |
Array.Max(arr) | double[] arr | double | Maximum element. |
Highest(arr,n) | double[] arr, int n | double | Maximum over last n bars. |
Lowest(arr,n) | double[] arr, int n | double | Minimum over last n bars. |
fill(arr,val) | double[] arr, double | void | Fill entire array with a constant. |
slice(arr,s,e) | double[] arr, int s,e | double[] | Extract sub-array from index s to e. |
reverse(arr) | double[] arr | double[] | Reversed copy. |
sort(arr) | double[] arr | double[] | Sorted ascending copy. |
String Functions
| Function / Property | Parameters | Returns | Description |
|---|
String.Length(text) | string text | int | Number of characters. |
String.Contains(text,sub) | string text, sub | bool | True if text contains sub. |
String.Upper(text) | string text | string | Uppercase copy. |
String.Lower(text) | string text | string | Lowercase copy. |
String.Substring(text,s,n) | string text, int s, n | string | Extract n chars starting at s. |
Logging & Alerts
| Function / Property | Parameters | Returns | Description |
|---|
Print(msg) | string msg | void | Write to the strategy journal. |
Log.Info(msg) | string msg | void | Info-level log entry. |
Log.Warn(msg) | string msg | void | Warning-level log entry. |
Log.Error(msg) | string msg | void | Error-level log entry. |
Alert(msg) | string msg | void | Pop-up alert (live mode only). |
Notify(msg) | string msg | void | Push notification to mobile app (live only). |
Init() { Print("Strategy started on " + Symbol()); }
Tick() {
double dd = (Account.Balance() - Account.Equity()) / Account.Balance() * 100.0;
if (dd > 5.0) { Log.Warn("Drawdown: " + ToString(dd) + "%"); }
if (Env.IsLive() && dd > 10.0) { Notify("Drawdown alert: " + ToString(dd) + "%"); }
}
Type Conversions
| Function / Property | Parameters | Returns | Description |
|---|
ToString(val) | any val | string | Convert int, double, bool, or datetime to string. |
ToDouble(text) | string text | double | Parse a string to double. |
ToInteger(text) | string text | int | Parse a string to int. |
ToTime(text) | string text | datetime | Parse an ISO-format datetime string. |
Orchestration Functions
These wire up sub-indicators inside Init(). Available only at the top level of a Strategy or Indicator script.
| Function / Property | Parameters | Returns | Description |
|---|
Load(proxyName) | identifier | void | Activate a sub-indicator proxy defined by a .calculate() block. |
Native.Source(i.Name) | indicator alias | void | Select a native indicator engine. |
Native.Init(sym, tf) | string sym, tf | void | Set symbol and timeframe context for the native engine. |
Native.Parameter(…) | variadic | void | Pass positional parameters to the native engine. |
Native.Bind(proxyName) | identifier | void | Bind the configured native engine to a proxy name. |
Native.Fetch(index, buf) | int idx, double[] | void | Copy native output buffer at index into buf. |
Custom.Source("file") | string path | void | Load an external .tbc script as a source. |
Custom.Init(sym, tf) | string sym, tf | void | Set context for the external script. |
Custom.Bind(proxyName) | identifier | void | Bind external script output to a proxy name. |
Custom.Fetch(index, buf) | int idx, double[] | void | Copy external script output buffer into buf. |
Chart.resume_index | — | int | Index of first bar needing recalculation. 0 on first run. |