Skip to main content

RunStrategyBacktest

Runs a compiled NinjaScript strategy through NT8's Strategy Analyzer engine for supported configurations. With optimization, it enumerates a parameter grid. This is a historical job, not deployment of a strategy to a trading account.

PropertyValue
Required scopemcp:trade
ExecutionAsynchronous; poll GetMcpJob with the returned job_id
AccountNT8's isolated Backtest simulation account
PrerequisiteThe strategy class must be available in NT8's compiled Custom assembly

Prepare the class​

A successful CompileNinjaScript(in_memory: true) validates source in the sandbox. Use WriteNinjaScriptFile to save the approved file, then inspect compile_engine. If it is file_only, press F5 in the NinjaScript Editor and resolve errors before backtesting. A sandbox compile alone does not load a new strategy into NT8's normal compiled strategy path.

When iterating, use versioned class names such as MyStrategy_v1 and MyStrategy_v2. Older add-ons may resolve a previously loaded type after recompilation; newer versions prefer fresher assemblies, but versioned names also make the evidence easier to audit.

Single-backtest request​

This is a smoke-check configuration using NT8's built-in SampleMACrossOver. It uses no commission and zero slippage. Confirm the class, instrument, trading-hours template and historical data exist in your installation. Use appropriate costs for a performance assessment.

{
"strategy_class": "SampleMACrossOver",
"instrument": "MES 06-26",
"bars_period": { "period_type": "Minute", "value": 5 },
"from": "2026-04-01T00:00:00Z",
"to": "2026-04-30T23:59:59Z",
"trading_hours": "CME US Index Futures ETH",
"parameters": { "Fast": 10, "Slow": 25 },
"fill": {
"type": "Standard",
"slippage_ticks": 0,
"commission_template": ""
},
"account": { "initial_cash": 100000, "denomination": "UsDollar" },
"timeout_ms": 120000
}

The current field names are strategy_class and bars_period.period_type. Put costs and fill settings in fill. The account argument is an overrides object, not an account-name string. Do not send "account": "Sim101".

ArgumentMeaning
strategy_classBare name of the compiled strategy class
instrumentFull instrument name, including the contract for futures
bars_periodPrimary bar type and value; optional value2 and market_data_type where applicable
from, toISO-8601 UTC timestamps
trading_hoursNT8 template name; omitted means the instrument's primary template
parametersPublic writable strategy-property overrides; use that class's actual names
fillOrder-fill resolution, slippage ticks and commission-template name
accountInitial cash and denomination for the isolated Backtest account
timeout_msOptional elapsed-time ceiling for the job

Poll for the result​

The initial call returns a job reference. Call GetMcpJob with its job_id. Pending or running is not a completed test. Read the terminal status and returned result; retain errors when a job fails or is cancelled. For a successful single run, inspect the metrics and trade detail actually returned by your installation.

Do not fill a response template with assumed profit, drawdown or trade counts. For an engine comparison, match the compiled class, data, dates, trading hours, parameters and supported fill/cost settings in NT8's UI, then compare the two observed result sets.

Parameter sweep​

Add an optimization object to a complete backtest request. For a custom class declaring FastPeriod and SlowPeriod, this produces nine combinations:

{
"optimization": {
"fitness": "MaxNetProfit",
"parameters_sweep": [
{ "name": "FastPeriod", "min": 8, "max": 10, "step": 1 },
{ "name": "SlowPeriod", "min": 20, "max": 22, "step": 1 }
]
}
}

Those names are examples for a custom strategy. SampleMACrossOver uses Fast and Slow instead. Unknown property names return an error with the available names.

Sweeps enumerate Cartesian combinations. The optimizer name is metadata; GeneticOptimizer and StrategyGenerator do not change the loop into those algorithms. Only numeric parameters are sweepable. Fixed parameters are applied to every iteration on add-on 1.13.8 and later, with swept values taking precedence. Older versions did not reapply fixed parameters during a sweep.

Inspect the returned ranking block and each row's fitness_value. If the requested fitness cannot be driven on that NT8 build, the response identifies its NetProfit fallback. keep_best_results and instantiated_on_each_iteration do not control the Cartesian loop. Full per-trade detail is omitted from sweep results; run the selected parameter_values as a separate single backtest to inspect the trades.

Supported-settings boundary​

Tick Replay is not exposed by this MCP interface. fill.type maps to OrderFillResolution. A Tick primary bar series is a tick-bar backtest. Neither that bar type nor High fill resolution enables the Strategy Analyzer's Minute-plus-Tick-Replay mode.

Backtests always use the isolated Backtest account. If that account is unavailable, the tool fails rather than falling back to Sim101 or a live account. A separate DeployStrategy call is required for forward simulation.

Failure handling​

Reported conditionNext step
nt8_build_unsupportedInspect the missing-symbol details and NT8/add-on compatibility
no_isolated_backtest_accountRestore/verify the NT8 Backtest account; do not substitute a trading account
bad_parameterMatch the returned list of valid strategy-property names
Timeout or backtest_abortedInspect the job result and reduce the request size or revise the elapsed-time ceiling
Missing class or historical dataVerify the NT8 rebuild and data availability before retrying

Workflow​

Define rules, inspect symbols, compile the draft, approve the file write, verify the NT8 rebuild, then run a fixed test. Review trade behavior before a bounded sweep. Evaluate selected parameters on separate data. Only then consider a separately approved simulation deployment and verify it through GetDeployedStrategyState.

For prompts, the exact capture checklist and the optional Sim101 step, follow Build an AI NinjaTrader Strategy: Compile, Backtest and Simulate.