Documentation/AlgoCode/Function reference

function

Lightweight reusable expression with optional parameters.

Reference/Language/Language

function name(param, ...)
  return expression

Define a small named helper with a parameter list and one return line. Parameters can be numbers, series, or true/false values. Calls can nest. A function cannot call itself. Prefer a plain assignment when you only need the condition once. No classes, loops, or generics.

Return value

Whatever the return expression produces

Note

  • Wrong argument count is a compile error, for example: 'breakout' expects 2 arguments, but got 1.
  • Recursion is not supported.

Example

function bullishTrend()
  return ema(close, 20) > ema(close, 50)

function breakout(level, buffer)
  return close > level + buffer

when bullishTrend() and breakout(previous day high, 5) and flat
  buy

See also