Training a Reinforcement Learning agent for crypto trading

Manual strategies cannot keep up with changing market regimes, and off-the-shelf trading robots break at the first reversal. We train reinforcement learning agents for your goals and risk constraints — turnkey, from problem statement to documentation handover. We configure the risk policy so that the result does not depend on a single lucky period.

Blockchain Development Services

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1359
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

Why Reinforcement Learning trading fails in the live market

Reinforcement learning for crypto looks great on history: the agent turns profitable, the equity curve is smooth, drawdown stays within specified boundaries.

Everything breaks in the transition to live trades, because the market is non-stationary: liquidity, volatility, and participant composition change, while the environment on which the agent trained remains in the past.

The first bottleneck is overfitting to historical data. When reward incentivizes profit at every step, the agent memorizes the microstructure of specific periods: exact levels, rebound patterns, entry timing.

These dependencies are not reproduced, so the agent loses profitability in the real market not because the idea is weak, but because it optimized for noise that is no longer in the real data.

The second is drawdown when the market regime changes. A behavior policy robust in a flat market falls apart in a trend or on a sharp move.

The risk penalty and position size limit help only partially: if regime shifts were rare in the training set, the agent simply has not learned a response to them.

The third is unstable trade execution. Slippage, commissions, partial fills, and latency between signal and trade are idealized in history, while in reality they eat the advantage entirely.

Below we break down how this is closed: from reward design and out-of-sample testing to risk control loops on a live account.

What a trained agent delivers: effect in measurable quantities

A trading agent is not a "black box" but a policy with a set of measurable characteristics.

We measure the effect in the same environment used for training and compare it with a baseline strategy: time in market, drawdown depth, reaction latency to volatility, limit compliance.

We describe the environment via Gymnasium, so the metrics are reproducible on any historical segment.

  • Robustness to market regimes. Training and validation run separately on segments with trend, flat, and high volatility. A policy overfit to one regime is screened out at validation, not on a live account.
  • Drawdown reduction. The drawdown penalty is built into the reward function and grows nonlinearly. On validation, this yields drawdown 1.5–2 times less than the baseline at comparable return.
  • Real-time risk management. Position size and stop are recalculated at each step from current volatility. The execution layer checks limits, volume, and price before sending an order — a model failure does not turn into an unplanned position.
  • Monitoring and decision logging. Every action is recorded together with the state, reward, and reason the constraint triggered. The log reconstructs why the agent entered or exited.

Degradation is visible by metrics before it becomes a loss: divergence of current metrics from validation runs triggers retraining by procedure, not by the fact of losses.

Comparison of approaches: reinforcement learning and manual strategies

The choice between reinforcement learning and manual rules is not a matter of taste, but a matter of how the goal is formalized and how much data is available at the input.

Reinforcement learning requires an environment where the agent can run episodes and receive reward; learning on labeled data works where the task reduces to prediction; parameter tuning of rules is needed when the logic is already described but not configured. Below are four options that are actually chosen between, and their engineering boundaries.

Four options and their boundaries

Option When appropriate Limited by
Reinforcement learning The goal is expressed through reward, there is an environment for running episodes, and a data reserve across different market regimes The agent finds loopholes in the reward function; the policy is poorly explainable, and behavior diverges from history when the regime changes
Learning on labeled data The task reduces to prediction: probability of movement, market state classification, entry filter Labels fix the past distribution; the model does not account for commissions and the impact of its own orders
Parameter tuning of rules Entry and exit logic is already described, there are few parameters, and robustness is needed rather than maximum on history Overfitting: the result grows on fitting and falls on out-of-sample data
Manual rules and indicators Few instruments, rare decisions, transparency of every entry is important Discipline and reaction speed; does not scale to dozens of instruments

In practice, a hybrid approach to the strategy most often wins: reinforcement learning is responsible for timing and position sizing, while manual rules and indicators set hard risk boundaries, bans on trading in certain states, and limits on a losing streak.

