Mercury Trading
Automated trading against Capital.com, running on Cloudflare Workers.
A strategy here is a single function. It receives sorted candles, open trades and account state, and returns typed decisions — LONG, EXIT_POSITION, ADJUST_ORDER and the rest — each with the reason it was made.
The backtester hands those decisions to a simulated broker; the cron worker hands the identical decisions to Capital.com. There is no second implementation to drift, so a backtest describes what the same code would have done live.
Where things live
The four sections in the sidebar, and what each one holds.
What happens every five minutes
The cron worker wakes on a five-minute schedule and walks every active campaign through the same four steps.
- 01Context is builtOne Capital.com session is opened per user, market details are fetched once per distinct epic, and an account session is built per account. Campaigns watching the same market share that work.
- 02The strategy runsEach campaign's strategy function is called with its sorted candles, its open trades and the current account state. It returns a list of typed decisions and the reason for each.
- 03Guards are appliedOn a live account, balance must be above the floor or the whole cycle bails out, and any LONG or SHORT without a stop loss is dropped and logged. Demo campaigns skip both.
- 04Results are recordedEnacted decisions become orders and positions on Capital.com; the decision, its reasoning and the resulting trade are written to the ledger you can read on the campaign page.
What a strategy looks like
Strategies live in common/strategies and are registered by key. A campaign names one of those keys, so the same strategy can run on several accounts with different variables.
Nothing in the function touches the network or the database. It reads what it was given and returns decisions, which is why the backtester and the cron worker can both call it unchanged.
Every decision carries a reason, and that string is stored with the trade. Months later the record still says why the position was opened.
Before you let a campaign trade
- A campaign only sends anything to the broker when
enactis on. Leave it off and the campaign still runs, still records its decisions, and touches nothing. demoselects the Capital.com demo environment. Run there until the decision log looks like the backtest did.- The live guards are a floor, not a strategy. They stop a live account trading below a minimum balance and refuse any entry without a stop loss — everything else about risk is the strategy's own job.
- A backtest describes the candles it was run on. Slippage, spread widening and gaps behave differently in a live book, so treat the result as the optimistic case rather than a forecast.
- Trading carries risk of loss. Positions opened here are real positions on a real account unless you have explicitly kept the campaign on demo.