Bentrix Docs
HomePricingDashboard

JavaScript: studies on a chart

Every method of client.study in the JavaScript SDK.

attach#

Attach an indicator · tool study_attach

scope: labplan: plussince 1.0.0

Attaches an indicator to a chart with its defaults — the person's saved default for the kind when there is one — as the indicator menu does; a custom study (custom:<id>) with its spec's defaults, or the inputs given. On, timeframe and wait_close set what it is computed on, as the settings card's Inputs tab does, for a built-in and a custom study alike; a timeframe the chart cannot read is refused by name. Answers the chart, the new study's id among its studies.

Declaration

client.study
attach(args: { chart: string; kind: string; convention?: string; inputs?: Record<string, unknown>; on?: string; timeframe?: string; wait_close?: boolean }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequiredThe chart's uri.
kindstringrequiredThe indicator, as a chart's setup names it (setup.studies[].kind), e.g. Sma, ema, rsi, macd, bollinger, atr; a custom study as custom:<id> (catalogue/indicators lists them).
conventionstringoptionalThe calculation, where the kind has two: talib or mt5.
inputsRecord<string, unknown>optionalA custom study's inputs by name, each within its spec's bounds; the rest take their defaults.
onstringoptionalOn a chart built by price or activity, what it is computed on: elements (the default) or candles, the time candles behind them.
timeframestringoptionalA timeframe of its own, as an interval is written (M5, H1, D1, …): the chart's or a longer one. Omitted, the chart's.
wait_closebooleanoptionalWith a timeframe of its own: true (the default) reads the last closed candle of it; false the one forming.

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):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "detached": false,
  "market": "SYN-DOCS",
  "setup": {
    "applied": "close",
    "candles": {
      "falling_body": [
        239,
        83,
        80
      ],
      "falling_border": [
        239,
        83,
        80
      ],
      "rising_body": [
        38,
        166,
        154
      ],
      "rising_border": [
        38,
        166,
        154
      ]
    },
    "colour_defaults": 2,
    "forecast": {
      "arrival_marks": false,
      "band_opacity": 0.18000000715255737,
      "coarser": "spanned",
      "diff": null,
      "element_on_time": "auto",
      "equivolume_width": "by_volume",
      "finer": "folded",
      "hidden": [],
      "keep_after_realized": {
        "horizons": 1
      },
      "on_profile": "forecast_session",
      "opacity": 0.6000000238418579,
      "other_rule": "derived",
      "past_newest": "clock_time",
      "readout": true,
      "room": "forecast",
      "samples_drawn": 32,
      "show": true,
      "time_on_elements": "derived",
      "trail": 0,
      "uncertainty": "fan"
    },
    "frame_colour": [
      163,
      169,
      180
    ],
    "grid": {
      "choice": "automatic",
      "colour": [
        69,
        75,
        87
      ],
      "step": 1.0
    },
    "layering": "candles-in-front",
    "magnet": {
      "on": true,
      "px": 10.0
    },
    "news": {
      "currencies": "market",
      "shown": "off"
    },
    "objects": [],
    "objects_bar": false,
    "outputs": {
      "hidden": [],
      "zones": false
    },
    "period_colour": [
      69,
      75,
      87
    ],
    "periods": true,
    "price": {
      "ask": true,
      "bid": true,
      "countdown": true,
      "last": "without_pair",
      "prev_close": false,
      "session_hl": false,
      "spread_band": false,
      "trade_chips": true
    },
    "shift_mark": true,
    "shift_parked": 0.0,
    "studies": [
      {
        "applied": "close",
        "author": "agent:1",
        "convention": "mt5",
        "id": 1,
        "kind": "rsi",
        "settings": {
          "period": 14,
          "shape": "period"
        }
      }
    ],
    "style": {
      "activity": {
        "volume_per_bar": 1000
      },
      "bars": {
        "falling": [
          239,
          83,
          80
        ],
        "hlc": false,
        "rising": [
          38,
          166,
          154
        ],
        "thickness": "px1"
      },
      "candles": {
        "bodies": "filled",
        "equivolume": false,
        "ha_smoothing": 1,
        "hollow": "both",
        "volume_width": [
          0.15000000596046448,
          0.8999999761581421
        ],
        "wick": "border"
      },
      "elements": {
        "bodies": "filled",
        "down": [
          239,
          83,
          80
        ],
        "kagi_reversal": {
          "kind": "auto"
        },
        "kagi_source": "closes",
        "kagi_thick_px": 2.5,
        "kagi_thin_px": 1.0,
        "line_break": 3,
        "line_break_source": "closes",
        "pnf_box": {
          "kind": "auto"
        },
        "pnf_glyph": "letters",
        "pnf_reversal": 3,
        "pnf_source": "closes",
        "range_box": {
          "kind": "auto"
        },
        "range_source": "closes",
        "renko_box": {
          "kind": "auto"
        },
        "renko_forming": "partial",
        "renko_reversal": 2,
        "renko_source": "closes",
        "renko_wicks": false,
        "up": [
          38,
          166,
          154
        ]
      },
      "line": {
        "above": [
          226,
          229,
          234
        ],
        "area_fill": 25,
        "baseline": "mean_of_shown",
        "baseline_fill": 30,
        "below": [
          226,
          229,
          234
        ],
        "colour": [
          226,
          229,
          234
        ],
        "column_down": [
          239,
          83,
          80
        ],
        "colum

Example

await client.study.attach({ chart, kind: "rsi" })

build#

Stop or compute again an Assay study's build · tool study_build

scope: labplan: freesince 1.11.0

Stops an Assay script study's build between two bars, as the square on its legend row does, or computes a stopped one again from its first bar, as the triangle does. A study that is not building, or not stopped, is refused by name. Answers the study's state: computing, stopped or ready.

Declaration

client.study
build(args: { chart: string; study: number; action: "stop" | "again" }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
action"stop" | "again"requiredstop ends an Assay study's build between two bars; again computes a stopped one again from its first bar.

Returns

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

What it answers

Answers the study's state: computing, stopped or ready.

Example

await client.study.build({ chart, study, action: "…" })

define#

Define a custom study · tool study_define

scope: labplan: plussince 1.2.0

Declares a custom study from a custom_study_spec, refused by name where the spec breaks a rule. An equal spec answers the same version; a different spec under the same id moves its version and every study of it on a chart is read again. Answers the kind to attach (custom:<id>) and the version.

Declaration

client.study
define(args: { spec: unknown }): Promise<any>

Parameters

NameTypeWhat it is
specunknownrequiredThe spec, as custom_study_spec describes it.

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):

{
  "kind": "custom:docs_range",
  "version": 1
}

Example

await client.study.define({ spec: "…" })

remove#

Remove an indicator · tool study_remove

scope: labplan: plussince 1.0.0

Takes a study off its chart, and with it every study computed on its lines, as the legend's x does once its question is answered. Answers the chart.

Declaration

client.study
remove(args: { chart: string; study: number }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequiredThe study's id, as the chart's answer gives it (setup.studies[].id).

Returns

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

What it answers

Answers the chart.

Example

await client.study.remove({ chart, study })

reset#

Reset an indicator · tool study_reset

scope: labplan: plussince 1.0.0

Puts a study back to the person's saved default for its kind, or to the kind's own when none is saved, as the settings card's Reset does. Answers the chart.

Declaration

client.study
reset(args: { chart: string; study: number }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequiredThe study's id, as the chart's answer gives it (setup.studies[].id).

Returns

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

What it answers

Answers the chart.

Example

await client.study.reset({ chart, study })

saveDefault#

Save an indicator as its kind's default · tool study_save_default

scope: labplan: plussince 1.0.0

Saves a study's settings and looks as the default every new study of its kind opens with, or forgets that default, as the settings card's Defaults menu does. Answers the chart.

Declaration

client.study
saveDefault(args: { chart: string; study: number; forget?: boolean }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
forgetbooleanoptionalTrue forgets the kind's saved default instead, and puts this study back to the kind's own.

Returns

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

What it answers

Answers the chart.

Example

await client.study.saveDefault({ chart, study })

seriesClear#

Drop a custom study's values · tool study_series_clear

scope: labplan: plussince 1.2.0

Drops the values handed over for a custom study on a chart; the study stays, waiting for its script. Answers the chart.

Declaration

client.study
seriesClear(args: { chart: string; study: number }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired

Returns

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

What it answers

Answers the chart.

Example

await client.study.seriesClear({ chart, study })

seriesGet#

Read what a custom study draws · tool study_series_get

scope: readplan: freesince 1.2.0

Reads what a chart draws now for a custom study — the values it holds, whoever computed them, at the bars it is drawn on as the chart last drew them — each line by its declared name with the newest limit values beside their bars' times; on a chart's elements (on: elements) each time is the element's candle open, beside its ordinal. A study on a timeframe of its own answers its values read back onto those bars. Nothing past the cursor. Answers waiting when nothing has landed.

Declaration

client.study
seriesGet(args: { chart: string; study: number; limit?: number }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
limitnumberoptionalThe newest values kept per line (at most 5000).

Returns

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

What it answers

Answers waiting when nothing has landed.

Example

await client.study.seriesGet({ chart, study })

seriesPut#

Hand over a custom study's values · tool study_series_put

scope: labplan: plussince 1.2.0

Hands over a custom study's values, each at one of the bars it is computed on: the chart's bar opens; on a chart built by price, its elements (each by its candle's open and its ordinal, chart_elements_get) or, set to the candles, the candles' opens; with a timeframe of its own, that timeframe's bar opens, read back onto the chart under its wait_close. A time past the workbench's cursor, or one that is not such a bar, is refused by name; at most 5000 values a call. A put under another epoch replaces the series, and a study set to compute on other bars drops it; the values are drawn on the chart and never saved. Answers how many were accepted, the newest time held, and how many a move of the clock back had cut since the last put.

Declaration

client.study
seriesPut(args: { chart: string; study: number; epoch: number; times: number[]; lines: Record<string, unknown>; append?: boolean; ordinals?: number[] }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequiredThe chart's uri.
studynumberrequiredThe custom study's id on the chart.
epochnumberrequiredThe program's own epoch: a put under another one replaces the whole series.
timesnumber[]requiredUTC milliseconds, oldest first, at most 5000: bar opens of what the study is computed on — the chart's interval, or on a chart built by price the candles behind it, or the study's own timeframe when it has one; on a chart's elements each element's candle open (chart_elements_get).
linesRecord<string, unknown>requiredEvery declared line by its name, one value per time; null is a gap.
appendbooleanoptionalTrue writes the newest value and after: the newest held is overwritten or followed.
ordinalsnumber[]optionalOn a chart's elements only: each element's ordinal among the elements of its candle, one per time (chart_elements_get); omitted, every one 0.

Returns

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

What it answers

Answers how many were accepted, the newest time held, and how many a move of the clock back had cut since the last put.

Example

await client.study.seriesPut({ chart, study, epoch: 1, times: "…", lines: "…" })

setBands#

Set an indicator's bands · tool study_set_bands

scope: labplan: plussince 1.0.0

Sets the deviation bands around a single-line study and their looks, as the Bands tab does; bands null turns them off. Patch fields: bands, band_looks. Answers the chart.

Declaration

client.study
setBands(args: { chart: string; study: number; patch: unknown }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
patchunknownrequiredFields of the study's entry (setup.studies[] in the chart's answer) laid over it; only this tab's fields.

Returns

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

What it answers

Answers the chart.

Example

await client.study.setBands({ chart, study, patch: "…" })

setInputs#

Set an indicator's inputs · tool study_set_inputs

scope: labplan: plussince 1.0.0

Sets what a study computes — its calculation, prices, settings (a custom study's inputs by name), timeframe, whether it waits for the higher candle to close, on a chart built by price whether it is computed on the elements or the candles (on: "elements" or "candles"), and a function of two series' second series (second: {"from": "price", "price": "open"}, {"from": "volume"}, {"from": "market", "symbol": "EURUSD", "price": "close"}, {"from": "study", "of": place, "line": 0} or {"from": "fixed", "value": 14}) — as the settings card's Inputs tab does, for a built-in and a custom study alike. Patch fields: convention, applied, applied_also, settings, timeframe, wait_close, on, second. Answers the chart.

Declaration

client.study
setInputs(args: { chart: string; study: number; patch: unknown }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
patchunknownrequiredFields of the study's entry (setup.studies[] in the chart's answer) laid over it; only this tab's fields.

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):

{
  "bench": "bentrix://lab/lab-1/bench/bench-2",
  "detached": false,
  "market": "SYN-DOCS",
  "setup": {
    "applied": "close",
    "candles": {
      "falling_body": [
        239,
        83,
        80
      ],
      "falling_border": [
        239,
        83,
        80
      ],
      "rising_body": [
        38,
        166,
        154
      ],
      "rising_border": [
        38,
        166,
        154
      ]
    },
    "colour_defaults": 2,
    "forecast": {
      "arrival_marks": false,
      "band_opacity": 0.18000000715255737,
      "coarser": "spanned",
      "diff": null,
      "element_on_time": "auto",
      "equivolume_width": "by_volume",
      "finer": "folded",
      "hidden": [],
      "keep_after_realized": {
        "horizons": 1
      },
      "on_profile": "forecast_session",
      "opacity": 0.6000000238418579,
      "other_rule": "derived",
      "past_newest": "clock_time",
      "readout": true,
      "room": "forecast",
      "samples_drawn": 32,
      "show": true,
      "time_on_elements": "derived",
      "trail": 0,
      "uncertainty": "fan"
    },
    "frame_colour": [
      163,
      169,
      180
    ],
    "grid": {
      "choice": "automatic",
      "colour": [
        69,
        75,
        87
      ],
      "step": 1.0
    },
    "layering": "candles-in-front",
    "magnet": {
      "on": true,
      "px": 10.0
    },
    "news": {
      "currencies": "market",
      "shown": "off"
    },
    "objects": [],
    "objects_bar": false,
    "outputs": {
      "hidden": [],
      "zones": false
    },
    "period_colour": [
      69,
      75,
      87
    ],
    "periods": true,
    "price": {
      "ask": true,
      "bid": true,
      "countdown": true,
      "last": "without_pair",
      "prev_close": false,
      "session_hl": false,
      "spread_band": false,
      "trade_chips": true
    },
    "shift_mark": true,
    "shift_parked": 0.0,
    "studies": [
      {
        "applied": "close",
        "author": "agent:1",
        "convention": "mt5",
        "id": 1,
        "kind": "rsi",
        "settings": {
          "period": 21,
          "shape": "period"
        }
      }
    ],
    "style": {
      "activity": {
        "volume_per_bar": 1000
      },
      "bars": {
        "falling": [
          239,
          83,
          80
        ],
        "hlc": false,
        "rising": [
          38,
          166,
          154
        ],
        "thickness": "px1"
      },
      "candles": {
        "bodies": "filled",
        "equivolume": false,
        "ha_smoothing": 1,
        "hollow": "both",
        "volume_width": [
          0.15000000596046448,
          0.8999999761581421
        ],
        "wick": "border"
      },
      "elements": {
        "bodies": "filled",
        "down": [
          239,
          83,
          80
        ],
        "kagi_reversal": {
          "kind": "auto"
        },
        "kagi_source": "closes",
        "kagi_thick_px": 2.5,
        "kagi_thin_px": 1.0,
        "line_break": 3,
        "line_break_source": "closes",
        "pnf_box": {
          "kind": "auto"
        },
        "pnf_glyph": "letters",
        "pnf_reversal": 3,
        "pnf_source": "closes",
        "range_box": {
          "kind": "auto"
        },
        "range_source": "closes",
        "renko_box": {
          "kind": "auto"
        },
        "renko_forming": "partial",
        "renko_reversal": 2,
        "renko_source": "closes",
        "renko_wicks": false,
        "up": [
          38,
          166,
          154
        ]
      },
      "line": {
        "above": [
          226,
          229,
          234
        ],
        "area_fill": 25,
        "baseline": "mean_of_shown",
        "baseline_fill": 30,
        "below": [
          226,
          229,
          234
        ],
        "colour": [
          226,
          229,
          234
        ],
        "column_down": [
          239,
          83,
          80
        ],
        "colum

Example

await client.study.setInputs({ chart, study: 1, patch: "…" })

setSlope#

Set an indicator's slope colouring · tool study_set_slope

scope: labplan: plussince 1.0.0

Sets how a single-line study is coloured by its slope and the colours of its five states, as the Slope tab does; slope null turns it off. Patch fields: slope, slope_look. Answers the chart.

Declaration

client.study
setSlope(args: { chart: string; study: number; patch: unknown }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
patchunknownrequiredFields of the study's entry (setup.studies[] in the chart's answer) laid over it; only this tab's fields.

Returns

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

What it answers

Answers the chart.

Example

await client.study.setSlope({ chart, study, patch: "…" })

setStyle#

Set an indicator's lines' looks · tool study_set_style

scope: labplan: plussince 1.0.0

Sets each line's colour, width, dash, kind and price line, the study's output and what it is computed on over an element chart, as the Style tab does. Patch fields: looks, output, on. Answers the chart.

Declaration

client.study
setStyle(args: { chart: string; study: number; patch: unknown }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
patchunknownrequiredFields of the study's entry (setup.studies[] in the chart's answer) laid over it; only this tab's fields.

Returns

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

What it answers

Answers the chart.

Example

await client.study.setStyle({ chart, study, patch: "…" })

setVisibility#

Set on which intervals an indicator is drawn · tool study_set_visibility

scope: labplan: plussince 1.0.0

Sets on which intervals a study is drawn, as the Visibility tab does. Patch field: visibility. Answers the chart.

Declaration

client.study
setVisibility(args: { chart: string; study: number; patch: unknown }): Promise<any>

Parameters

NameTypeWhat it is
chartstringrequired
studynumberrequired
patchunknownrequiredFields of the study's entry (setup.studies[] in the chart's answer) laid over it; only this tab's fields.

Returns

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

What it answers

Answers the chart.

Example

await client.study.setVisibility({ chart, study, patch: "…" })

undefine#

Forget a custom study's definition · tool study_undefine

scope: labplan: plussince 1.2.0

Forgets a custom study a program defined. Refused while any chart holds a study of it, and for a script's: a script's study is the person's file. Answers the kind.

Declaration

client.study
undefine(args: { kind: string }): Promise<any>

Parameters

NameTypeWhat it is
kindstringrequiredThe custom kind, custom:<id>.

Returns

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

What it answers

Answers the kind.

Example

await client.study.undefine({ kind: "…" })

values#

Compute a study · tool study_values

scope: readplan: freesince 1.0.0

Computes a study over a laboratory workbench's bars as its chart reads them at the cursor — never a bar past the clock — and answers each line by what it is, with the newest values beside their candles' times. An Assay indicator of the indicators folder is computed too, with no chart: study as custom:<id>, its inputs given or its defaults, each line by its declared name.

Declaration

client.study
values(args: { bench: string; symbol: string; timeframe: string; study: unknown; inputs?: Record<string, unknown>; limit?: number }): Promise<any>

Parameters

NameTypeWhat it is
benchstringrequiredThe laboratory workbench's uri.
symbolstringrequired
timeframestringrequiredThe interval, as the menu writes it.
studyunknownrequiredThe study as a chart's setup files it (setup.studies[] in a chart's answer, without id), or "custom:<id>" for an Assay indicator of the indicators folder.
inputsRecord<string, unknown>optionalAn Assay indicator's inputs by name; those not given take its spec's defaults.
limitnumberoptionalThe newest values kept per line (at most 5000).

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):

{
  "cursor_ms": 1791892903523,
  "lines": [
    {
      "line": "Main",
      "values": [
        51.68415901908286,
        52.57435557385333,
        52.7306736537927,
        57.865591776766635,
        57.4091548608301
      ]
    }
  ],
  "symbol": "SYN-DOCS",
  "timeframe": "H1",
  "times": [
    1791878400000,
    1791882000000,
    1791885600000,
    1791889200000,
    1791892800000
  ]
}

Example

await client.study.values({ bench, symbol: "SYN-DOCS", timeframe: "H1", study })

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