Optimize strategy (2-D parameter sweep)
optimize_strategyRun a 2-D parameter sweep over two strategy node config fields, backtesting a grid of combinations to find the settings with the highest Sharpe ratio.
Instructions
Run a 2-D parameter sweep over two numeric config fields of a strategy's nodes, backtesting a steps x steps grid of value combinations; waits up to 600s. Use this after a strategy already trades sensibly (verify with run_backtest) to tune thresholds, periods, or sizes. Call get_strategy FIRST to obtain the exact node ids and config field names, and get_capabilities to keep the bounds inside the indicator's real range (sweeping an RSI threshold from 80 to 140 wastes half the grid on cells that can never fire). Parameters: strategyId (UUID, required); xNodeId and xField, yNodeId and yField (strings from get_strategy, required) - the two axes must not be the same node id AND field; xMin/xMax and yMin/yMax (finite numbers, required) with xMax > xMin and yMax > yMin - the steps values are spaced linearly and include both endpoints (xMin 10, xMax 30, steps 5 tests 10, 15, 20, 25, 30); steps (whole number 3 to 10, default 5); timeframe: one of 1m, 5m, 15m, 1h, 1d - optional override, defaults to what the server picks. Returns the best cell (highest sharpe, preferring cells that actually traded), the strategy's current cell, the sharpe grid as compact rows of numbers (rows = y values top to bottom, columns = x values left to right), the sweep window and timeframe, and a verbatim warning when every cell produced zero trades. If the wait times out, the error includes a jobId to check with get_job_status.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xMax | Yes | Highest x value to test. Must be strictly greater than xMin. | |
| xMin | Yes | Lowest x value to test. Must be strictly less than xMax. | |
| yMax | Yes | Highest y value to test. Must be strictly greater than yMin. | |
| yMin | Yes | Lowest y value to test. Must be strictly less than yMax. | |
| steps | No | Grid resolution per axis; steps x steps backtests are run. Whole number 3 to 10, default 5. | |
| xField | Yes | Numeric config field on the x node, e.g. 'period' or 'threshold'. | |
| yField | Yes | Numeric config field on the y node. Must differ from xField when yNodeId equals xNodeId. | |
| xNodeId | Yes | Node id whose config field varies along the x axis. Exactly as returned by get_strategy. | |
| yNodeId | Yes | Node id whose config field varies along the y axis. May be the same node as xNodeId. | |
| timeframe | No | Optional bar timeframe override: one of 1m, 5m, 15m, 1h, 1d (lowercase). Defaults to what the server picks for the strategy. | |
| strategyId | Yes | Strategy UUID. Find it with list_strategies (it is also returned by create_strategy). Not a strategy name. |