PineForge Codegen

by pineforge-4pass

Not rated
GitHub

About

Local MCP server: AI writes PineScript v6, bundled engine transpiles to C++ and backtests against Binance data — no API key, fully local.

Details

Author
pineforge-4pass
Categories
Finance, Developer Tools

Setup

Install PineForge Codegen in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/pineforge-4pass/pineforge-codegen-mcp

Follow the installation instructions in the repository README, then restart your MCP client.

What can you do with PineForge Codegen MCP?

- Transpile Pine Script v6 to C++— Convert a Pine Script v6 strategy into a C++ translation unit withtranspile_pinewithout running a backtest.
- Backtest a Pine strategy against OHLCV data— Run a single deterministic backtest withbacktest_pine, providing source, CSV path, and optional input/override/runtime parameters.
- Sweep strategy parameters in one run— Usebacktest_pine_gridto test all combinations ofinputs×overridesagainst a single CSV, with ranking and optional concurrency.
- Fetch Binance OHLCV data for backtesting— Pull spot or USDT-perp klines viafetch_binance_ohlcvand write a backtest-ready CSV with automatic pagination.
- Discover available Binance symbols— List or filter tradable symbols withbinance_symbolsbefore fetching market data.
- Inspect engine parameters and Pine coverage— Querylist_engine_paramsfor every accepted override and runtime knob, or usecheck_pine_featureandget_coverage_topicto verify Pine language support.

Self-contained stdio MCP server: an AI agent writes PineScript v6, and the bundledpineforge-releaseimage transpiles it to C++ and backtests it against Binance market data — all in one container, in-process.Fully local— the image bundles thepineforge-codegentranspiler, so Pine → C++ → backtest run with no host Docker daemon.No API key, nothing leaves the box.

Runs as a self-contained container over stdio — engine bundled, in-process, no host Docker daemon, no API key. Mount a working dir at/workso the server can read/write your CSVs:

docker run --rm -i -v "$PWD:/work" ghcr.io/pineforge-4pass/pineforge-backtest-mcp:latest

Only requirement: Docker, and outbound network for the Binance fetch tools. Wire it into your MCP client below.

Want the fastest try with no Docker and no API key? Paste the Streamable HTTP endpoint into any MCP client:

Tradeoff vs this repo: the hosted server ismetered(per-IP weekly quota onbacktest_pine+ Cloudflare edge rate-limiting) and runs against afixed, sealed crypto data-lake(Binance spot + USDT-perp). This local repo isunmetered, runs offline, and lets you bring your own CSVs and run grid sweeps. Repo:pineforge-mcp-public.

Mount a directory at/work; pointfetch_binance_ohlcv/backtest_pineat paths under it. (-iis required; never add-t— a TTY corrupts the stdio JSON-RPC stream.)

{ "mcpServers": { "pineforge-backtest": { "command": "docker", "args": [ "run", "--rm", "-i", "-v", "${workspaceFolder}:/work", "ghcr.io/pineforge-4pass/pineforge-backtest-mcp:latest" ] } } }

(In Cursor: Settings → MCP → New MCP Server → paste the above.)

claude mcp add pineforge-backtest \ -- docker run --rm -i -v "$PWD:/work" ghcr.io/pineforge-4pass/pineforge-backtest-mcp:latest

The capability gap this closes.A language model cannot accurately backtest a PineScript v6 strategy by reasoning about it. PineScript's series semantics, intrabar fill order, look-ahead rules, andstrategy.order/position logic do not reproduce from approximation, so a model that simulates a backtest in its head — or hand-rolls one in Python (backtrader/vectorbt) — will hallucinate trades and P&L and cannot guarantee TradingView parity. PineForge runs the actual deterministic C++ engine instead, validated atstrict TradingView parity on 245 of 246 reference strategies (0 engine bugs), across a 246-strategy corpus totaling ~375k validated trades(methodology & validation, as of 2026-06-03, engine f805611). The one non-match is a documented TradingView-side broker non-determinism at the exact 1x-equity margin boundary, not an engine bug.

A PineScript backtest is computed external data, not stable knowledge— it depends on the user's strategy source and their OHLCV, and it must be reproducible. That is a tool call, not a recall task.

When these tools are the right fit.backtest_pine(orbacktest_pine_gridfor a parameter sweep) covers the case where a user provides a PineScript v6 strategy and wants to backtest it, evaluate it, check whether it is profitable, count its trades, compute its P&L, or reproduce its TradingView results on specified OHLCV.transpile_pinecovers the Pine → C++ conversion only.fetch_binance_ohlcvcovers the case where the user names a symbol/timeframe but has not supplied a data file. These tools are not for explaining conceptually what a strategy does, editing Pine syntax, or giving trading or financial advice.

