Skip to content
BeeSystem
LabSamplesAgentsBuilt by
Open the lab
Tu Duong
WorkCase studyLive deskExperienceContact
Back to portfolio

Case study

A trading-support platform for MetaTrader 5

A private platform that sits between a trader and their MT5 accounts. It sizes orders from the money at risk, manages positions after entry, enforces account limits on the server, and lets the trader practise against live prices without risking money.

Role
Sole designer and engineer
Period
2023 – present
Stack
Go · PostgreSQL · TypeScript/React · MQL5 · Docker
Status
In daily use on live and paper accounts

This page covers the execution and risk side of the platform only.

Try it on live prices

The paper desk runs these trade functions in your browser on live BTC and ETH prices: risk-based sizing, resting and armed orders, ladders, max-R, drawdown floors and the trade magazine, with every action in a journal.

Open the live paper desk

What it does

01Placing an order02Managing an open position03Account limits04Automation with permission05Practice06Operations
01

Placing an order

The ticket starts from how much money the trader is willing to lose, not from a lot size.

  • Size from money at risk

    Risk is a fixed amount or a percentage of capital, and the stop is a price distance. The lot size is derived. When the budget cannot buy the minimum lot, the order rounds up to 0.01 and the ticket shows the real risk of that lot, and the account limits are checked again with that number.

  • Take-profit from a reward-to-risk ratio

    The target is stated as R, a multiple of the stop distance, so changing the stop moves the target with it.

  • Armed entries: limit after return

    Wait until price touches level A, then rest a limit order at return level B. The condition is held by the Expert Advisor, so it keeps working while the server restarts.

  • Margin is not risk

    A pending order holds no margin until it triggers, so a tight stop can produce a lot the account cannot carry at that moment. Margin is checked before sending: automated orders are refused, manual ones get a warning with the numbers.

02

Managing an open position

Positions are keyed by account and ticket, so a trade opened by hand in MetaTrader can be managed the same way.

  • Partial close and close-all

    Close any share of a position, or flatten everything, from the console. The same endpoints serve the trader and the automation.

  • Take-profit ladder

    Up to three levels, each closing a share. The last level replaces the broker's take-profit instead of deleting it, so the broker still holds a backstop if the EA stops. The EA reads progress from the remaining volume, so a repeated command cannot close twice.

  • System exit versus broker backstop

    The platform's own exit rule closes the position. The take-profit at the broker is only a safety net for when the platform is unreachable.

  • Max-R ceiling

    Optionally close automatically when open profit reaches N times the risk taken. One R is frozen at the stop that existed when the rule attached. Otherwise a trailing stop shrinks R, lowers the ceiling onto the price, and closes the trade at breakeven without anyone pressing anything.

03

Account limits

Limits belong to an account, not to an instrument. Otherwise two instruments each think they own the whole room, and the account runs at twice its limit while every screen reports compliance.

  • Logical accounts

    Named slices of one real account. Each slice stores a share, not an amount, so a withdrawal re-prices every slice in proportion and no stale figure keeps sizing orders against money that has left.

  • Daily and overall drawdown floors

    Prop-desk style: the overall floor is fixed from the capital, and the daily floor is pinned at the day's opening balance, so a profit enlarges the room instead of being ignored.

  • The day is cut on a wall clock

    The trading day starts at midnight in the account's time zone, with daylight saving. A day boundary taken as milliseconds modulo 24 hours is an hour out twice a year, enough to put a real loss on the wrong side of a hard limit.

  • Refuse, don't shrink

    An order over a limit is refused in one line, with the numbers that would make it fit. At the limit no new orders open, and open positions keep their stops, because closing them early is a trading decision, not a safety one.

04

Automation with permission

Nothing touches real money unless the trader allowed that action.

  • Click or signed grant

    Each action is either a click or falls under a grant: a signed permission for a bounded scope that expires on its own and can be revoked. A kill switch revokes everything.

  • Watchers can only reduce exposure

    A watcher acting under a grant may close or reduce, never open. This is enforced in code and pinned by a test, so it holds however wide the grant is.

  • No log, no action

    If the action cannot be recorded, it does not happen. An automated close that cannot be reported is not sent.

  • Stale data means no trade

    If the account snapshot is older than its freshness window, the server refuses to execute. Automated sends carry the decision id as the client order id, are never retried automatically, and their outcome is confirmed by reading the broker's book.

05

Practice

