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 / PropertyParametersReturnsDescription
Math.Abs(x)double xdoubleAbsolute value.
Math.Sqrt(x)double xdoubleSquare root.
Math.Pow(base,exp)double base, expdoublebase raised to the power of exp.
Math.Log(x)double xdoubleNatural logarithm.
Math.Exp(x)double xdoublee raised to the power x.
Math.Sin(x)double xdoubleSine (radians).
Math.Cos(x)double xdoubleCosine (radians).
Math.Floor(x)double xdoubleLargest integer ≤ x.
Math.Ceil(x)double xdoubleSmallest integer ≥ x.
Math.Round(x)double xdoubleRound to nearest integer.
Math.Min(a,b)double a, bdoubleMinimum of two values.
Math.Max(a,b)double a, bdoubleMaximum of two values.
Math.Clamp(x,lo,hi)double x, lo, hidoubleConstrain x to [lo, hi].

Array Functions

Function / PropertyParametersReturnsDescription
create_array(size)int sizedouble[]Create a zero-filled array.
length(arr)double[] arrintNumber of elements.
Array.Sum(arr)double[] arrdoubleSum of all elements.
Array.Avg(arr)double[] arrdoubleAverage of all elements.
Array.Min(arr)double[] arrdoubleMinimum element.
Array.Max(arr)double[] arrdoubleMaximum element.
Highest(arr,n)double[] arr, int ndoubleMaximum over last n bars.
Lowest(arr,n)double[] arr, int ndoubleMinimum over last n bars.
fill(arr,val)double[] arr, doublevoidFill entire array with a constant.
slice(arr,s,e)double[] arr, int s,edouble[]Extract sub-array from index s to e.
reverse(arr)double[] arrdouble[]Reversed copy.
sort(arr)double[] arrdouble[]Sorted ascending copy.

String Functions

Function / PropertyParametersReturnsDescription
String.Length(text)string textintNumber of characters.
String.Contains(text,sub)string text, subboolTrue if text contains sub.
String.Upper(text)string textstringUppercase copy.
String.Lower(text)string textstringLowercase copy.
String.Substring(text,s,n)string text, int s, nstringExtract n chars starting at s.

Logging & Alerts

Function / PropertyParametersReturnsDescription
Print(msg)string msgvoidWrite to the strategy journal.
Log.Info(msg)string msgvoidInfo-level log entry.
Log.Warn(msg)string msgvoidWarning-level log entry.
Log.Error(msg)string msgvoidError-level log entry.
Alert(msg)string msgvoidPop-up alert (live mode only).
Notify(msg)string msgvoidPush notification to mobile app (live only).
Logging exampleTDSL
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 / PropertyParametersReturnsDescription
ToString(val)any valstringConvert int, double, bool, or datetime to string.
ToDouble(text)string textdoubleParse a string to double.
ToInteger(text)string textintParse a string to int.
ToTime(text)string textdatetimeParse 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 / PropertyParametersReturnsDescription
Load(proxyName)identifiervoidActivate a sub-indicator proxy defined by a .calculate() block.
Native.Source(i.Name)indicator aliasvoidSelect a native indicator engine.
Native.Init(sym, tf)string sym, tfvoidSet symbol and timeframe context for the native engine.
Native.Parameter(…)variadicvoidPass positional parameters to the native engine.
Native.Bind(proxyName)identifiervoidBind the configured native engine to a proxy name.
Native.Fetch(index, buf)int idx, double[]voidCopy native output buffer at index into buf.
Custom.Source("file")string pathvoidLoad an external .tbc script as a source.
Custom.Init(sym, tf)string sym, tfvoidSet context for the external script.
Custom.Bind(proxyName)identifiervoidBind external script output to a proxy name.
Custom.Fetch(index, buf)int idx, double[]voidCopy external script output buffer into buf.
Chart.resume_indexintIndex of first bar needing recalculation. 0 on first run.