Bentrix Docs
HomePricingDashboard

JavaScript: strategies

Every method of client.strategy in the JavaScript SDK.

batchGet#

Read a batch · tool batch_get

scope: readplan: freesince 1.12.0

Reads a batch: how many of its cells settled, each cell's figures and where it stands (queued, arming, running, ended with its run, refused or not started with why), and the path of its record once every cell settled; then too its statistics against chance - for the cell with the highest net, the probabilistic and deflated Sharpe ratio, the minimum backtest length and the Harvey-Liu haircut over every trial the ledger counts for the strategy, the probability of backtest overfitting over the cells, the interquartile mean of the cells' nets with a bootstrap interval, the first market's price change as the baseline, and the conventions labelled as such.

Declaration

client.strategy
batchGet(args: { batch: string }): Promise<any>

Parameters

NameTypeWhat it is
batchstringrequiredThe batch's uri (bentrix://batch/<id>).

Returns

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

What it answers

What the tool's description says.

Example

await client.strategy.batchGet({ batch: "…" })

batchStop#

Stop a batch · tool batch_stop

scope: labplan: freesince 1.12.0

Stops a batch: its running cells end as a run's Stop ends them, the cells not yet started are not started, and what settled stays. Answers the batch.

Declaration

client.strategy
batchStop(args: { batch: string }): Promise<any>

Parameters

NameTypeWhat it is
batchstringrequiredThe batch's uri (bentrix://batch/<id>).

Returns

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

What it answers

Answers the batch.

Example

await client.strategy.batchStop({ batch: "…" })

batteryGet#

Read the verification battery · tool battery_get

scope: readplan: freesince 1.14.0

Answers this session's verification battery: how many of its workbenches settled, and once all did, each of the sixteen checks — its verdict (pass, fail, measured, not run), what it found in a sentence, and its figures.

Declaration

client.strategy
batteryGet(): Promise<any>

It takes no arguments.

Returns

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

What it answers

Answers this session's verification battery: how many of its workbenches settled, and once all did, each of the sixteen checks — its verdict (pass, fail, measured, not run), what it found in a sentence, and its figures.

Example

await client.strategy.batteryGet()

batteryRun#

Run the verification battery · tool battery_run

scope: labplan: freesince 1.14.0

Runs the sixteen checks of Bentrix's own engine on a laboratory workbench's recording: a reference strategy (EMA 8 crossing EMA 21, hourly) at machine speed on workbenches made alike it — as it is, again, on twice the spread, on one-minute OHLC ticks, over the first half of its days — and scripted orders on three more (a buy and a sell held to the middle of the days, a stop and a limit). Answers as battery_get does; battery_get again until every check is answered: pass, fail, measured or not run, each with its reason and figures.

Declaration

client.strategy
batteryRun(args: { bench: string }): Promise<any>

Parameters

NameTypeWhat it is
benchstringrequiredThe laboratory workbench whose recording the battery runs on: bentrix://lab/<lab>/bench/<bench>.

Returns

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

What it answers

Answers as battery_get does; battery_get again until every check is answered: pass, fail, measured or not run, each with its reason and figures.

Example

await client.strategy.batteryRun({ bench })

benchSetAutomation#

Arm a workbench's automation · tool bench_set_automation

scope: labplan: plussince 1.0.0

Arms or disarms a laboratory workbench's automation — whether a run's intents on it become orders — as the workbench's own switch does. A disarmed run still decides and journals what it would have sent. Answers the switch.

Declaration

client.strategy
benchSetAutomation(args: { bench: string; armed: boolean }): Promise<any>

Parameters

NameTypeWhat it is
benchstringrequiredThe workbench's uri.
armedbooleanrequiredWhether a run's intents on it become orders.

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

{
  "armed": true,
  "bench": "bentrix://lab/lab-1/bench/bench-2"
}

Example

await client.strategy.benchSetAutomation({ bench, armed: true })

envAct#

Act on the market's clock · tool env_act

scope: labplan: plussince 1.14.0

Takes one action in a live environment's episode, at the close it stands at: the position brought to the action's side - a flip closes first, and opens only once the close was sent; on a real account under Confirm the close is proposed in the trade panel for the person's Send. Moves no clock. Answers the refusal in its words and the outcome (sent, awaiting_person, refused); env_observe at the next close gives the reward.

Declaration

client.strategy
envAct(args: { env: string; action: unknown }): Promise<any>