Practising with different rules from real trading teaches a system that does not exist, so practice goes through the same gates.

  • Paper venue inside the EA

    Orders in simulation mode fill against live bid and ask inside the Expert Advisor and report back through the same channels as real ones. The mode is a stored per-instrument setting, and the server refuses a ticket that disagrees with it.

  • Paper tickets that cannot collide

    Paper ticket numbers live in a range real tickets do not reach, survive a reload, and stay below 2⁵³ so the browser can repeat them exactly.

  • A trade magazine

    Manual entries spend bullets from a magazine that refills every 30 minutes, and a winning trade earns one back. It turns over-trading from a habit into a visible budget. Automated orders do not spend bullets.

  • Missions and a challenge ladder

    Goals such as doubling the account or a winning streak with a minimum gain per trade. In the challenge, the trader declares the hand (trades per day, reward-to-risk, win rate) and the stake is solved from it, not typed in.

06

Operations

Run by one person on one Linux VPS, so the operational rules are written into the tools.

  • Two brokers, one platform

    Two MetaTrader terminals from different brokers run side by side on the same Linux host. Orders route by credential, and an ambiguous choice is refused rather than guessed.

  • The EA is the last gate

    The server's view of the book can be seconds old, so the Expert Advisor re-checks side, stop and book before it sends anything.

  • Deploys that respect open orders

    A deploy that would restart the link to the terminal refuses while orders are armed or resting, prints them, and needs an explicit override.

  • Rebuild only what changed

    Each service is stamped with a hash of its full source dependency set, so a change rebuilds only the services that import it, in seconds.

The path of an order

Every order, whether manual or automated, takes the same path. Each gate either passes the order on or refuses it with a reason.

  1. 1

    Console

    Ticket: risk, stop distance, R

  2. 2

    Server gates

    Freshness · account limits · margin · permission

  3. 3

    Execution

    Routed by credential to one broker

  4. 4

    Expert Advisor

    Last checks · ladders · armed entries · paper venue

  5. 5

    Broker

    Live or paper fill

↺The EA pushes positions and orders back. The server keeps the book and the ledger in PostgreSQL, and watchers read from there.

Three bugs worth reading about

None of them failed a test or threw an error, and all three involved real money.

  • 01

    A permission from the future

    An executor read the clock before reading its permission record. The record was stamped a few milliseconds later, looked as if it came from the future, and every firing was refused. Tests froze both clocks and stayed green. The fix reads the later of the two times.

  • 02

    Long is not buy

    Positions say long or short, orders say buy or sell. Comparing a position's side to "sell" was false for every short, so its exit would have pointed the wrong way and closed on arming. Side is now parsed by a function that refuses anything it does not know.

  • 03

    The right ticket, the wrong broker

    With two accounts under one user, the terminal session was chosen by user rather than by credential, so the console priced the trade for one broker and the order landed on the other. The choice now happens where the refusal is written, and two candidates without a declaration are refused.

Try the sizing rules

The same arithmetic the ticket uses, running entirely in your browser. It is not connected to any account or market data.

Order ticket

Risk as

Side

100 for gold (XAUUSD) on most brokers

Lot size
0.20
Risk budget
$100.00
Real risk of this lot
$100.00
Stop loss
4,095.00
Take profit
4,110.00
Reward at target
$200.00

Risk per attempt for a series

Declare the drawdown you accept for a series and how many attempts it must survive, and the risk per attempt is derived.

Risk per attempt
1.048%
On the capital above
$104.81
Naive split (drawdown ÷ attempts)
1.000%

Each stake is a share of the balance left after the previous loss, so the exact figure is f = 1 − (1 − D)^(1/N), slightly above D ÷ N.

Illustration only. Not financial advice.

Want to see the real thing?

The platform runs on private accounts, so there is no public login. I am glad to walk through it live, including the console, the EA and the code.

Get in touch
BeeSystem

Data research without code, with an AI assistant.

Checking the lab…

Product

  • Research workspace
  • Samples
  • Strategy lab
  • Paper desk

Developers

  • For agents (MCP)
  • Lanes

Company

  • Built by Tu Duong
  • Contact

Legal

  • Privacy
  • Terms
© 2026 BeeSystem · Samples: vega-datasets (NOAA, Scripps, NASA, EIA, Gapminder) · Market data: Binance public APIA research tool. Market results are not financial advice: past results on one market and one window say little about the future.