Skip to main content
Glama
pineforge-4pass

PineForge-Codegen

backtest_pine_grid

Optimize PineScript strategies by parameter sweeping across input and override grids, then rank results by key metrics to find the best configuration.

Instructions

Use when the user wants to optimize, sweep, tune, or compare PineScript parameter values (e.g. 'try fast length 8/12/19', 'find the best commission/qty settings') rather than test a single configuration — for one fixed configuration use backtest_pine. Run a parameter sweep: transpile the Pine source ONCE (locally, in-container), then re-run the same compiled strategy against the OHLCV CSV across the cartesian product of inputs × overrides grids. Returns a ranked list of {inputs, overrides, summary, elapsed_seconds} entries sorted by sort_by descending, plus the top entry under best. Cap: max_combinations (default 64). Set concurrency > 1 to run backtests in parallel — each docker container has its own startup overhead, so 2-4 is usually plenty.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesPineScript v6 source.
ohlcv_csv_pathYesPath to OHLCV CSV (same format as backtest_pine).
imageNoDocker image override. Defaults to ghcr.io/pineforge-4pass/pineforge-engine:latest.
inputsNoGrid of input.*() names → list of values to sweep. Example: {"Fast Length": [8, 12, 19], "Slow Length": [21, 26, 39]}
overridesNoGrid of strategy(...) header overrides → list of values, one axis per key. Example: {"default_qty_value": [1, 5], "commission_value": [0.04]}. Call list_engine_params for the full catalog with types and enum values.
fixed_inputsNoInputs applied to every combo (overridden by per-combo `inputs` keys).
fixed_overridesNoOverrides applied to every combo (overridden by per-combo `overrides` keys).
runtimeNoEngine runtime args applied to every combo in the sweep. Same shape as backtest_pine.runtime — input_tf / script_tf / bar_magnifier / magnifier_samples / magnifier_dist. Currently fixed across the grid (not swept); add to the grid axes through future versions if you need to vary them.
max_combinationsNoHard cap on combinations. Default 64.
concurrencyNoParallel backtests. Default 1.
include_tradesNoInclude the per-trade list in each result. Default false (saves tokens).
sort_byNosummary.* field to rank by, descending. Default net_pnl.
report_pathNoWhere to write the full sweep JSON IF it is too large to return inline. Oversized sweeps are offloaded here and the tool returns the best + top-ranked combinations + report_path; read the file for all combinations. Defaults to pineforge-grid-<timestamp>.json in the working dir.
Behavior4/5

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

Describes internal process (transpile once, re-run compiled strategy), output format (ranked list, best), and performance constraints (max_combinations, concurrency overhead). Lacks explicit statement on destructiveness or side effects, but overall clear.

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?

Well-structured paragraph, front-loaded with usage guidance, efficient sentences. Could be slightly more concise but appropriate for complexity.

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?

Covers all key aspects: when to use, process, output, constraints, concurrency, and schema included. No output schema, but description sufficiently explains return structure.

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

Parameters3/5

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

Schema provides 100% coverage for all 13 parameters. Description adds general context (e.g., default max_combinations, concurrency advice) but does not significantly deepen meaning beyond what schema already offers.

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?

Clear verb 'optimize, sweep, tune, compare' and resource 'PineScript parameter values'. Explicitly distinguishes from sibling 'backtest_pine' by stating when to use each.

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

Usage Guidelines5/5

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

Provides explicit when-to-use ('optimize, sweep, tune, or compare') and when-not-to-use ('for one fixed configuration use backtest_pine'). Also gives context on concurrency and max_combinations.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pineforge-4pass/pineforge-codegen-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server