Parameters

NameTypeWhat it is
envstringrequired
actionunknownrequiredThe action: 0, 1 or 2 for a discrete environment, a number in [-1, 1] for a continuous one, {side, size, stop, target} for an order one.

Returns

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

What it answers

Answers the refusal in its words and the outcome (sent, awaiting_person, refused); env_observe at the next close gives the reward.

Example

await client.strategy.envAct({ env, action: "…" })

envClose#

Close an environment · tool env_close

scope: labplan: plussince 1.14.0

Lets an environment go. Its workbench and its deals stay as they are.

Declaration

client.strategy
envClose(args: { env: string }): Promise<any>

Parameters

NameTypeWhat it is
envstringrequired

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

{
  "closed": "env-1"
}

Example

await client.strategy.envClose({ env: "env-1" })

envMake#

Make a trading environment · tool env_make

scope: labplan: plussince 1.14.0

Makes a reinforcement-learning environment over a workbench - observations of the closed candles and the account, discrete, continuous or order actions, eight named rewards, tape, window or session episodes (a growing curriculum optional), a modelled participation cap - and answers its id with its observation and action spaces. On a laboratory workbench env_reset starts an episode, env_step takes an action, run_episode runs a list; the workbench is rewound at each reset, its deals undone, so give it one of its own. On a paper or REAL workbench the clock is the market's: env_reset at a close, env_act, then env_observe at the next close. Env_close lets it go.

Declaration

client.strategy
envMake(args: { bench: string; action?: "discrete" | "continuous" | "order"; deadband?: number; episode?: "tape" | "window" | "session"; episode_bars?: number; follow?: boolean; growing?: { first: number; last: number; over: number }; impact?: number; interval?: string; lots?: number; max_points?: number; max_steps?: number; participation?: number; reward?: string; ruin?: number; symbol?: string; window?: number }): Promise<any>

Parameters

NameTypeWhat it is
benchstringrequiredThe workbench's uri. A laboratory workbench is rewound at each reset, its deals undone — give it one of its own; a paper or REAL one runs on the market's clock (env_act, env_observe).
action"discrete" | "continuous" | "order"optionalDiscrete (0 flat, 1 long, 2 short; the default), continuous (a target in [-1, 1]) or order (side, size, stop and target in points).
deadbandnumberoptionalA continuous action's flat zone, by default 0.1.
episode"tape" | "window" | "session"optionalTape (the whole days), window (episode_bars candles from the seed's draw; the default) or session (one day).
episode_barsnumberoptionalA window episode's candles, by default 200.
followbooleanoptionalFollow a clock someone else moves rather than drive it — a paper or REAL workbench always does; a laboratory one may (a replay the person plays, acted on at each close): no rewind, env_act and env_observe.
growing{ first: number; last: number; over: number }optionalA curriculum: window episodes lengthening from first to last candles over over episodes.
impactnumberoptionalWith participation: the reward charged impact x units / the candle's volume - never the account.
intervalstringoptionalThe interval a step lasts (M1 to W1), by default H1.
lotsnumberoptionalThe lots a whole position holds, by default 0.01.
max_pointsnumberoptionalAn order action's largest stop or target, in points, by default 10000.
max_stepsnumberoptionalOn a live workbench: the steps after which an episode is truncated.
participationnumberoptionalA modelled participation cap: an order's units at most this share of the last closed candle's volume, in (0, 1].
rewardstringoptionalThe reward plugin, by default dsr_dd_penalty@1.
ruinnumberoptionalThe share of the opening equity at or below which an episode ends in ruin, by default 0.5.
symbolstringoptionalThe market, by default the workbench's first.
windownumberoptionalThe closed candles an observation holds, by default 32.

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

{
  "action_space": {
    "kind": "discrete",
    "meaning": [
      "flat",
      "long",
      "short"
    ],
    "n": 3
  },
  "env": "env-1",
  "first_ms": 1790812800000,
  "interval": "H1",
  "last_ms": 1793491200000,
  "length_ms": 3600000,
  "live": false,
  "observation_space": {
    "account": {
      "dtype": "float32",
      "meaning": "side, log equity ratio to the episode's start, open profit over the opening equity",
      "shape": [
        3
      ]
    },
    "market": {
      "dtype": "float32",
      "meaning": "open, high, low, close as log ratios to the last close",
      "shape": [
        8,
        4
      ]
    }
  },
  "reward": "dsr_dd_penalty@1",
  "symbol": "SYN-DOCS"
}

Example

await client.strategy.envMake({ bench })

envObserve#

Observe at a close · tool env_observe

scope: labplan: plussince 1.14.0

Answers where an environment's episode stands at the close at_ms: the observation, the reward of the move since the last env_act, terminated (ruin), truncated (no candle closed, or the episode's steps) and info. On a live workbench it follows env_act at each close; on a laboratory workbench standing at at_ms it reads the observation a laboratory step would.