We test such combinations with walk-forward validation on consecutive segments and comparison with a simple benchmark — if the agent does not beat it on out-of-sample data, it does not go to production.

Stages of work: from problem statement to agent handover

In Reinforcement Learning projects for trading, work starts not with code, but with task breakdown: which instruments and on what horizon we trade, what risk is unacceptable.

At this same step we fix metrics — return adjusted for drawdown, share of profitable trades, maximum drawdown. Without formal metrics there is nothing to stop training with, and the result cannot be accepted.

  1. Task and metrics breakdown. We agree on the horizon, instrument set, and risk constraints; metrics become the stopping criterion for training and the acceptance criterion for the agent.
  2. Historical data preparation. We collect quotes and the order book from open sources (Binance), remove gaps and outliers, bring series to a unified frequency — otherwise the agent will learn noise instead of patterns.
  3. Training environment design. We reproduce exchange logic: commissions, slippage, partial order fills. Under ideal conditions, the agent shows profit that does not exist in reality.
  4. Reward function setup. We balance profit and risk penalty: with skewed weights, the agent either goes inactive or into excessive trading, where commission eats the result.
  5. Pre-live validation. A run on an out-of-sample historical segment and in simulation on abnormal market periods, comparison with the baseline strategy.
  6. Agent handover and support. We deliver code, environment configurations, the trained model, and documentation on metrics; we remain in touch after launch.

Each step closes with a verifiable artifact: data report, environment configuration, learning curve, validation protocol. Going back a step is cheaper than sorting out losses on a live account.

Risk policies, configurations, and agent documentation

A trained agent without an operational loop is useless: it cannot be reproduced, checked, or safely stopped. Therefore, together with the model, the client receives the full set of artifacts — from launch configurations to instructions for the on-call team.

  • Launch configurations: environment parameters, instrument composition, decision horizon, and initial conditions. The same dataset with one configuration reproduces the agent's behavior.
  • Risk-limiting policies: per-session drawdown limit, daily stop, maximum position size, and trade frequency. When triggered, the agent switches to closing mode instead of continuing to build position.
  • Exchange integration schemes: order, quote, and account state streams with failure points, timeouts, and retry order specified.
  • Logs and reporting: for every decision, observation, action, reward, and actual execution result are saved — from them a return and risk report is assembled.
  • Team instructions: order of starting, stopping, and rolling back a policy version, actions when account state diverges from expected.
  • Retraining procedure: on what data the policy updates, which metrics are thresholds, and when the version rolls back to the previous one.
  • Pre-release check set: historical run, execution latency simulation, and behavior on exchange connection loss.

Each item is a file, scheme, or document that stays in your repository and is read without our involvement. Handover is closed when your team itself starts, stops, and rolls back the agent, and logs confirm that risk policies triggered.

Case: an agent robust to trading regime changes

What it was before

The first version of the agent was trained on one year of history taken from Binance, and on the training segment it looked smooth: 12% drawdown, stable growth.

On the regime change from trend to range, behavior fell apart — the model kept building positions by inertia, drawdown grew to 38%, and the share of profitable trading days fell below half.

The error was not in the architecture but in the data: the agent saw one market state and had no features by which to distinguish it from another.

What was changed

History was labeled by regimes — uptrend, downtrend, range, elevated volatility — and these features were added to the agent's observation.

Training was rebuilt so that episodes alternated between regimes, and the reward penalized concentration in one scenario: winning at the expense of one lucky period became unprofitable.

At runtime, a limiter was added that reduces position size when the regime changes until the agent gains statistics on new conditions.

What became

On the same control segment as before, drawdown was 14% instead of 38%, the share of profitable days grew from 54% to 66%, and the return-to-risk ratio — from 0.7 to 1.8.

