Bentrix Docs
HomePricingDashboard

JavaScript: indicators and scripts

Every method of client.indicator in the JavaScript SDK.

ideBoard#

Read or arrange the Assay IDE's board · tool ide_board

scope: labplan: freesince 3.14.0

The board of the script in front: where each statement's cluster stands, laid out by hand, kept beside the script in the indicators folder and never in its text. Read answers it; place moves one statement's cluster; tidy lays them all again in the text's order; forget deletes the arrangement. A view act, as a person's drag of a cluster's body is: no byte of the script changes. The script must be saved into the indicators folder.

Declaration

client.indicator
ideBoard(args: { action: string; index?: number; x?: number; y?: number }): Promise<any>

Parameters

NameTypeWhat it is
actionstringrequiredread answers the arrangement; place puts statement index (from 0, in the text's order) at x, y; tidy lays every statement again in the text's order; forget deletes the arrangement.
indexnumberoptional
xnumberoptional
ynumberoptional

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

What the tool's description says.

Example

await client.indicator.ideBoard({ action: "…" })

ideEdit#

Set the text in the Assay IDE · tool ide_edit

scope: labplan: freesince 1.16.0

Sets the whole text of the tab in front of the Assay IDE, as typing does: checked at once, one entry the person's Ctrl+Z takes back, nothing saved (indicator_install saves). Answers the IDE as ide_state does, with the new findings.

Declaration

client.indicator
ideEdit(args: { source: string }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe whole new text of the tab in front.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the IDE as ide_state does, with the new findings.

Example

await client.indicator.ideEdit({ source: "…" })

ideGraph#

Read the Assay IDE's graph · tool ide_graph

scope: readplan: freesince 3.14.0

Answers the sheet of the tab in front of the Assay IDE: a row per statement with its own line number and the kind of thing it is, and inside each row the nodes it draws, each with its kind, its label and the lines its text stands on. The same sheet the window draws, read the same way a person reads it. Writes nothing.

Declaration

client.indicator
ideGraph(): Promise<any>

It takes no arguments.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the sheet of the tab in front of the Assay IDE: a row per statement with its own line number and the kind of thing it is, and inside each row the nodes it draws, each with its kind, its label and the lines its text stands on.

Example

await client.indicator.ideGraph()

ideGraphEdit#

Make a gesture on the Assay IDE's graph · tool ide_graph_edit

scope: labplan: freesince 3.14.0

Makes one gesture on the sheet of the tab in front, exactly as a person's press or drag makes it: written into the text by the same function, one entry the person's Ctrl+Z takes back, checked as typing is, nothing saved. A gesture the sheet refuses is answered with its sentence and changes nothing. Answers the IDE as ide_state does.

Declaration

client.indicator
ideGraphEdit(args: { gesture: unknown }): Promise<any>

Parameters

NameTypeWhat it is
gestureunknownrequiredOne gesture of the sheet, as ide_graph's rows and nodes name the text: {"SetLiteral": {"at": span, "value": "20"}}, {"Wire": {"from": span, "to": span, "cast": null}}, {"AddRow": {"after": span, "text": "…"}}, {"MoveRow": …}, {"DeleteRow": …}, {"WrapIn": {"first": span, "last": span, "with": "If"}}, {"Extract": …} and the rest; a span is {"start": {"line": l, "col": c}, "end": {…}} exactly as ide_graph answers it.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the IDE as ide_state does.

Example

await client.indicator.ideGraphEdit({ gesture: "…" })

ideOpen#

Open a script in the Assay IDE · tool ide_open

scope: labplan: freesince 1.16.0

Opens the Assay IDE on a script of the indicators folder by its file name, brought to the front if a tab holds it already, or on a new script's text in a new tab, not saved. Answers the IDE as ide_state does.

Declaration

client.indicator
ideOpen(args: { file?: string; source?: string }): Promise<any>

Parameters

NameTypeWhat it is
filestringoptionalA script of the indicators folder by its file name (mean.assay), brought to the front if a tab holds it already. Give this or source.
sourcestringoptionalOr a new script's whole text, in a new tab, not saved.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the IDE as ide_state does.

Example

await client.indicator.ideOpen()

ideState#

Read the Assay IDE · tool ide_state

scope: readplan: freesince 1.16.0

Answers whether the Assay IDE is open, its tabs (each tab's number, name, whether it is unsaved and whether it is in front, and the tab shown beside it in a split), and the tab in front: its name, file, text, findings and stops with their conditions. Writes nothing.

Declaration

client.indicator
ideState(): Promise<any>

It takes no arguments.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers whether the Assay IDE is open, its tabs (each tab's number, name, whether it is unsaved and whether it is in front, and the tab shown beside it in a split), and the tab in front: its name, file, text, findings and stops with their conditions.

Example

await client.indicator.ideState()

ideStop#

Put or take a stop in the Assay IDE · tool ide_stop

scope: labplan: freesince 1.16.0

Puts a stop on a line of the script in front of the Assay IDE, with the condition it stops on, or takes it away, as F9 and the stop's condition field do. A run and inspect then says where it fires. Answers the IDE as ide_state does.

Declaration

client.indicator
ideStop(args: { line: number; on: boolean; condition?: string }): Promise<any>

Parameters

NameTypeWhat it is
linenumberrequiredThe line of the script in front, from 1.
onbooleanrequiredTrue puts a stop there (or changes its condition), false takes it away.
conditionstringoptionalThe condition it stops on, an expression of the script (n % 2 == 1); empty or absent: whenever the line runs.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the IDE as ide_state does.

Example

await client.indicator.ideStop({ line: 1, on: true })

install#

Install a study script · tool indicator_install

scope: adminplan: plussince 1.2.0

Writes a study script into the person's indicators folder: a Python study, or an Assay script when the file name ends.assay. A file already there is written over only with replace, and then waits for the person's tick like a new one. It is not run - not even read for its declaration - until the person ticks it in Settings › Indicators. Answers the file and its state.

Declaration

client.indicator
install(args: { file_name: string; source: string; replace?: boolean }): Promise<any>

Parameters

NameTypeWhat it is
file_namestringrequiredThe script's file name in the indicators folder: [a-z0-9_]{1,32}, with or without.py; with.assay for an Assay script.
sourcestringrequiredThe script's whole text: one @study, as bentrix.study declares it; or an Assay script, which script_check checks first.
replacebooleanoptionalTrue writes over the script already in the folder under this name (the Assay editor's Save); the file is then the agent's and waits for the person's tick again. Omitted or false, a file already there is never written over.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the file and its state.

Example

await client.indicator.install({ file_name: "docs_sma.assay", source: "//@version=6\nindicator(\"Docs SMA\", overlay=true)\nplot(ta.sma(close, 20))\n" })

read#

Read a study script's text · tool indicator_read

scope: readplan: freesince 1.10.0

Answers the text of one script in the person's indicators folder - an Assay script or a Python study - with its state as indicators_state lists it: what the Assay editor opens. Only a file of that folder is read; a script from elsewhere is handed to script_check and indicator_install as text.

Declaration

client.indicator
read(args: { file: string }): Promise<any>

Parameters

NameTypeWhat it is
filestringrequiredThe script's file name in the indicators folder, with its extension: my_rsi.assay or my_sma.py.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the text of one script in the person's indicators folder - an Assay script or a Python study - with its state as indicators_state lists it: what the Assay editor opens.

Example

await client.indicator.read({ file: "…" })

rescan#

Read the indicators folder again · tool indicator_rescan

scope: labplan: plussince 1.2.0

Reads the person's indicators folder again, as Settings › Indicators' Rescan does: each script that may run describes itself, and indicators_state reads the outcome once it lands.

Declaration

client.indicator
rescan(): Promise<any>

It takes no arguments.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

What the tool's description says.

Example

await client.indicator.rescan()

scriptCheck#

Check an Assay script · tool script_check

scope: readplan: freesince 1.5.0

Compiles an Assay script under Settings › Assay's settings and derives the custom study it would be, writing nothing; budgets says the steps a bar, bars back, array elements, string characters and nesting it runs under, and what a trial run over 500 synthetic bars used of them (whether it ran, its fault, the most steps a bar took and its share of the budget). Answers every finding with its line and column (kind: error, refused, later, reads the future), the notes on calls that run as no-ops, and either the study's custom_study_spec or the reasons it cannot be one, each at its place; and the compatibility report: how many built-ins it names and every place that does not simply run (each finding, and each built-in that diverges, with what it computes differently), as the Assay editor exports it.

Declaration

client.indicator
scriptCheck(args: { source: string; name?: string }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text; it begins //@version=5 or //@version=6.
namestringoptionalThe file's stem the study's id is made from; omitted, the id is script_<8 hex> of the text.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Recorded from a running Bentrix 0.1.382 on a laboratory of generated markets (long lists cut to their first rows):

{
  "budgets": {
    "limits": {
      "max_array": 100000,
      "max_bars_back": 5000,
      "max_nesting": 60,
      "max_string": 4096,
      "steps_per_bar": 2000000
    },
    "trial": {
      "bars": 500,
      "fault": null,
      "peak_steps_per_bar": 19,
      "ran": true,
      "share_of_budget": 0.0
    }
  },
  "compatibility": {
    "builtins": 3,
    "rows": [],
    "runs": true
  },
  "compiles": true,
  "diagnostics": [],
  "notes": [],
  "refusals": [],
  "spec": {
    "about": "",
    "family": "oscillator",
    "id": "script_093b8749",
    "lines": [
      {
        "name": "plot_0",
        "plot": "line"
      }
    ],
    "lookback": 1,
    "scale": "auto",
    "schema_version": 1,
    "title": "t"
  },
  "version": {
    "declared": 6,
    "served": 6
  }
}

Example

await client.indicator.scriptCheck({ source: "//@version=6\nindicator(\"t\")\nplot(ta.sma(close, 20))\n" })

scriptComplete#

Complete an Assay script at a place · tool script_complete

scope: readplan: freesince 1.15.0

Answers what may be typed at line and col of an Assay script, best first, in the text's own version (a version-4 text is offered version 4's names, each with what it is read as): each item's label, kind, signature or type, note, the text it inserts, whether it runs here, and whether it is Assay's own; and the span the items replace. Writes nothing.

Declaration

client.indicator
scriptComplete(args: { source: string; line: number; col: number }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.
linenumberrequiredThe line, from 1.
colnumberrequiredThe column, from 1, in characters.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers what may be typed at line and col of an Assay script, best first, in the text's own version (a version-4 text is offered version 4's names, each with what it is read as): each item's label, kind, signature or type, note, the text it inserts, whether it runs here, and whether it is Assay's own; and the span the items replace.

Example

await client.indicator.scriptComplete({ source: "…", line: 1, col: 1 })

scriptConvert#

Convert an Assay script to a newer version · tool script_convert

scope: readplan: freesince 1.15.0

Answers an older script (version 1 to 4, or no version line) written in version 5 or 6 - the text and the edits that make it, one a changed run of lines - as the IDE's Convert command shows it in a diff: the version pass's own reading written onto the source, every comment and the layout kept, computing what the original computes. Refused by name where an edit in place cannot say it (a script declaring its own ta, a strategy's when inside an expression) and for a conversion down. Writes nothing; the agent applies the edits or not.

Declaration

client.indicator
scriptConvert(args: { source: string; to: number }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, version 1 to 4 or with no version line.
tonumberrequiredThe version it is written in: 5 or 6.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers an older script (version 1 to 4, or no version line) written in version 5 or 6 - the text and the edits that make it, one a changed run of lines - as the IDE's Convert command shows it in a diff: the version pass's own reading written onto the source, every comment and the layout kept, computing what the original computes.

Example

await client.indicator.scriptConvert({ source: "…", to: 1 })

scriptDefinition#

Where an Assay script declares a name · tool script_definition

scope: readplan: freesince 1.15.0

Answers the span where the script declares the name at line and col; null for a built-in or no name. Writes nothing.

Declaration

client.indicator
scriptDefinition(args: { source: string; line: number; col: number }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.
linenumberrequiredThe line, from 1.
colnumberrequiredThe column, from 1, in characters.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the span where the script declares the name at line and col; null for a built-in or no name.

Example

await client.indicator.scriptDefinition({ source: "…", line: 1, col: 1 })

scriptFolds#

Where an Assay script folds · tool script_folds

scope: readplan: freesince 1.15.0

Answers each run of lines that folds: the line that stays shown and the last line it hides. Writes nothing.

Declaration

client.indicator
scriptFolds(args: { source: string }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers each run of lines that folds: the line that stays shown and the last line it hides.

Example

await client.indicator.scriptFolds({ source: "…" })

scriptFormat#

Format an Assay script · tool script_format

scope: readplan: freesince 1.15.0

Answers the script's text formatted as the IDE's Format makes it, and the edits that make it: whitespace moved and nothing else - no name rewritten, the version line unchanged. Writes nothing.

Declaration

client.indicator
scriptFormat(args: { source: string }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the script's text formatted as the IDE's Format makes it, and the edits that make it: whitespace moved and nothing else - no name rewritten, the version line unchanged.

Example

await client.indicator.scriptFormat({ source: "…" })

scriptHistoryList#

An Assay script's kept versions · tool script_history_list

scope: readplan: freesince 1.15.0

Answers the versions the IDE kept of one script of the indicators folder, newest first: each one's id, when (UTC), what took it (save, run, format, convert, restore), the lines it added and removed against the one before, and its label. Writes nothing.

Declaration

client.indicator
scriptHistoryList(args: { file: string }): Promise<any>

Parameters

NameTypeWhat it is
filestringrequiredA script of the indicators folder, by its file name (rsi_divergence.assay) or its stem.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the versions the IDE kept of one script of the indicators folder, newest first: each one's id, when (UTC), what took it (save, run, format, convert, restore), the lines it added and removed against the one before, and its label.

Example

await client.indicator.scriptHistoryList({ file: "…" })

scriptHistoryRead#

Read one kept version of an Assay script · tool script_history_read

scope: readplan: freesince 1.15.0

Answers the text of one version the IDE kept of a script, exactly as it stood. Writes nothing; an agent that wants it back installs it with indicator_install.

Declaration

client.indicator
scriptHistoryRead(args: { file: string; id: string }): Promise<any>

Parameters

NameTypeWhat it is
filestringrequiredA script of the indicators folder, by its file name or its stem.
idstringrequiredA version's id, as script_history_list answers it.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the text of one version the IDE kept of a script, exactly as it stood.

Example

await client.indicator.scriptHistoryRead({ file: "…", id: "…" })

scriptHover#

What a name in an Assay script is · tool script_hover

scope: readplan: freesince 1.15.0

Answers what the name at line and col of an Assay script is: its span, its title (a built-in's signature, or how the script declares it), its note, whether it runs here, what a version 1-4 name is read as, and whether it is Assay's own; null where no name stands there. Writes nothing.

Declaration

client.indicator
scriptHover(args: { source: string; line: number; col: number }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.
linenumberrequiredThe line, from 1.
colnumberrequiredThe column, from 1, in characters.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers what the name at line and col of an Assay script is: its span, its title (a built-in's signature, or how the script declares it), its note, whether it runs here, what a version 1-4 name is read as, and whether it is Assay's own; null where no name stands there.

Example

await client.indicator.scriptHover({ source: "…", line: 1, col: 1 })

scriptInspect#

Run an Assay script recorded, as the IDE's Run and inspect does · tool script_inspect

scope: readplan: freesince 1.15.0

Runs a script over a workbench's bars of one market and interval, up to its cursor and never past it (the newest 5000), recorded as the IDE's Run and inspect records it, and answers: how many bars were read, each asked bar's named values at its close and the lines that ran in it (a bar outside the kept 5000 or past the bars read is refused), the bars where each stop fired, the script's log, its fault, and its lines by steps. Runs nothing on a chart and writes nothing.

Declaration

client.indicator
scriptInspect(args: { source: string; bench: string; symbol: string; timeframe: string; bars?: number[]; stops?: Array<{ condition?: string; line: number }> }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text.
benchstringrequiredThe workbench's uri, as get_state gives it.
symbolstringrequiredOne of the workbench's markets.
timeframestringrequiredAn interval's label: M1, H4, D1.
barsnumber[]optionalThe bars whose rows are answered, by their place from 0 (the oldest read); omitted, the last.
stopsArray<{ condition?: string; line: number }>optionalStops, as the IDE's F9 puts them: the bars where each fired are answered.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

What the tool's description says.

Example

await client.indicator.scriptInspect({ source: "…", bench, symbol: "SYN-DOCS", timeframe: "H1" })

scriptReferences#

Every place an Assay script reads a name · tool script_references

scope: readplan: freesince 1.15.0

Answers every span where the script reads the name at line and col (its own name, in its own scope), the declaration among them unless include_declaration is false. Writes nothing.

Declaration

client.indicator
scriptReferences(args: { source: string; line: number; col: number; include_declaration?: boolean }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text.
linenumberrequiredThe line, from 1.
colnumberrequiredThe column, from 1, in characters.
include_declarationbooleanoptionalWhether the declaration is among the answers; true when omitted.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers every span where the script reads the name at line and col (its own name, in its own scope), the declaration among them unless include_declaration is false.

Example

await client.indicator.scriptReferences({ source: "…", line: 1, col: 1 })

scriptRename#

Rename a name an Assay script declares · tool script_rename

scope: readplan: freesince 1.15.0

Answers the edits that rename the script's own name at line and col to new_name everywhere it is read in its scope, or refuses by name (a built-in, a name already taken there, a name that is not one). Answers edits and writes nothing; the agent applies them or not.

Declaration

client.indicator
scriptRename(args: { source: string; line: number; col: number; new_name: string }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text.
linenumberrequiredThe line, from 1.
colnumberrequiredThe column, from 1, in characters.
new_namestringrequiredThe name it is given.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the edits that rename the script's own name at line and col to new_name everywhere it is read in its scope, or refuses by name (a built-in, a name already taken there, a name that is not one).

Example

await client.indicator.scriptRename({ source: "…", line: 1, col: 1, new_name: "…" })

scriptSignature#

The call an Assay script's place stands in · tool script_signature

scope: readplan: freesince 1.15.0

Answers the call that line and col of an Assay script stands inside: the callee as written, its signature, its parameters with their types, which one is being typed, its note and what a version 1-4 name is read as; null where the place is in no call. Writes nothing.

Declaration

client.indicator
scriptSignature(args: { source: string; line: number; col: number }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.
linenumberrequiredThe line, from 1.
colnumberrequiredThe column, from 1, in characters.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the call that line and col of an Assay script stands inside: the callee as written, its signature, its parameters with their types, which one is being typed, its note and what a version 1-4 name is read as; null where the place is in no call.

Example

await client.indicator.scriptSignature({ source: "…", line: 1, col: 1 })

scriptSymbols#

An Assay script's outline · tool script_symbols

scope: readplan: freesince 1.15.0

Answers the outline the IDE shows: the declaration, the inputs, the functions with their parameters, the types and enums, and the outputs by title, each with its span and kind, nested. Writes nothing.

Declaration

client.indicator
scriptSymbols(args: { source: string }): Promise<any>

Parameters

NameTypeWhat it is
sourcestringrequiredThe script's whole text, in any version 1 to 6 or with no version line.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers the outline the IDE shows: the declaration, the inputs, the functions with their parameters, the types and enums, and the outputs by title, each with its span and kind, nested.

Example

await client.indicator.scriptSymbols({ source: "…" })

scriptVocabulary#

A version's own words · tool script_vocabulary

scope: readplan: freesince 1.15.0

Answers a version's keywords and, for versions 1 to 4, every name that version writes bare and what it is read as (sma read as ta.sma, study as indicator). Writes nothing.

Declaration

client.indicator
scriptVocabulary(args: { version: number }): Promise<any>

Parameters

NameTypeWhat it is
versionnumberrequiredA version, 1 to 6.

Returns

Promise<any> — the tool’s answer as a plain object.

What it answers

Answers a version's keywords and, for versions 1 to 4, every name that version writes bare and what it is read as (sma read as ta.

Example

await client.indicator.scriptVocabulary({ version: 1 })

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