Bentrix Docs
HomePricingDashboard

Python: indicators and scripts

Every method of client.indicator in the Python SDK.

ide_board#

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
def ide_board(self, action: str, *, index: Optional[int] = None, x: Optional[float] = None, y: Optional[float] = None) -> Dict[str, Any]

Parameters

NameTypeWhat it is
actionstrrequiredread 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.
indexOptional[int]optional
xOptional[float]optional
yOptional[float]optional

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

What the tool's description says.

Example

client.indicator.ide_board("…")

ide_edit#

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
def ide_edit(self, source: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

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

Example

client.indicator.ide_edit("…")

ide_graph#

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
def ide_graph(self) -> Dict[str, Any]

It takes no arguments.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.ide_graph()

ide_graph_edit#

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
def ide_graph_edit(self, gesture: Any) -> Dict[str, Any]

Parameters

NameTypeWhat it is
gestureAnyrequiredOne 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

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

Answers the IDE as ide_state does.

Example

client.indicator.ide_graph_edit("…")

ide_open#

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
def ide_open(self, *, file: Optional[str] = None, source: Optional[str] = None) -> Dict[str, Any]

Parameters

NameTypeWhat it is
fileOptional[str]optionalA 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.
sourceOptional[str]optionalOr a new script's whole text, in a new tab, not saved.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

Answers the IDE as ide_state does.

Example

client.indicator.ide_open()

ide_state#

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
def ide_state(self) -> Dict[str, Any]

It takes no arguments.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.ide_state()

ide_stop#

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
def ide_stop(self, line: int, on: bool, *, condition: Optional[str] = None) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

Answers the IDE as ide_state does.

Example

client.indicator.ide_stop(1, 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
def install(self, file_name: str, source: str, *, replace: Optional[bool] = None) -> Dict[str, Any]

Parameters

NameTypeWhat it is
file_namestrrequiredThe script's file name in the indicators folder: [a-z0-9_]{1,32}, with or without.py; with.assay for an Assay script.
sourcestrrequiredThe script's whole text: one @study, as bentrix.study declares it; or an Assay script, which script_check checks first.
replaceOptional[bool]optionalTrue 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

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

Answers the file and its state.

Example

client.indicator.install("docs_sma.assay", "//@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
def read(self, file: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.read("…")

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
def rescan(self) -> Dict[str, Any]

It takes no arguments.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

What the tool's description says.

Example

client.indicator.rescan()

script_check#

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
def script_check(self, source: str, *, name: Optional[str] = None) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_check("//@version=6\nindicator(\"t\")\nplot(ta.sma(close, 20))\n")

script_complete#

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
def script_complete(self, source: str, line: int, col: int) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text, in any version 1 to 6 or with no version line.
lineintrequiredThe line, from 1.
colintrequiredThe column, from 1, in characters.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_complete("…", 1, 1)

script_convert#

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
def script_convert(self, source: str, to: int) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_convert("…", 1)

script_definition#

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
def script_definition(self, source: str, line: int, col: int) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text, in any version 1 to 6 or with no version line.
lineintrequiredThe line, from 1.
colintrequiredThe column, from 1, in characters.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_definition("…", 1, 1)

script_folds#

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
def script_folds(self, source: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

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

Example

client.indicator.script_folds("…")

script_format#

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
def script_format(self, source: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_format("…")

script_history_list#

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
def script_history_list(self, file: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_history_list("…")

script_history_read#

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
def script_history_read(self, file: str, id: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

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

Example

client.indicator.script_history_read("…", "…")

script_hover#

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
def script_hover(self, source: str, line: int, col: int) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text, in any version 1 to 6 or with no version line.
lineintrequiredThe line, from 1.
colintrequiredThe column, from 1, in characters.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_hover("…", 1, 1)

script_inspect#

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
def script_inspect(self, source: str, bench: str, symbol: str, timeframe: str, *, bars: Optional[List[int]] = None, stops: Optional[List[InspectStop]] = None) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text.
benchstrrequiredThe workbench's uri, as get_state gives it.
symbolstrrequiredOne of the workbench's markets.
timeframestrrequiredAn interval's label: M1, H4, D1.
barsOptional[List[int]]optionalThe bars whose rows are answered, by their place from 0 (the oldest read); omitted, the last.
stopsOptional[List[InspectStop]]optionalStops, as the IDE's F9 puts them: the bars where each fired are answered.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

What it answers

What the tool's description says.

Example

client.indicator.script_inspect("…", bench, "SYN-DOCS", "H1")

script_references#

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
def script_references(self, source: str, line: int, col: int, *, include_declaration: Optional[bool] = None) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text.
lineintrequiredThe line, from 1.
colintrequiredThe column, from 1, in characters.
include_declarationOptional[bool]optionalWhether the declaration is among the answers; true when omitted.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_references("…", 1, 1)

script_rename#

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
def script_rename(self, source: str, line: int, col: int, new_name: str) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text.
lineintrequiredThe line, from 1.
colintrequiredThe column, from 1, in characters.
new_namestrrequiredThe name it is given.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_rename("…", 1, 1, "…")

script_signature#

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
def script_signature(self, source: str, line: int, col: int) -> Dict[str, Any]

Parameters

NameTypeWhat it is
sourcestrrequiredThe script's whole text, in any version 1 to 6 or with no version line.
lineintrequiredThe line, from 1.
colintrequiredThe column, from 1, in characters.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_signature("…", 1, 1)

script_symbols#

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
def script_symbols(self, source: str) -> Dict[str, Any]

Parameters

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

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_symbols("…")

script_vocabulary#

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
def script_vocabulary(self, version: int) -> Dict[str, Any]

Parameters

NameTypeWhat it is
versionintrequiredA version, 1 to 6.

Returns

Dict[str, Any] — the tool’s answer as a dict of plain values.

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

client.indicator.script_vocabulary(1)

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