Bentrix Docs
HomePricingDashboard

Your first output, step by step

Put a model's number on your chart in a few minutes, give it a meaning, watch it make arrows, and see how often it was right — on a practice market, with a short program you can copy, or by asking an AI assistant.

01What you will do

In about ten minutes you will:

  1. put a model's number on a chart, in a pane of its own;
  2. tell Bentrix what the number means — buy when it is high, sell when it is low;
  3. move the replay on, and watch the number change and the arrows appear;
  4. see how often the number was right.

Everything happens in a laboratory of generated markets, so nothing is real money and you need no download, no broker and no account.

The "model" here is deliberately simple: of the last 20 candles, how many closed higher than they opened? If 13 of 20 rose, the number is 0.65. It is an example to learn with, not a good model, and the last step shows why.

02Before you start

  1. Open Bentrix.
  2. Make a laboratory of generated markets, if you have none: ☰ › File › New laboratory, then Generated markets. Make a workbench in it with one market and open a chart of it at H1 (one candle an hour). Generated markets shows each step.
  3. Play the replay for a while, so the chart has at least 20 closed candles. The model needs them.
  4. Select that workbench in the left rail. The program below works on the workbench you have selected.

Then choose one of the two ways below: a short Python program, or an AI assistant.

03Way 1 — a short Python program

What you need

  • Python 3.9 or later on this computer.
  • Bentrix's Python SDK. The Python SDK page shows how to install it, in one command.

The program

Make a file named first_output.py, paste this into it, and save it. Every line is explained after the program.

import bentrix
from bentrix import Output

# 1. Connect to the Bentrix open on this computer. The first time, it appears in Settings › Agents as "my-first-output".
app = bentrix.connect(name="my-first-output")

# 2. The workbench you have selected in the window, and its first chart's market and interval.
state = app.workspace.get_state(depth="charts")
bench = state["selected"]
chart = next(c for lab in state["laboratories"] for b in lab["benches"] if b["uri"] == bench for c in b["charts"])
market, interval = chart["market"], chart["timeframe"]
print("workbench:", bench, "| chart:", market, interval)


def up_share():
    """A very simple number between 0 and 1: of the last 20 closed candles, the share that closed higher than it opened.
    It is an example to learn with — not a good model."""
    w = app.data.bars_window(bench, [interval], symbol=market, limit=20)
    rows = w["markets"][market][interval]["rows"]       # oldest first: [time, open, high, low, close, ...]
    ups = sum(1 for r in rows if r[4] > r[1])
    return rows[-1][0], ups / len(rows)                   # the newest closed candle's time, and the share


# 3. Put the number on the chart, and say what it means to you.
anchor, value = up_share()
app.output.put(bench, Output.scalar("my_first", market, anchor, value=value, range=(0, 1),
                                    units="probability", output="up_share"))
app.output.meaning_set(bench, "my_first", "up_share", {"reads": "direction", "high_means": "buy", "low_means": "sell",
                                                       "act_above": 0.55, "act_below": 0.45})
print("first value:", round(value, 2))

# 4. Thirty more candles: move the replay one candle on, and put a new value each time.
for _ in range(30):
    app.replay.step(bench, n=1, unit="candle", timeframe=interval)
    anchor, value = up_share()
    app.output.put(bench, Output.scalar("my_first", market, anchor, value=value, range=(0, 1),
                                        units="probability", output="up_share"))
print("done: 31 values on the chart")

# 5. How did it do? Each value is checked against the candle that came after it arrived.
report = app.output.report(bench, market, "my_first", "up_share", interval=interval)["result"]
counts, measures = report["counts"], report["measures"]
print("values checked:", counts["scored"], "| late:", counts["late"], "| still waiting:", counts["pending"])
print("AUC:", round(measures["auc"], 2), "(0.5 is a coin toss; higher is better)")
print("at your thresholds - right:", measures["at_threshold"]["tp"] + measures["at_threshold"]["tn"],
      "wrong:", measures["at_threshold"]["fp"] + measures["at_threshold"]["fn"])

Run it

Open a terminal in the folder where you saved the file and run:

python first_output.py

The first time, the program is paired with Bentrix under the name my-first-output. It then appears in ☰ › Settings › Agents with the permissions read, lab and paper — it can work in the laboratory and on paper, never on a real account — and you can take them away there at any time.

