Skip to main content
Glama

FiveSocket MT5 MCP Server

Backtest a trading rule

run_backtest
Read-onlyIdempotent

Backtest a simple trading rule on one connected account's own broker candles. Read-only: it replays past bars and never places or changes a broker order. Write the rule from the user's plain words: one exact broker symbol, a timeframe (M1, M5, M15, H1, H4 or D1), a UTC from and to range of at most 50000 bars, one entry per side with an optional exit condition, a stop, an optional target, the risk per trade and an initialBalance. A condition compares two series with above, below, crossesAbove or crossesBelow; join 2 to 8 of them with {kind: "all" | "any", conditions: [...]}. A series is {kind: "price", field: "close"}, {kind: "constant", value: 70}, or an indicator with a period: sma, ema, rsi, atr, highest or lowest. Example for "buy gold on H1 when the close crosses above the 50 EMA, stop 1.5 ATR, target 2R, risk 1%": {symbol: "XAUUSD", timeframe: "H1", from: "2026-01-01T00:00:00Z", to: "2026-11-01T00:00:00Z", entries: [{side: "long", when: {kind: "crossesAbove", left: {kind: "price", field: "close"}, right: {kind: "ema", period: 50}}}], stop: {kind: "atr", period: 14, multiple: 1.5}, target: {kind: "riskMultiple", value: 2}, risk: {kind: "percentOfBalance", value: 1}, initialBalance: 10000}. A condition is read when a bar closes and the order fills at the next bar's open. The result has the trade count, net result in the account currency, maximum drawdown, win rate, profit factor, costs paid, an equity curve of at most 50 points and the assumptions. Report the dates the bars actually cover, from metadata.firstBarTime and lastBarTime, not the dates asked for; when the broker's history is shorter than the range, the first assumption says so. Tell the user the assumptions that shape the numbers: historical spread is approximated from one value per bar, today's swap rates and tick value are applied to the whole period, the account's headline leverage is used for every symbol, and commission is counted only when costs.commissionPerLotRoundTrip is supplied. When the user has set a prop-firm program for the account, propOverlay estimates from bar data whether the run would have touched the daily or maximum loss floor or reached the first target; set initialBalance to the challenge size for that. Present it as an estimate and never as a pass or a fail: a backtest that stays inside the limits can still fail live, and propOverlay.limits lists what it cannot see. A backtest describes the past and does not predict future results. On insufficient_history widen the range or lower the timeframe; on symbol_not_found use details.suggestions; on backtest_unsupported the symbol cannot be priced, so say so and do not estimate; on invalid_request fix the named field and call again.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "rule": "<rule>",
      "accountId": "<accountId>"
    },
    "name": "run_backtest"
  }
}

Input Schema

NameRequiredDescriptionDefault
ruleYes
costsNo
accountIdYes
includeTradesNoReturn the first 500 trades as well as the summary.

Output Schema

NameRequiredDescriptionDefault
loginYes
serverYes
sourceYesLive MT5 source data the run read: the account currency and leverage, and the symbol's current contract, swap and tick-value facts. The candles themselves are not returned.
accountIdYes
calculatedYesFiveSocket-calculated values. A backtest is a simulation over past bars, not a forecast.
propOverlayYesPresent when the user has set a prop-firm program for the account: an estimate, from bar data, of how the same run would have fared against that program's daily-loss, maximum-loss and profit-target rules. A run that stays inside the limits here can still fail live.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already cover read-only/idempotent safety, but the description adds substantial behavior beyond them: conditions are read at bar close and fills occur at the next bar's open, spread is approximated from one value per bar, today's swap and tick value are applied to the whole period, headline leverage is used for all symbols, and commission only counts when costs.commissionPerLotRoundTrip is supplied. It also enumerates error codes and their remedies and explicitly frames propOverlay as an estimate, not a pass/fail.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

It is long, but for a tool with a deeply nested rule schema nearly every sentence earns its place, and the purpose and read-only constraint are front-loaded. The main weakness is that it arrives as one undifferentiated block with no breaks, making the error-handling and propOverlay guidance harder to scan than it needs to be.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex, nested, multi-parameter backtest tool, the description covers the full path an agent needs: how to translate plain words into a rule, fill semantics, the assumption set to disclose, propOverlay caveats, and each error's remedy. An output schema exists, so restating the result fields is slight redundancy rather than a gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is only 25%, yet the description compensates by explaining the rule grammar in plain language: condition comparators (above/below/crossesAbove/crossesBelow), the 2-to-8 all/any join, the three series kinds (price, constant, indicator with period), and the timeframe enum, plus a complete worked example JSON. Minor gaps remain around accountId and the costs costMultiplier/spreadFloorPoints fields, but the semantic burden is largely carried.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb and resource: 'Backtest a simple trading rule on one connected account's own broker candles,' then immediately narrows the scope with 'Read-only: it replays past bars and never places or changes a broker order.' No sibling tool does rule backtesting, so an agent can distinguish it from get_candles or prop_status without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives rich conditional guidance: when the user has a prop-firm program, set initialBalance to the challenge size; on insufficient_history widen the range or lower the timeframe; on symbol_not_found use details.suggestions. It does not name sibling alternatives (e.g., use get_candles for raw data or prop_status for current limits), so the when-not-to-use routing is left implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.