π Get real-time stocks from TradingView
TypeScript backtestingbacktesting-trading-strategiesbitcoinchartscryptocryptocurrencyethereumrealtime-stocksstocksstocks-apistocks-pricestradingtradingviewtradingview-apitradingview-indicatortradingview-replaytradingview-scraper
Release 4.1.0 (#353)
Mathieu Colmonf04af705f24d
diff --git a/docs/release-4.1.0.md b/docs/release-4.1.0.mdnew file mode 100644index 0000000..b86e4be--- /dev/null+++ b/docs/release-4.1.0.md@@ -0,0 +1,17 @@+# 4.1.0++Release channel: `latest`. Minor release: one new entry point, no breaking change for 4.0.x users.++## Backtest API++New entry point `@mathieuc/tradingview/backtest`, built from the [honest-backtest](../examples/honest-backtest) example (#351, #352). You write the entry rule, `(candles) => [{ bar, direction }]`; the module applies the protocol and returns a JSON report. See the [backtest guide](backtest.md).++- `backtest()` downloads candles once with `getCandles` and freezes them; `runBacktest()` runs synchronously on candles or a saved snapshot; `backtestMany()` runs several markets, with exits per market if needed.+- Look-ahead check: the signal is rerun on truncated history, and the run stops with the new `TradingViewError` code `LOOK_AHEAD` when a signal depends on later bars or repaints.+- Protocol: entry at the next bar's open, fee and adverse slippage on both sides (random baseline included), stop and target in the same candle counted as a loss, gaps filled at the open, warm-up never traded, chronological 70/30 in-sample/out-of-sample split with no position across it, four interchangeable exits, 1 000 seeded random-entry runs per exit and split.+- The report holds identifiers and numbers only (exit ids, exit reasons, `IS`/`OOS`, warning codes), with metrics per segment, buy and hold, trades with bar indices and times. `chartData()` prepares a price chart, and `formatReport()` and `tradesToCsv()` render the report as text and CSV.+- `examples/honest-backtest` uses the module; `examples/backtest-custom-signal.js` shows a custom rule.++The module makes no claim of profitability: a negative or inconclusive result is a valid outcome.++Pre-releases 4.1.0-beta.1 and 4.1.0-beta.2 were published under the `beta` tag. 4.1.0 has the same code as 4.1.0-beta.2; only the version, these notes and the `llms.txt` line about the beta tag change.diff --git a/llms.txt b/llms.txtindex 4788c90..250c5f1 100644--- a/llms.txt+++ b/llms.txt@@ -22,7 +22,7 @@ Low-level API: TradingViewClient, client.createChart() (ChartSession: setMarket,Pine studies need a TradingView account (session cookies). Built-in studies and candles/quotes work anonymously, with history limits.Docs: docs/data-api.md, docs/backtest.md, docs/low-level-api.md, docs/migration-v4.md, docs/v4-coverage.md, docs/v4-reliability.md, docs/protocol-contributing.md. Examples: examples/.-Backtest API (import from '@mathieuc/tradingview/backtest'; since 4.1.0-beta.1, npm tag beta; report format frozen in 4.1.0-beta.2): write only the entry rule, do not write an engine.+Backtest API (import from '@mathieuc/tradingview/backtest', since 4.1.0): write only the entry rule, do not write an engine.- backtest({ symbol, timeframe, years?, credentials?, signal, exits?, fee?, slippage?, splitRatio?, runs?, seed? }) -> { report, snapshot }. runBacktest(candles | snapshot, options) -> report, synchronous, no network.- signal(candles) -> [{ bar, direction: 'long' | 'short', refs? }]: decided at the close of `bar` using bars 0..bar only; entry is always the next bar's open. Optional signal.warmupBars (default 200) and signal.label.- The engine reruns signal on truncated history and throws TradingViewError code LOOK_AHEAD if a signal depends on later bars (or repaints).diff --git a/package-lock.json b/package-lock.jsonindex 507a53b..66f3f0a 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "@mathieuc/tradingview",- "version": "4.1.0-beta.2",+ "version": "4.1.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@mathieuc/tradingview",- "version": "4.1.0-beta.2",+ "version": "4.1.0","license": "ISC","dependencies": {"ws": "^8.18.0"diff --git a/package.json b/package.jsonindex b86793d..6df5271 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "@mathieuc/tradingview",- "version": "4.1.0-beta.2",+ "version": "4.1.0","description": "TradingView market data for JavaScript and TypeScript: candles, quotes, indicators and strategies, with a simple data API and full low-level access.","type": "module","main": "./dist/index.js",