Bentrix Docs
HomePricingDashboard

Assay reference: constructs

The language’s constructs — versions, declarations, history, control flow, functions, types — each with its disposition and the whole script Bentrix’s own census runs to prove it.

//@version=5

runs

Version 5 runs

//@version=5
indicator("t")
plot(close)

//@version=6

runs

Version 6 runs

//@version=6
indicator("t")
plot(close)

//@version=4

runs

Version 4 runs, read onto version 5

//@version=4
study("t")
plot(sma(close, 5))

//@version=1 to 3

runs

Versions 1 to 3 run, read onto version 5

//@version=3
study("t")
plot(close, color=red, style=area)

no version header

runs

Read as version 1, as the language reads it

study("t")
plot(sma(close, 5), color=blue)

a later version

refused

Refused by version

//@version=7
indicator("t")
plot(close)

declaration with =

runs

A series, declared afresh on every bar

//@version=5
indicator("t")
x = close
plot(x)

typed declaration

runs

A declared type; na needs one

//@version=5
indicator("t")
float x = na
x := close
plot(x)

qualified declaration

runs

Const, simple, series

//@version=5
indicator("t")
const int n = 3
simple float k = 2.0
series float s = close * k
plot(s + n)

var

runs

Initialised once, kept across bars

//@version=5
indicator("t")
var float acc = 0.0
acc += close
plot(acc)

varip

runs

Kept across the ticks of the forming bar too

//@version=5
indicator("t")
varip int ticks = 0
ticks += 1
plot(ticks)

:= and the compound assignments

runs

Reassignment

//@version=5
indicator("t")
x = 1.0
x := 2.0
x += 1
x -= 1
x *= 2
x /= 2
x %= 3
plot(x)

history operator

runs

A value n bars ago; na beyond the history

//@version=5
indicator("t")
n = 2
plot(close[1] + close[n] + (high - low)[1])

tuple declaration

runs

A function's several results

//@version=5
indicator("t")
f() => [close, open]
[a, b] = f()
plot(a - b)

ternary

runs

Cond ? A: b

//@version=5
indicator("t")
plot(close > open ? 1 : 0)

if as statement and value

runs

Else if, else

//@version=5
indicator("t")
x = if close > open
    1
else if close < open
    -1
else
    0
plot(x)

switch

runs

On a value or on conditions, with a default

//@version=5
indicator("t")
m = "a"
x = switch m
    "a" => 1
    => 2
y = switch
    close > open => 1
    => 0
plot(x + y)

for to by

runs

An inclusive count, up or down

//@version=5
indicator("t")
s = 0.0
for i = 0 to 4 by 2
    s += close[i]
plot(s)

for in

runs

Over an array's items, or its indices and items

//@version=5
indicator("t")
a = array.from(1.0, 2.0)
s = 0.0
for v in a
    s += v
for [i, v] in a
    s += i * v
plot(s)

while, break, continue

runs

A loop on a condition

//@version=5
indicator("t")
i = 0
while true
    i += 1
    if i < 3
        continue
    break
plot(i)

function

runs

Single- and multi-line; each call site keeps its own state

//@version=5
indicator("t")
f(x) => x * 2
g(x, n = 2) =>
    y = x + n
    y * 2
plot(f(close) + g(close))

method

runs

Called on its first parameter's type

//@version=5
indicator("t")
method twice(float self) => self * 2
x = close
plot(x.twice())

user type

runs

Fields with defaults; objects are references

//@version=5
indicator("t")
type P
    float x = 1.0
    int n
var P p = P.new()
p.x := close
q = p.copy()
plot(q.x)

enum

runs

Named members with titles

//@version=6
indicator("t")
enum M
    fast = "Fast"
    slow
m = input.enum(M.fast, "Mode")
plot(m == M.fast ? 1 : 0)

array<T>

runs

Typed arrays and their methods

//@version=5
indicator("t")
array<float> a = array.new<float>(0)
a.push(close)
plot(a.size())

lazy and/or (version 6)

runs

The right side runs only when it decides

//@version=6
indicator("t")
plot(close > 0 and open > 0 ? 1 : 0)

numbers as conditions (version 5)

runs

A non-zero number is true in version 5; version 6 refuses it

//@version=5
indicator("t")
x = 1
plot(x ? 1 : 0)

export

runs

Accepted and ignored: nothing is exported from an indicator

//@version=5
indicator("t")
export f(x) => x
plot(f(close))

import

runs

A library from the person's own indicators folder, by the name it declares; nothing is fetched

//@version=5
indicator("t")
import someone/lib/1 as lib
plot(close)

matrix<T>

runs

A reference, its elements row by row

//@version=5
indicator("t")
m = matrix.new<float>(2, 2, 0.0)
m.set(0, 0, close)
plot(m.get(0, 0))

map<K, V>

runs

A reference, its pairs in the order first put

//@version=5
indicator("t")
m = map.new<string, float>()
m.put("a", close)
plot(m.get("a"))

strategy()

runs

A strategy script

//@version=5
strategy("t")
plot(close)

drawings

runs

Lines, labels, boxes and tables drawn in the study's pane

//@version=5
indicator("t")
l = line.new(bar_index, low, bar_index, high)
plot(close)

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed