Skip to main content
Glama
pineforge-4pass

PineForge-Codegen

backtest_pine

Run a deterministic PineScript v6 strategy backtest on an OHLCV CSV locally via Docker, returning trades, P&L, and drawdown from a real engine.

Instructions

Run a real, deterministic backtest of a PineScript v6 strategy — prefer this over estimating its trades or P&L by reasoning, which is unreliable for Pine (series semantics, intrabar fills, and strategy.* order logic do not reproduce from approximation). Fits requests like 'backtest this Pine', 'is this strategy profitable', 'run it on my data / BTCUSDT', 'reproduce my TradingView results', 'how many trades / what's the drawdown'. Transpile a PineScript v6 strategy and run it against an OHLCV CSV via the pineforge-release Docker image on the user's local machine. Fully local — transpile + backtest run in-container; nothing leaves the box, no API key. Optional inputs overrides input.() named values from the Pine source (keys = the second arg of input.(...) calls, e.g. 'Fast Length'). Optional overrides overrides strategy(...) header fields (initial_capital, commission_value, default_qty_value, pyramiding, slippage, default_qty_type, commission_type, process_orders_on_close). Returns the parsed JSON report (summary, trades, applied_inputs, applied_overrides, elapsed_seconds). If the report is too large to return inline it is written to report_path and a compact summary (with that path) is returned instead. Use backtest_pine_grid for sweeps.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageNoDocker image override. Defaults to ghcr.io/pineforge-4pass/pineforge-engine:latest.
inputsNoMap of Pine input.*() names → value (string/number/bool). Sent as PINEFORGE_INPUTS env var to the runtime.
sourceYesPineScript v6 source.
runtimeNoEngine runtime args (NOT strategy() header) controlling timeframe semantics and intra-bar fill simulation. input_tf / script_tf set the chart and strategy timeframes — script_tf must be coarser than or equal to input_tf or the engine rejects the run. bar_magnifier + magnifier_samples + magnifier_dist enable sub-bar price-path sampling for tighter stop / limit fills. Each field is optional and only forwarded to the engine when set. Call list_engine_params for the full catalog.
overridesNostrategy(...) header overrides. Each key maps to a single argument of the Pine `strategy()` call; only the keys you set are applied. Sent as PINEFORGE_OVERRIDES env var. Call list_engine_params for the full catalog with types and enum values.
report_pathNoWhere to write the full JSON report IF it is too large to return inline. Large backtests (long trade lists + equity curves) are offloaded to this file and the tool returns a compact summary + report_path instead; read the file for the complete trades/equity. Defaults to pineforge-backtest-<timestamp>.json in the working dir.
ohlcv_csv_pathYesAbsolute or cwd-relative path to OHLCV CSV with header 'timestamp,open,high,low,close,volume' (timestamp = UNIX ms UTC).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.9.30
    • removedInput schema / properties / inputs / additionalProperties / anyOf
      Removed value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "number"
      -  },
      -  {
      -    "type": "boolean"
      -  }
      -]
    • addedInput schema / properties / inputs / additionalProperties / type
      Added value: +[
      +  "string",
      +  "number",
      +  "boolean"
      +]
  2. Changed1 schema field changedv0.9.0
    • addedInput schema / properties / report_path
      Added value: +{
      +  "description": "Where to write the full JSON report IF it is too large to return inline. Large backtests (long trade lists + equity curves) are offloaded to this file and the tool returns a compact summary + report_path instead; read the file for the complete trades/equity. Defaults to pineforge-backtest-<timestamp>.json in the working dir.",
      +  "type": "string"
      +}
  3. First observedv0.8.4

TDQS

A4.8/5.0
Behavior5/5

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

With no annotations, the description carries the full behavioral burden and does so: fully local execution, nothing leaves the box, no API key required, deterministic results, and the large-report offloading behavior (full JSON to report_path, compact summary returned instead). It even enumerates the returned report fields (summary, trades, applied_inputs, applied_overrides, elapsed_seconds). This is unusually rich disclosure for an unannotated tool.

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 well front-loaded: the core action, the prefer-over-estimation rule, and example requests come first, and the parameter details come last. There is mild redundancy in re-listing the overrides header fields that the schema already enumerates, which keeps it from a 5.

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 tool with nested objects, no output schema, and zero annotations, the description covers the execution environment, the inputs needed (Pine source + OHLCV CSV path with expected header), and the return contract including the offload-to-file fallback. Nothing an agent needs to invoke it correctly is missing.

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

Parameters4/5

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

Schema coverage is 100%, so the schema already documents every field, which sets a baseline of 3. The description adds genuine meaning beyond the schema by explaining that inputs keys are the second arg of input.*() calls (e.g. 'Fast Length') and that overrides map to strategy() header fields, and it lets the agent know the full catalog lives in list_engine_params.

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?

The description states a specific verb and resource ('Run a real, deterministic backtest of a PineScript v6 strategy') and elaborates the mechanism (transpile + run against OHLCV CSV via the pineforge-release Docker image). It also explicitly routes to siblings: 'Use backtest_pine_grid for sweeps' and distinguishes itself from estimation-by-reasoning. An agent can select it over transpile_pine or backtest_pine_grid without opening any schema.

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?

It names concrete triggering requests ('backtest this Pine', 'is this strategy profitable', 'run it on my data / BTCUSDT') and an explicit exclusion with rationale (prefer this over estimating P&L by reasoning). It also names the alternative for parameter sweeps (backtest_pine_grid) and points to list_engine_params for the full catalog.

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