A reinforcement-learning environment over any laboratory workbench: observations of the closed candles and the account, three kinds of action, eight rewards, episodes drawn by seed — and every step filled by the same venue a person trades on.
The Gym's loop: observe the closed candles, act, the venue fills with its costs, and the reward comes back.
Gym
What it does, part by part.
The loop
Observe, act, fill, reward
env_reset starts an episode; env_step takes an action, moves the clock to the next close and answers the observation, the reward and whether the episode ended — the shape every learning library expects.
Sixty-four environments stepped together, and the three kinds of action.
Honest fills
A policy cannot learn a fill that does not exist
Every action is an order on the simulated venue — spread, commission, swap, the volume step and the stops level — and the observation holds only closed candles, so look-ahead is impossible.
Eight rewards, from P&L to the differential Sharpe
A participation cap and an impact charge, as a setting
An episode's start is drawn from its seed, the same on every machine; the same seed and the same actions give the same deals, and the ledger hash proves it.
In Python the environment is a Gymnasium environment; in the other eight languages it is the same calls. Train PPO, or write Q-learning in a page, and test on seeds the training never saw.
Make an environment over the selected workbench, run one episode to its end — in each of the nine languages.
state = client.workspace.get_state(depth="benches")
bench = state["selected"]
made = client.strategy.env_make(bench, episode_bars=24, interval="H1", reward="pnl@1", window=8)
env = made["env"]
now = client.strategy.env_reset(env, seed=7)
total = 0.0for _ inrange(1000):
now = client.strategy.env_step(env, 1)
r = now["reward"]
total += r
if now["terminated"] or now["truncated"]: break
print("total reward:", total)
const state = await client.workspace.getState({ depth: "benches" });
const bench = state.selected;
const made = await client.strategy.envMake({ bench, episode_bars: 24, interval: "H1", reward: "pnl@1", window: 8 });
const env = made.env;
let now = await client.strategy.envReset({ env, seed: 7 });
let total = 0.0;
for (let i0 = 0; i0 < 1000; i0++) {
now = await client.strategy.envStep({ env, action: 1 });
const r = now.reward;
total += r;
if (now.terminated || now.truncated) break;
}
console.log("total reward:", total);
var state = await client.Workspace.GetState(depth: "benches");
var bench = state!["selected"]?.GetValue<string>() ?? "";
var made = await client.Strategy.EnvMake(bench, episodeBars: 24, interval: "H1", reward: "pnl@1", window: 8);
var env = made!["env"]?.GetValue<string>() ?? "";
var now = await client.Strategy.EnvReset(env, seed: 7);
var total = 0.0;
for (var i0 = 0; i0 < 1000; i0++)
{
now = await client.Strategy.EnvStep(env, 1);
var r = now!["reward"]!.GetValue<double>();
total += r;
if (now!["terminated"]!.GetValue<bool>() || now!["truncated"]!.GetValue<bool>()) break;
}
Console.WriteLine($"total reward: {total}");
state := must(client.Workspace.GetState(ctx, mcp.WorkspaceGetStateArgs{Depth: mcp.Ptr[string]("benches")}))
bench := text(at(state, "selected"))
made := must(client.Strategy.EnvMake(ctx, mcp.StrategyEnvMakeArgs{Bench: bench, EpisodeBars: mcp.Ptr[int64](24), Interval: mcp.Ptr[string]("H1"), Reward: mcp.Ptr[string]("pnl@1"), Window: mcp.Ptr[int64](8)}))
env := text(at(made, "env"))
var now any = must(client.Strategy.EnvReset(ctx, mcp.StrategyEnvResetArgs{Env: env, Seed: mcp.Ptr[int64](7)}))
total := float64(0.0)
for i0 := 0; i0 < 1000; i0++ {
now = must(client.Strategy.EnvStep(ctx, mcp.StrategyEnvStepArgs{Env: env, Action: 1}))
r := num(at(now, "reward"))
total += r
ifat(now, "terminated") == true || at(now, "truncated") == true {
break
}
}
fmt.Println("total reward:", total)
Object state = client.workspace.getState(new Bentrix.WorkspaceApi.GetStateArgs().depth("benches"));
String bench = (String) at(state, "selected");
Object made = client.strategy.envMake(new Bentrix.StrategyApi.EnvMakeArgs(bench).episodeBars(24L).interval("H1").reward("pnl@1").window(8L));
String env = (String) at(made, "env");
Object now = client.strategy.envReset(new Bentrix.StrategyApi.EnvResetArgs(env).seed(7L));
double total = 0.0;
for (int i0 = 0; i0 < 1000; i0++) {
now = client.strategy.envStep(new Bentrix.StrategyApi.EnvStepArgs(env, 1));
double r = ((Number) at(now, "reward")).doubleValue();
total += r;
if (Boolean.TRUE.equals(at(now, "terminated")) || Boolean.TRUE.equals(at(now, "truncated"))) break;
}
System.out.println("total reward:" + " " + total);
auto state = client.workspace.get_state(WorkspaceApi::GetStateArgs().depth("benches"));
auto bench = (state["selected"].is_string() ? state["selected"].str() : std::string());
auto made = client.strategy.env_make(StrategyApi::EnvMakeArgs(bench).episode_bars(24).interval("H1").reward("pnl@1").window(8));
auto env = (made["env"].is_string() ? made["env"].str() : std::string());
Json now = client.strategy.env_reset(StrategyApi::EnvResetArgs(env).seed(7));
double total = 0.0;
for (int i0 = 0; i0 < 1000; i0++) {
now = client.strategy.env_step(StrategyApi::EnvStepArgs(env, 1));
auto r = now["reward"].num();
total += r;
if (now["terminated"] == Json(true) || now["truncated"] == Json(true)) break;
}
std::cout << "total reward:" << " " << total << std::endl;
state = client.workspace.get_state(; depth = "benches")
bench = state["selected"]
made = client.strategy.env_make(bench; episode_bars = 24, interval = "H1", reward = "pnl@1", window = 8)
env = made["env"]
now = client.strategy.env_reset(env; seed = 7)
total = 0.0for _ in1:1000
global now = client.strategy.env_step(env, 1)
r = now["reward"]
global total += r
(now["terminated"] || now["truncated"]) && break
endprintln("total reward:", " ", total)
state <- client$workspace$get_state(depth = "benches")
bench <- state$selected
made <- client$strategy$env_make(bench, episode_bars = 24, interval = "H1", reward = "pnl@1", window = 8)
env <- made$env
now <- client$strategy$env_reset(env, seed = 7)
total <- 0.0for (k inseq_len(1000)) {
now <- client$strategy$env_step(env, 1)
r <- now$reward
total <- total + r
if (isTRUE(now$terminated) || isTRUE(now$truncated)) break
}
cat("total reward:", format(total), "\n")
let state = client.workspace().get_state(mcp::WorkspaceGetStateArgs::new().depth("benches"))?;
let bench = state["selected"].as_str().unwrap_or_default().to_string();
let made = client.strategy().env_make(mcp::StrategyEnvMakeArgs::new(bench.clone()).episode_bars(24).interval("H1").reward("pnl@1").window(8))?;
let env = made["env"].as_str().unwrap_or_default().to_string();
letmut now = client.strategy().env_reset(mcp::StrategyEnvResetArgs::new(env.clone()).seed(7))?;
letmut total: f64 = 0.0;
for _ in0..1000 {
now = client.strategy().env_step(mcp::StrategyEnvStepArgs::new(env.clone(), 1))?;
let r = now["reward"].as_f64().unwrap_or(f64::NAN);
total += r;
if now["terminated"] == true || now["truncated"] == true { break; }
}
println!("total reward: {}", total);
How it works
Four steps, in order.
Give it a workbenchA laboratory workbench of its own.
Make the environmentInterval, window, actions, reward, episodes.
TrainIn any language, or with Gymnasium.
Test honestlyOn seeds and windows it never saw.
Packages
Learn on Free. Trade on Plus. Build on Pro.
What each package holds of this page. While the beta lasts, Plus and Pro are free to take: you choose your package on your account page, with no payment.
Bentrix is in beta. Plus and Pro are free to take.
One download for Windows. Choose your package on your account page, with no payment, while the beta lasts; a feature of Plus or Pro carries its badge in the application, so nothing changes by surprise.