Declaration

client.strategy
envObserve(args: { env: string; at_ms: number; moved?: boolean }): Promise<any>

Parameters

NameTypeWhat it is
envstringrequired
at_msnumberrequiredThe close the workbench stands at.
movedbooleanoptionalFalse when no candle closed since the last observation (the market said nothing): the episode is truncated.

Returns

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

What it answers

Answers where an environment's episode stands at the close at_ms: the observation, the reward of the move since the last env_act, terminated (ruin), truncated (no candle closed, or the episode's steps) and info.

Example

await client.strategy.envObserve({ env, at_ms: 1 })

envReset#

Start an episode · tool env_reset

scope: labplan: plussince 1.14.0

Starts an environment's next episode. In the laboratory the workbench is rewound to its start with its deals undone, then advanced as Play would to the episode's start (the tape's first hour after the warm-up, a window the seed draws or start_ms gives, or a session's day); on a live workbench nothing moves and the episode starts at at_ms. Answers the observation and info (the reward's name, the ledger hash, the start, the end, the opening equity).

Declaration

client.strategy
envReset(args: { env: string; at_ms?: number; bars?: number; seed?: number; start_ms?: number }): Promise<any>

Parameters

NameTypeWhat it is
envstringrequiredThe environment, as env_make answered it.
at_msnumberoptionalOn a live workbench: the close the market last reached, where the episode starts.
barsnumberoptionalWith start_ms: the episode's candles.
seednumberoptionalThe seed: given, the episode draws start over from it; absent, the next episode of the last seed.
start_msnumberoptionalA window episode's start, chosen by a person's own sampler instead of the seed's draw.

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

{
  "info": {
    "end_ms": 1792828800000,
    "episode_index": 0,
    "ledger_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
    "opening": 10000.0,
    "reward": "dsr_dd_penalty@1",
    "start_ms": 1792785600000
  },
  "obs": {
    "account": [
      0.0,
      0.0,
      -0.0
    ],
    "market": [
      [
        0.001366929616779089,
        0.003762140404433012,
        0.0010633289348334074,
        0.002853242214769125
      ],
      [
        0.002873448887839914,
        0.004236459266394377,
        0.0013568111462518573,
        0.0013568111462518573
      ],
      [
        0.001366929616779089,
        0.0019536297768354416,
        0.0011341773206368089,
        0.0017311288975179195
      ],
      "… 5 more"
    ]
  }
}

Example

await client.strategy.envReset({ env: "env-1" })

envStep#

Take an action · tool env_step

scope: labplan: plussince 1.14.0

Takes one action in a laboratory environment's episode: the position brought to the action's side through the workbench's venue (refused in its words, never clipped into another), then the workbench advanced to the interval's next close. Answers the observation, the reward, terminated (ruin), truncated (the episode's or the tape's end) and info (the ledger hash, the refusal, the equity, the cursor, the participation it was cut to).

Declaration

client.strategy
envStep(args: { env: string; action: unknown }): Promise<any>

Parameters

NameTypeWhat it is
envstringrequired
actionunknownrequiredThe action: 0, 1 or 2 for a discrete environment, a number in [-1, 1] for a continuous one, {side, size, stop, target} for an order one.

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

{
  "info": {
    "cursor_ms": 1791154800000,
    "equity": 9998.23,
    "ledger_hash": "db865d84c5c5875ec1bf7ef2d5ba0b26ec224518c9cb1e88270286b61fed3962",
    "refused": null,
    "reward": "dsr_dd_penalty@1"
  },
  "obs": {
    "account": [
      1.0,
      -0.0001770156668499112,
      -0.00017499999376013875
    ],
    "market": [
      [
        0.004607579670846462,
        0.005970589816570282,
        0.003090942045673728,
        0.003090942045673728
      ],
      [
        0.003101060399785638,
        0.0036877605598419905,
        0.0028683082200586796,
        0.0034652596805244684
      ],
      [
        0.0034753745421767235,
        0.0034753745421767235,
        0.0021494701504707336,
        0.0021595980506390333
      ],
      "… 5 more"
    ]
  },
  "reward": 0.0,
  "terminated": false,
  "truncated": false
}

Example

await client.strategy.envStep({ env: "env-1", action: 1 })

ledgerQuery#

Read the trial ledger · tool ledger_query

scope: readplan: freesince 1.14.0

Reads the trial ledger: every run, batch cell and re-run written before its result was shown, and each result after it, in order - sequence number, wall clock, kind (trial or result), body (strategy, version, digest, tick model, span start, the batch and its figures; or of, trades and net; or an external family's name, count and description) and the hash chain. With strategy, that strategy's trials and their results only, and trials counts them (the N a multiple-testing correction needs). Always answers union, every trial the ledger holds (a run one, an external line its count), and families, each family's and strategy's count. Says where the chain stops following, if it does. The ledger has no door that removes a line.

Declaration

client.strategy
ledgerQuery(args: { from_seq?: number; limit?: number; strategy?: string }): Promise<any>

Parameters

NameTypeWhat it is
from_seqnumberoptionalThe first line to answer (its sequence number); omitted, from the first.
limitnumberoptionalHow many lines at most; omitted, 500.
strategystringoptionalA strategy, by its name as every other tool takes it (rsi pullback) or its stem (its file name, rsi_pullback), to read that strategy's trials and their results only.

Returns

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

What it answers

What the tool's description says.

Example

await client.strategy.ledgerQuery()

ledgerRecord#

Record trials tried outside a run · tool ledger_record

scope: labplan: freesince 1.17.0

Appends to the trial ledger a family of candidates tried in the person's own code - an event study's cells, a grid searched outside Bentrix - as one line with its count, before any of its result exists (kind trial: family, count, description, digest); or what came of such a trial (kind result: of, result). The family's count joins the ledger's union, the N a correction across everything tried takes, and never leaves it: the ledger has no door that removes a line. A run's own trials are Bentrix's to write and are refused here. Answers the line's sequence number, the family's count and the union.

Declaration

client.strategy
ledgerRecord(args: { kind: string; count?: number; description?: string; digest?: string; family?: string; of?: number; result?: unknown }): Promise<any>

Parameters

NameTypeWhat it is
kindstringrequiredtrial: a family of candidates tried outside a run, written before any of its result exists. result: what came of an earlier external trial.
countnumberoptionalTrial: how many candidates this line adds to the family, 1 to 10,000,000.
descriptionstringoptionalTrial: what was tried, in words, at most 4,000 characters.
digeststringoptionalTrial: a digest of the pre-registration, at most 128 characters.
familystringoptionalTrial: the family's name, letters, digits, _, - and ., at most 64.
ofnumberoptionalResult: the sequence number of the external trial it answers.
resultunknownoptionalResult: what came of it, an object of at most 64 KiB.

Returns

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

What it answers

Answers the line's sequence number, the family's count and the union.

Example

await client.strategy.ledgerRecord({ kind: "…" })

optimisationImport#

Import a MetaTrader optimisation · tool optimisation_import

scope: labplan: freesince 1.14.0

Reads a MetaTrader optimisation's results table (Pass, Result or Profit, Sharpe Ratio, Trades, and the expert's inputs), writes every pass to the trial ledger as a trial of name with its result, and judges the best pass (the highest Sharpe ratio) over the ledger's N for that name: its probabilistic and deflated Sharpe ratio and the Harvey-Liu haircut. The table carries no return series, so the sample is the pass's trades with a normal's skew and kurtosis, said, and PBO is not computed, said. The Strategies panel's Import optimisation results draws the same.

Declaration

client.strategy
optimisationImport(args: { name: string; table: string }): Promise<any>

Parameters

NameTypeWhat it is
namestringrequiredThe expert's name: what its passes are counted under in the trial ledger.
tablestringrequiredThe optimiser's exported table: its Export to XML file's text, or the table as CSV or tab-separated text with its header row.

Returns

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

What it answers

What the tool's description says.

Example

await client.strategy.optimisationImport({ name: "…", table: "…" })

runEpisode#

Run an episode · tool run_episode

scope: labplan: plussince 1.14.0

Resets a laboratory environment (with the seed when given) and takes the actions in turn until the episode ends or they run out. Answers each step's reward, refusal and equity, the steps taken, whether it terminated or was truncated, and the ledger hash.

Declaration

client.strategy
runEpisode(args: { env: string; actions: unknown[]; seed?: number }): Promise<any>

Parameters

NameTypeWhat it is
envstringrequired
actionsunknown[]requiredThe actions, taken in turn until the episode ends or they run out.
seednumberoptional

Returns

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

What it answers

Answers each step's reward, refusal and equity, the steps taken, whether it terminated or was truncated, and the ledger hash.

Example

await client.strategy.runEpisode({ env, actions: "…" })

runGet#

Read a run · tool run_get

scope: readplan: freesince 1.0.0

A run's state, its counts, and once it has ended its manifest: the tester report MetaTrader's tester shows, the trades and the equity samples.

Declaration

client.strategy
runGet(args: { run: string }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequiredThe run's uri.

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",
  "counts": {
    "candles": 473,
    "emitted": 2,
    "held_back": 0,
    "not_armed": 0,
    "refused": 0,
    "sent": 2
  },
  "manifest": {
    "armed": true,
    "bench": "Laboratory(LaboratoryId(1)) / bench-2",
    "conditions": {
      "build": "0.1.382+d7ec1b8",
      "cost_edition": "BENTRIX standard costs 2026.1",
      "costs": {},
      "currency": "USD",
      "data": [
        {
          "m1_months": 1,
          "m1_sha256": "d1d4fdd94b1c927d202e9ef4a32f96454be073d7e192179c7a0ce25d15403f44",
          "market": "SYN-DOCS",
          "tick_bytes": 2498934,
          "tick_days": 26,
          "tick_list_sha256": "635122d183d4dba8218133ef30067c18c2cf2e0e7976f9ec9e2fbf3781102d3d"
        },
        {
          "m1_months": 1,
          "m1_sha256": "59de407e183966b0d79280d26f5083ad0b4c4d2d339a23f112ecc1a57fe3d811",
          "market": "SYN-DOCS2",
          "tick_bytes": 4181811,
          "tick_days": 26,
          "tick_list_sha256": "076c16d51e91b0c38bd4281efb403ea14a16dc10ad7e97f74f82d3aa0d929c4a"
        }
      ],
      "document": {
        "entry": {
          "cancel_on_opposite": false,
          "expires_candles": null,
          "from": null,
          "kind": "market",
          "limit_offset": null,
          "offset": null
        },
        "exits": {
          "breakeven": null,
          "first_target": null,
          "stop": {
            "atr": {
              "study": "atr",
              "times": 1.5
            }
          },
          "target": {
            "r": 2.0
          },
          "trail": null
        },
        "interval": "H1",
        "limits": {
          "max_bars": null,
          "max_open": null,
          "one_position_per_market": true,
          "per_day": null
        },
        "made_by": "agent",
        "made_ms": 0,
        "markets": [
          "SYN-DOCS"
        ],
        "name": "docs rsi",
        "notes": "",
        "rules": {
          "buy": {
            "all": [
              {
                "cond": "rsi:level.cross_up:30"
              },
              {
                "compare": {
                  "above": [
                    "price.close",
                    "ema200"
                  ]
                }
              }
            ]
          },
          "close_buys": {
            "any": [
              {
                "compare": {
                  "cross_down": [
                    "rsi",
                    50.0
                  ]
                }
              },
              {
                "bars_in_trade": 48
              }
            ]
          },
          "close_sells": {
            "any": [
              {
                "compare": {
                  "cross_up": [
                    "rsi",
                    50.0
                  ]
                }
              },
              {
                "bars_in_trade": 48
              }
            ]
          },
          "sell": {
            "all": [
              {
                "cond": "rsi:level.cross_down:70"
              },
              {
                "compare": {
                  "below": [
                    "price.close",
                    "ema200"
                  ]
                }
              }
            ]
          }
        },
        "schema": 1,
        "sessions": {
          "desks": [],
          "flat_at": null,
          "window": null
        },
        "sizing": {
          "mode": "lots",
          "value": 0.1
        },
        "studies": {
          "atr": {
            "applied": "close",
            "convention": "mt5",
            "kind": "atr",
            "settings": {
              "period": 14,
              "shape": "period"
            }
          },
          "ema200": {
            "applied": "close",
            "convention": "talib",
            "kind": "ema",
            "settings": {
              "period": 200,
              "shape": "period"
            }

Example

await client.strategy.runGet({ run })

runParity#

Compare a run with another engine's trades · tool run_parity

scope: readplan: freesince 1.14.0

Compares an ended run's closed trades with a trade list another engine produced - MetaTrader's tester, another backtester, an earlier run - each put in one canonical form (one line a closed trade: close time in ms, L or S, net at two decimals, in closing order) and hashed with sha256. Answers both hashes and counts, whether they are one list, and the first trade where they part with each side's line. Times are compared as each list writes them. The Run window's Validation tab draws the same.

Declaration

client.strategy
runParity(args: { run: string; list: string }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequiredThe run's uri.
liststringrequiredThe other engine's trade list, as its file's text: a JSON list of trades (time_ms or time, long or side, net or profit with commission and swap), a Bentrix run.json, or a CSV with a header naming those columns (a deals report's Direction column keeps its out rows).

Returns

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

What it answers

Answers both hashes and counts, whether they are one list, and the first trade where they part with each side's line.

Example

await client.strategy.runParity({ run, list: "…" })

runPause#

Pause a run · tool run_pause

scope: labplan: plussince 1.0.0

Hands a running run's clock back to the person at the end of its candle, as Pause does. Answers the run.

Declaration

client.strategy
runPause(args: { run: string }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequiredThe run's uri.

Returns

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

What it answers

Answers the run.

Example

await client.strategy.runPause({ run })

runResume#

Resume a run · tool run_resume

scope: labplan: plussince 1.0.0

Continues a paused run from wherever its workbench's clock now stands, as Resume does. Answers the run.

Declaration

client.strategy
runResume(args: { run: string }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequiredThe run's uri.

Returns

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

What it answers

Answers the run.

Example

await client.strategy.runResume({ run })

runRobustness#

Test a run's robustness · tool run_robustness

scope: readplan: freesince 1.14.0

Tests how robust an ended run of this session is, over its trades read with their entries, every draw from one fixed seed: the maximum drawdown over the trades drawn again in another order, the net with a tenth of the trades left out, the net with each trade's fill degraded by up to a tenth of the median absolute trade net (each as 5th, 50th and 95th percentiles of 1,000 draws); the random-entry percentile (the share of random draws - as many trades, each held as long as one of the run's, at a random minute in a random direction on its first market - whose sum of price moves is below the run's); and its trades, net and wins under the quiet, middle and busy days; and its metrics - Van Tharp's SQN, expectancy and its parts, the longest drawdown duration and the market's own trading days a year. Each with its definition; kept as robustness.json beside the run's run.json. The Run window's Validation tab draws the same.

Declaration

client.strategy
runRobustness(args: { run: string }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequiredThe run's uri.

Returns

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

What it answers

What the tool's description says.

Example

await client.strategy.runRobustness({ run })

runSetPace#

Change a run's pace · tool run_set_pace

scope: labplan: plussince 1.0.0

Switches a run between machine speed and the replay's pace at the cursor, as the Run window's pace does. Answers the run.

Declaration

client.strategy
runSetPace(args: { run: string; pace: "machine" | "replay" }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequired
pace"machine" | "replay"required

Returns

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

What it answers

Answers the run.

Example

await client.strategy.runSetPace({ run, pace: "…" })

runStop#

Stop a run · tool run_stop

scope: labplan: plussince 1.0.0

Ends a run at the end of its candle, as the Run window's Stop does; Stop is never refused while a run runs or waits paused. Answers the run.

Declaration

client.strategy
runStop(args: { run: string }): Promise<any>

Parameters

NameTypeWhat it is
runstringrequiredThe run's uri.

Returns

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

What it answers

Answers the run.

Example

await client.strategy.runStop({ run })

statsFamilyTest#

Test a family of candidates against chance · tool stats_family_test

scope: readplan: freesince 1.17.0

Tests a family of candidates against a benchmark at once, from each candidate's performance less the benchmark's period by period: Hansen's test for superior predictive ability (the consistent p-value, with the liberal one and the conservative one, which is White's reality check) and each candidate's Romano-Wolf stepdown adjusted p-value, over one stationary bootstrap drawn the same for every candidate. The same series and seed give the same answer. Pure arithmetic: reads and writes nothing; a family larger than candidates x periods x resamples = 200,000,000 is refused with its size.

Declaration

client.strategy
statsFamilyTest(args: { series: number[][]; mean_block?: number; resamples?: number; seed?: number }): Promise<any>

Parameters

NameTypeWhat it is
seriesnumber[][]requiredEach candidate's performance less the benchmark's, period by period (larger is better), every row the same length: one row a candidate.
mean_blocknumberoptionalThe stationary bootstrap's mean block length in periods; omitted, 10.
resamplesnumberoptionalBootstrap resamples; omitted, 1,000; at most 20,000.
seednumberoptionalThe bootstrap's seed (the same seed, the same answer); omitted, 1.

Returns

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

What it answers

What the tool's description says.

Example

await client.strategy.statsFamilyTest({ series: "…" })

batch#

Run a strategy over a grid of its figures · tool strategy_batch

scope: labplan: freesince 1.12.0

Runs a saved strategy once per combination of the grid's values, each cell on a workbench of its own made over every condition of the given laboratory workbench (stretch, markets, zone, account, costs) and run from its first moment at machine speed, at most workers at once. A cell the validator refuses is said by field and never run; a batch past Largest batch is refused with the number. Two figures vary the cells' benches rather than the document: tick_model (real, every-tick, ohlc-m1, open-only) and spread_multiplier (numbers above zero, 1 as recorded); a settled batch's record compares the results under each, with a sign-flip flag. With dry, answers the cells and the estimate and makes nothing. Answers the batch's uri; batch_get reads its cells and their runs.

Declaration

client.strategy
batch(args: { strategy: string; bench: string; grid: Record<string, unknown>; dry?: boolean; version?: number; workers?: number }): Promise<any>

Parameters

NameTypeWhat it is
strategystringrequiredThe saved strategy's name.
benchstringrequiredThe laboratory workbench whose conditions every cell's own bench copies.
gridRecord<string, unknown>requiredEach figure the batch varies, by its path in the document (studies.fast.settings.period, sizing.value, a script's script.inputs.<title>), and the values it takes.
drybooleanoptionalPlan only: the cells and the estimate, nothing made.
versionnumberoptionalA version; the latest when absent.
workersnumberoptionalHow many cells run at once; the computer's cores less two when absent.

Returns

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

What it answers

Answers the batch's uri; batch_get reads its cells and their runs.

Example

await client.strategy.batch({ strategy, bench, grid: "…" })

get#

Read strategies · tool strategy_get

scope: readplan: freesince 1.0.0

Lists the person's strategies with their versions, or reads one version of one — the latest when none is named — as the file holds it.

Declaration

client.strategy
get(args: { name?: string; version?: number }): Promise<any>

Parameters

NameTypeWhat it is
namestringoptionalThe strategy's name; absent lists every strategy with its versions.
versionnumberoptionalA version; the latest when absent.

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

{
  "strategies": [
    {
      "name": "docs rsi",
      "unreadable": 0,
      "versions": [
        1
      ]
    }
  ]
}

Example

await client.strategy.get()

run#

Run a strategy · tool strategy_run

scope: labplan: plussince 1.0.0

Runs a saved strategy version on a laboratory workbench from its cursor, as the Run sheet does — one run per workbench; on a paper workbench at the market's own pace only (pace: replay); on a real account's workbench (with real) the person allows it on a card first, and every order follows the account's Automations mode - answered as a job. Its intents become orders only while the workbench's automation is armed (bench_set_automation). Answers the run's uri; run_get reads it, and its tester report once it ends.

Declaration

client.strategy
run(args: { strategy: string; bench: string; pace?: "machine" | "replay"; version?: number }): Promise<any>

Parameters

NameTypeWhat it is
strategystringrequiredThe saved strategy's name.
benchstringrequiredThe laboratory workbench it runs on, from its cursor.
pace"machine" | "replay"optional
versionnumberoptionalA version; the latest when absent.

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",
  "counts": {
    "candles": 0,
    "emitted": 0,
    "held_back": 0,
    "not_armed": 0,
    "refused": 0,
    "sent": 0
  },
  "manifest": null,
  "pace": "machine",
  "state": "running",
  "uri": "bentrix://run/2990368"
}

Example

await client.strategy.run({ strategy: "docs rsi", bench })

save#

Save a strategy · tool strategy_save

scope: labplan: plussince 1.0.0

Saves a strategy document as its next version — version 1 for a new name — validated first, never over a file; a document the latest version already says is not written again. Answers the version, its digest and the validation.

Declaration

client.strategy
save(args: { document: unknown }): Promise<any>

Parameters

NameTypeWhat it is
documentunknownrequiredThe strategy document, as bentrix://strategy/schema 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):

{
  "digest": "bd74f65d1a4641b3eca93ccd8df3e303de223a63522baa90def8adb99ffdf49a",
  "name": "docs rsi",
  "validation": {
    "refusals": [],
    "runnable": true,
    "warnings": []
  },
  "version": 1,
  "written": true
}

Example

await client.strategy.save({ document: "…" })

validate#

Validate a strategy · tool strategy_validate

scope: readplan: freesince 1.0.0

Validates a strategy document as the editor does, field by field: whether it can run, what refuses it and what is only warned. Saves nothing.

Declaration

client.strategy
validate(args: { document: unknown }): Promise<any>

Parameters

NameTypeWhat it is
documentunknownrequiredThe strategy document, as bentrix://strategy/schema 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):

{
  "refusals": [],
  "runnable": true,
  "warnings": []
}

Example

await client.strategy.validate({ document: "…" })

walkforward#

Walk a strategy forward · tool strategy_walkforward

scope: labplan: freesince 1.14.0

Cuts the workbench's days into windows of in_sample_days and the out_of_sample_days after them (anchored: every in-sample stretch starts at the first day; rolling: the in-sample days before), and for each window in turn runs the grid as a batch over its in-sample days, chooses the cell with the highest in-sample net, and runs it as chosen over the out-of-sample days on a bench whose days begin at the in-sample start. Every cell and every out-of-sample run is a trial in the ledger, naming the walk and the window. Answers the walk's uri; walk_get reads its windows and, once ended, its record.

Declaration

client.strategy
walkforward(args: { strategy: string; bench: string; grid: Record<string, unknown>; in_sample_days: number; out_of_sample_days: number; mode: string; version?: number; workers?: number }): Promise<any>

Parameters

NameTypeWhat it is
strategystringrequiredThe saved strategy's name.
benchstringrequiredThe laboratory workbench whose days are walked and whose conditions every bench copies.
gridRecord<string, unknown>requiredEach figure the in-sample batches vary, by its path, and its values (strategy_batch's grid; never tick_model).
in_sample_daysnumberrequiredDays of each in-sample stretch.
out_of_sample_daysnumberrequiredDays of each out-of-sample stretch.
modestringrequiredAnchored (every in-sample stretch starts at the first day) or rolling (the days before).
versionnumberoptionalA version; the latest when absent.
workersnumberoptionalHow many in-sample cells run at once; the computer's cores less two when absent.

Returns

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

What it answers

Answers the walk's uri; walk_get reads its windows and, once ended, its record.

Example

await client.strategy.walkforward({ strategy, bench, grid: "…", in_sample_days: 1, out_of_sample_days: 1, mode: "…" })

walkGet#

Read a walk-forward run · tool walk_get

scope: readplan: freesince 1.14.0

Answers a walk-forward run as it stands: each window's in-sample and out-of-sample stretches, its batch, the figures chosen and their in-sample net, the out-of-sample trades and net, and the efficiency (out-of-sample net a day over in-sample net a day, where the in-sample net is above zero); the out-of-sample total; and once every window settled, where its record was written.

Declaration

client.strategy
walkGet(args: { walk: string }): Promise<any>

Parameters

NameTypeWhat it is
walkstringrequiredThe walk's uri (bentrix://walk/<id>).

Returns

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

What it answers

Answers a walk-forward run as it stands: each window's in-sample and out-of-sample stretches, its batch, the figures chosen and their in-sample net, the out-of-sample trades and net, and the efficiency (out-of-sample net a day over in-sample net a day, where the in-sample net is above zero); the out-of-sample total; and once every window settled, where its record was written.

Example

await client.strategy.walkGet({ walk: "…" })

walkStop#

Stop a walk-forward run · tool walk_stop

scope: labplan: freesince 1.14.0

Stops a walk-forward run as its Stop does: the window's in-sample batch or out-of-sample run stopped, the windows not reached failed as stopped; what settled stays. Answers the walk as walk_get does.

Declaration

client.strategy
walkStop(args: { walk: string }): Promise<any>

Parameters

NameTypeWhat it is
walkstringrequiredThe walk's uri (bentrix://walk/<id>).

Returns

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

What it answers

Answers the walk as walk_get does.

Example

await client.strategy.walkStop({ walk: "…" })

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