Bringing Pine Scripts into TradingView¶
Paste the .pine file generated by forge pine generate into TradingView and configure an alert.
1. Open the Pine Editor¶
Open a chart in TradingView and click the "Pine Editor" tab at the bottom of the screen.
2. Paste the script¶
Copy the contents of the generated .pine file into the editor and click "Add to chart" (▶).
3. Create an alert¶
Click the bell icon (Alerts) on the top right → "Create alert".
- Condition: Select your script
- Webhook URL: Enable and paste the alpha-strike endpoint
- Message: Use the JSON payload format described in the alpha-strike integration guide
4. Tip: in-script alert conditions¶
Defining alertcondition inside Pine Script makes alert setup cleaner.
// Example alertcondition definition
longSignal = ta.crossover(ema_fast, ema_slow)
shortSignal = ta.crossunder(ema_fast, ema_slow)
alertcondition(longSignal, title="Long Entry", message="long")
Next step
Configure the webhook receiver in TradingView × alpha-strike Integration.
5. Verifying the Pine Script through an MCP server (issue #523)¶
forge pine verify ships the generated Pine Script to TradingView Desktop via a third-party MCP server for verification. Beyond compile checks, it can compare TV's Strategy Tester aggregate metrics or per-trade list against the matching alpha-forge backtest, surfacing translation errors mechanically.
5.1 Prerequisites¶
- Launch TradingView Desktop with
--remote-debugging-port=9222 - Run a third-party MCP server in a separate process:
tradesdontlie/tradingview-mcp— good for compile checks and chart manipulationoviniciusramosp/tradingview-mcp(vinicius fork) — strong on Strategy Tester aggregates; recommended formetrics/signalmodes- Configure the endpoint and flavor in
forge.yaml:
tv_mcp:
pine_verify:
enabled: true
endpoint: "node /opt/tv-mcp/server.js"
runtime: node
flavor: vinicius # use vinicius for metrics/signal
timeout_seconds: 60
5.2 verify modes¶
| Mode | What it verifies | Recommended flavor |
|---|---|---|
compile_only |
Pine Script syntax / compilation only | tradesdontlie is sufficient |
metrics |
TV Strategy Tester aggregates (PF, win rate, total trades, etc.) vs alpha-forge metrics | vinicius (avoids the data_get_strategy_results bug in tradesdontlie) |
signal |
tradesdontlie: match TV trade list against alpha-forge trades by entry time and compute a match rate.vinicius: returns no timestamps, so the comparison auto-switches to count-based (totals only, issue #580) |
tradesdontlie (when time matching is required) / vinicius (when counts alone suffice) |
regime |
Not implemented (parked) — upstream MCP servers do not expose a time-series study tool, so the HMM state column cannot be retrieved per-bar (issue #581). Selecting this mode fails fast with an explicit error. | — |
5.3 Workflow¶
# 1. Compile-only verification (fastest)
forge pine verify --strategy spy_sma_v1 \
--mcp-server "node /opt/tv-mcp/server.js"
# 2. Strategy Tester metrics comparison (vinicius recommended)
forge pine verify --strategy spy_sma_v1 \
--check-mode metrics \
--symbol SPY --interval D \
--mcp-server-flavor vinicius \
--auto-backtest \
--output reports/verify_spy.md
# 3. Per-trade time matching (±60s tolerance, 95% match required)
forge pine verify --strategy spy_sma_v1 \
--check-mode signal \
--symbol SPY --interval D \
--mcp-server-flavor vinicius \
--auto-backtest \
--match-tolerance-seconds 60 \
--min-match-rate 0.95
5.4 Avoiding period mismatches¶
A large total_trades gap in metrics mode is usually a data-period mismatch (yfinance's ~5y vs TradingView's decades). To bring alpha-forge's history closer to TradingView's, switch the data fetch to the TradingView MCP provider:
See the forge data command reference for details.
5.5 Report output¶
With --output reports/xxx.md, the Markdown report includes:
- Strategy ID and verification mode
- Comparison table (alpha-forge ↔ TradingView)
- Detected mismatches (items beyond tolerance)
- Verdict (PASS / FAIL) and recommended actions
Combine with forge journal report --with-chart --symbol SPY --interval D to get strategy history + verification + TV chart in a single page.