It prints something like this. Your numbers will differ, because your market is not the same as ours:

workbench: bentrix://lab/lab-1/bench/bench-2 | chart: SYN-PRACTICE H1
first value: 0.3
done: 31 values on the chart
values checked: 30 | late: 0 | still waiting: 1
AUC: 0.41 (0.5 is a coin toss; higher is better)
at your thresholds - right: 15 wrong: 15

What each step does, and what you see

Step 1 — connect. bentrix.connect finds the Bentrix running on this computer and asks it to let the program in under the name you give. Nothing appears on the chart yet.

Step 2 — find your workbench and chart. The program asks Bentrix which workbench is selected, and reads the market and the interval of its first chart, such as SYN-PRACTICE and H1.

Step 3 — the first value, and its meaning. The program reads the last 20 closed candles, counts how many rose, and puts the share on the chart as an output named my_first.up_share. Then it sets the output's meaning: a value above 0.55 means buy, below 0.45 means sell, and in between means nothing. On your screen:

  • a new pane opens under the price chart, with a line at the value;
  • a legend row appears: ◌ OUTPUT · my_first · up_share · scalar · 0.3000;
  • two dashed lines appear in the pane at 0.55 and 0.45 — your thresholds;
  • if the value is already beyond a threshold, an arrow appears on the candle the value arrived in, as soon as that candle is drawn.

The anchor is the time of the newest closed candle — the candle the model was looking at. The program never says when the value arrived. Bentrix stamps that itself, on the workbench's clock, so a value can never claim to have existed earlier than it did.

Step 4 — thirty more candles. The program moves the replay on one candle at a time and puts a new value after each. You see the candles appear one by one, the line in the pane follow them, and arrows appear where the value crosses a threshold: a green arrow under a candle where it rises above 0.55, a red arrow over a candle where it falls below 0.45.

Step 5 — how did it do? Bentrix pairs each value with the candle that came after it arrived, and counts:

  • values checked — how many values had a candle after them to be checked against;
  • late — values that arrived after the candle they were about had closed (none here: the program answers at once);
  • still waiting — the newest value, whose next candle has not come yet;
  • AUC — how well the values tell a rising candle from a falling one. 0.5 is what tossing a coin gives; 1 would be perfect. Our simple model scored 0.41: no better than a coin, which is exactly what you should expect from counting rising candles;
  • right and wrong at your thresholds.

A low score is the point of this step, not a failure. A model that looks sensible can be worthless, and Bentrix lets you find that out on history, before you trust it. Measuring an output explains every measure.

04Way 2 — ask an AI assistant

If you have connected an AI assistant to Bentrix (Connect an AI assistant, step by step), you can ask it in plain words. For example:

i

On the workbench I have selected, read the last 20 closed H1 candles of the chart's market. Put an output named my_first.up_share, a number from 0 to 1 that is the share of those candles that closed higher than they opened. Set its meaning: buy above 0.55, sell below 0.45. Then step the replay one candle at a time, 30 times, putting a new value after each step. At the end, show me the output's report.

The assistant uses the same tools as the program above — bars_window, output_put, output_meaning_set, replay_step and output_report — and you see the same pane, lines and arrows appear. An assistant can only do what its permissions in ☰ › Settings › Agents allow; see Permissions and scopes.

05Now try these yourself

  • Change the meaning. Press the name up_share in the legend row. The meaning sheet opens. Set A high value means to Sell and A low value means to Buy, and press Done. Every arrow on the chart turns round. The model did not change; only what you read into it did.
  • Move the thresholds. In the same sheet, set Acts above to 0.6. Fewer arrows appear, because the value must now go higher to count as a buy.
  • Hide it. Press the eye in the legend row: the pane and the arrows disappear from this chart. Press it again to bring them back.
  • Remove it. Press the × in the legend row: the output leaves the workbench.
  • Go back in time. Move the replay back a few candles. The values that had not yet arrived at that moment disappear with them: a value cannot exist before it arrives.

06If something does not appear

See common questions. The usual causes are a chart of another market than the output's, an output hidden with its eye, and a meaning not yet set (no meaning, no arrows).

07Where to go next

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