More important than the numbers, behavior changed: the agent itself cuts exposure in an unfamiliar regime and returns to the usual position size when the return distribution again matches training. There are no more manual switches between strategies.

What to do if a ready trading algorithm is already deployed

The answer depends on how many decisions in the current system are described by explicit rules, and how many by market noise. This determines the fate of a ready algorithmic bot: layer learning on top, move the logic to learning, or replace the loop entirely.

First scenario — keep the rules and add learning on top. The bot trades under the previous conditions, while the agent selects only execution parameters: position size, entry thresholds, volatility filters.

Compatibility with current settings is maximum here — we do not touch the loop, learning works in a narrow action space.

Second scenario — move the logic to learning. Previous rules become the environment: the reward function penalizes undesirable actions, action constraints set the risk framework.

Refinement of the existing agent is iterative — on history, then on the stream, where behavior is compared to a benchmark from the old rules. Migration is justified when the rules contradict each other and threshold tuning does not converge.

Third scenario — replace the loop entirely. It is taken when the rules are unprofitable by themselves or there are too many to keep in mind.

Then external risk control is more important: limits, stop conditions, and the decision log live outside the agent — the trained policy does not explain every step.

We choose the scenario by one measurement: what share of decisions is described by explicit rules. High — we layer learning on top, low — we migrate and retrain.

In any variant, a reproducible simulator and trade log are needed, otherwise the learning effect cannot be separated from market change.

Technical concerns: overfitting, latency, robustness

The main objection to reinforcement learning is that growth on history does not transfer to the live market.

Most often the cause is not the idea itself, but future leakage into features and fitting to one volatility regime: the agent memorizes a specific segment instead of market behavior.

We separate validation by time: training on one window, tuning on the next, final evaluation on an out-of-sample segment the agent has not seen. The model must pass identical thresholds at all three stages, otherwise it does not go into work.

How to distinguish agent overfitting from market change?

Look at the gap between the result on training and on the out-of-sample segment — that is the sign of overfitting. Additionally, compare feature distribution and volatility regime: if the market shifted, model retraining is needed, not rule revision.

What happens to open positions during model retraining?

Retraining runs on a copy of the model, the trading loop continues on the current version. The new one goes live only after passing thresholds and warm-up on live data; on divergence, we return to the previous one without a pause in trading.

What decision-making latency do we consider acceptable?

The budget is counted from the arrival of market data to order confirmation, with reserve for network and exchange. If the decision does not fit within the decision-making latency, the order is not sent: a missed entry is cheaper than execution at a price that no longer exists.

What supports capital protection in an unstable market?

Limits, not forecast accuracy: position size limit, daily drawdown stop, automatic risk reduction when spread widens. They trigger regardless of whether the model is right in an individual trade.

Let's discuss the task: we'll come back with estimate and work plan

Send inputs on the task — that is enough to come back with an estimate and work plan, not clarifying questions.

Reinforcement learning is sensitive to history quality and to how the agent's goal is formalized, so specifics at the input directly shorten timelines and determine team composition.

What is useful to send:

  • description of the trading idea: instruments, position holding horizon, what you consider a good result;
  • quote or trade history in any readable format — terminal export, CSV, exchange archive;
  • risk constraints: allowable drawdown, per-trade limit, emergency stop rules;
  • launch loop — test account, exchange sandbox, or live account with limited volume;
  • who remains on your side after handover: analyst, developer, on-call shift;
  • where data will be stored and the model computed — your infrastructure or our loop.

The review takes one pass: we look at the data, check whether the environment is reproducible, and where future leakage occurs in training.

In response, we return an estimate, work plan, and stages: data preparation, simulation environment, agent training, validation on a period outside the training window, handover of the result with documentation and launch on your side.

We describe team composition by roles with load at each stage, so you see who is responsible for what. The first response on inputs — within one to two business days, the estimate and work plan — within three to five business days after the review.

If the data is raw, we will say so immediately and list what needs to be collected before the start.