Honest limits.Offline; PineScript v6; needs Docker. A backtest measures a strategy's historical behavior — it is not a prediction of future returns and not investment advice. Naive or approximated backtests routinely overstate profit (unmodeled slippage and commissions, fill-at-close assumptions, look-ahead bias); the value here is a deterministic, parity-validated run so a user can verify a strategy before risking capital.

Free, local, zero-I/O catalog of every key accepted bybacktest_pine/backtest_pine_grid, split into two groups:

- strategy_overrides— the 9strategy(...)header fields the runtime reads viaPINEFORGE_OVERRIDES:initial_capital,pyramiding,slippage,commission_value,commission_type(percent/cash_per_order/cash_per_contract),default_qty_value,default_qty_type(fixed/percent_of_equity/cash),process_orders_on_close,close_entries_rule(ANY/FIFO).
- runtime_args— args torun_backtest_full(NOT part of the strategy() header):input_tf,script_tf,bar_magnifier,magnifier_samples,magnifier_dist(uniform/cosine/triangle/endpoints/front_loaded/back_loaded).

Each entry is{key, type, enum?, description}. Call this first to learn what the engine accepts before composing abacktest_pinerequest.

{ "source": "//@version=6\nstrategy(\"sma cross\")\n...", "ohlcv_csv_path": "./btcusdt_15m_7d.csv", // Optional: override Pine input.() values without touching the source. // Keys = the second arg of input.*(...) (e.g. "Fast Length"). "inputs": { "Fast Length": 8, "Slow Length": 21 }, // Optional: override strategy(...) header fields. Each key is typed — // call list_engine_params for the catalog. "overrides": { "initial_capital": 100000, "default_qty_type": "percent_of_equity", "default_qty_value": 10, "commission_type": "percent", "commission_value": 0.04, "slippage": 2, "pyramiding": 0, "process_orders_on_close": true, "close_entries_rule": "ANY" }, // Optional: engine runtime args (NOT strategy() header). Use script_tf // to aggregate the input CSV into a coarser strategy timeframe — the // engine REJECTS script_tf finer than input_tf with a structured error // ({"engine":"pineforge","error":"..."}, exit code 1). "runtime": { "input_tf": "15", "script_tf": "60", "bar_magnifier": true, "magnifier_samples": 8, "magnifier_dist": "endpoints" } }

inputsis forwarded as thePINEFORGE_INPUTSenv var to the engine,overridesasPINEFORGE_OVERRIDES, and eachruntimefield as a separatePINEFORGE_INPUT_TF/PINEFORGE_SCRIPT_TF/PINEFORGE_BAR_MAGNIFIER/PINEFORGE_MAGNIFIER_SAMPLES/PINEFORGE_MAGNIFIER_DISTenv var. Empty / unset → defaults fromstrategy.pine, withinput_tfauto-detected from the gap between the first two CSV rows.

Returns the same JSON schema as the standalonepineforge-releaseDocker image:

{ "engine": "pineforge", "summary": { "total_trades": 49, "net_pnl": -190.85, ... }, "applied_inputs": { "Fast Length": "8", "Slow Length": "21" }, "applied_overrides": { "default_qty_value": "5" }, "trades": [ ... ], "elapsed_seconds": 0.0042, "_meta": { "strategy_cpp_bytes": 5079, "image": "ghcr.io/.../pineforge-release:latest" } }

Transpiles the Pine sourceonce(locally, in-container) then runs the same compiled binary against the cartesian product ofinputs×overrides. Returns a ranked list plus the top entry underbest.

{ "source": "//@version=6\nstrategy(\"macd\")\n...", "ohlcv_csv_path": "./btcusdt_15m_7d.csv", // Each axis is {key: list-of-values}. All combinations are tried. "inputs": { "Fast Length": [8, 12, 19], "Slow Length": [21, 26, 39] }, "overrides": { "default_qty_value": [1, 5], "commission_value": [0.04] }, // Optional knobs: "fixed_inputs": { "Source": "close" }, // applied to every combo "fixed_overrides": {}, // typed strategy() overrides "runtime": { "input_tf": "15", // engine runtime args, fixed "script_tf": "60" }, // across the sweep "max_combinations": 64, // hard cap "concurrency": 2, // parallel docker runs "include_trades": false, // omit per-trade lists "sort_by": "net_pnl" // ranking metric }

Writes a backtest-ready CSV (headertimestamp,open,high,low,close,volume, timestamp = open time in UNIX ms UTC) from Binance's public endpoints. No auth required. Requests > 1000 bars are paginated automatically. Output path is subject to the same cwd scope asohlcv_csv_path(relax withPINEFORGE_ALLOW_ANYWHERE=1).

{ "symbol": "BTCUSDT", "interval": "15m", // 1s, 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M "market": "spot", // or "usdt_perp" for USDT-margined perpetual futures "limit": 672, // total bars; > 1000 paginates "output_path": "./btcusdt_15m_7d.csv" // Optional: "start_time" / "end_time" in UNIX ms UTC. }
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.