Documentation
Everything you need to get started with Foresight.
Overview
Foresight is a native C++ backtesting engine for TradingView Pine Script strategies. It transpiles your Pine Script, runs it against OHLCV data locally, and lets you optimise strategy parameters using differential evolution — all without a browser or TradingView subscription.
The application is a standalone Windows desktop app with an integrated script editor, interactive charts, and a built-in data manager for downloading market data.
Quick Start
- Launch Foresight.
- Open a Pine Script file via File → Open Script (or drag-and-drop a
.pinefile onto the window). - Load market data via File → Open Data (any OHLCV CSV), or use the Data Manager to download data directly.
- The backtest runs automatically. Results appear in the charts and statistics panels.
- Adjust parameters with the sliders and enable the optimizer to search for better configurations.
Loading Scripts
Use File → Open Script or press Ctrl+O to open a .pine file.
You can also drag-and-drop a script file directly onto the application window.
The script is compiled immediately and any errors are shown in the editor with red line markers.
Your 8 most recently opened scripts appear under File → Recent Scripts for quick access.
Loading Data
Use File → Open Data or press Ctrl+Shift+O to load an OHLCV CSV file. Foresight accepts standard CSV format with columns for timestamp, open, high, low, close, and volume. Your data stays entirely on your machine.
Alternatively, use the Data Manager to download data directly from supported providers. Recent data files are available under File → Recent Data.
Data Manager
Open the Data Manager from File → Data Manager. It provides a built-in way to browse, download, and manage market data from multiple providers — no external tools or subscriptions needed. Downloaded datasets are stored locally and can be auto-updated in the background.
Browse & Download
The Browse tab lets you search for symbols across all supported providers and download historical data.
Workflow
- Select a provider from the dropdown (Yahoo Finance, TradingView, or Dukascopy).
- Choose a timeframe (1m, 5m, 15m, 1H, 4H, Daily, Weekly). Only timeframes supported by the selected provider are shown.
- Type in the search box to filter symbols by name, ticker, or asset class.
- Click a symbol to select it, then click Download — or simply double-click a symbol to start the download immediately.
- A progress bar shows download status in real time.
Downloaded data is saved as a CSV and added to your My Data library automatically.
My Data Library
The My Data tab shows all datasets you have downloaded.
| Column | Description |
|---|---|
| Symbol | Ticker symbol (e.g. BTCUSD, AAPL) |
| Provider | Data source (Yahoo, TradingView, Dukascopy) |
| Timeframe | Bar interval (1m through Weekly) |
| Last Updated | When the dataset was last refreshed |
| Size | File size on disk |
| Auto-update | Toggle to enable background updates |
Interactions
- Double-click a row to load that dataset into the current backtest and close the Data Manager.
- Right-click a row for a context menu: Load into Backtest, Update Now, or Remove.
Auto-Update
Enable the auto-update checkbox on any dataset to keep it current in the background. Foresight checks for staleness automatically:
- Intraday (1m, 5m, 15m): updates if older than 4 hours
- Hourly (1H, 4H): updates if older than 1 day
- Daily / Weekly: updates if older than 3 days
Updates are incremental — only new bars since the last update are downloaded and appended.
Data Providers
Yahoo Finance
Stocks, ETFs, indices, crypto, forex. Supports 1m, 5m, 15m, 1H, Daily, and Weekly timeframes. No 4H support.
TradingView
All asset classes. Supports all timeframes including 4H.
Dukascopy
Forex pairs, metals, indices, and crypto. Supports all timeframes. Downloads up to 10-15 years of history. Data is fetched from Dukascopy's CDN, decompressed, and resampled to your chosen timeframe.
Running a Backtest
Once a script and data file are loaded, the backtest runs automatically. Results update in real time across all panels — charts, statistics, and the trades list. Adjust any parameter slider to re-run the backtest instantly with the new value.
Trade Report
The Trades tab shows a full breakdown of every trade the strategy executed. You can also access the trade report by double-clicking any entry in the results library — this opens a detailed stats view including the complete trade list for that parameter configuration.
| Column | Description |
|---|---|
| # | Trade number |
| Type | Long or Short |
| Entry Date | Entry timestamp |
| Entry Price | Fill price at entry |
| Exit Date | Exit timestamp |
| Exit Price | Fill price at exit |
| P&L | Absolute profit or loss |
| P&L % | Percentage return |
| Bars | Trade duration in bars |
Winning trades are shown in green, losing trades in red.
CSV Export
Click the Export button at the top of the Trades tab to save the full trade list as a CSV file. A native file dialog opens where you can choose the destination and filename. The exported CSV includes all columns from the trade report — suitable for further analysis in Excel, Python, or any spreadsheet tool.
Statistics & KPIs
The bottom panel displays key performance indicators at a glance:
| Metric | Description |
|---|---|
| Total Return % | Net strategy return over the data period |
| Sharpe Ratio | Risk-adjusted return (higher is better) |
| Win Rate % | Percentage of trades that were profitable |
| Max Drawdown % | Worst peak-to-trough equity decline |
| Profit Factor | Gross profit divided by gross loss |
| Trade Count | Total number of trades executed |
Advanced statistics include annual/monthly returns, standard deviation, Calmar ratio, average win/loss size, consecutive win/loss streaks, and a monthly returns heatmap.
Charts
Foresight provides several chart views, accessible as tabs in the main area:
- Price / Equity — Candlestick chart with trade entry/exit markers (left) and equity curve (right).
- Profit & Loss — Bar chart of per-trade P&L. Green bars for wins, red for losses.
- Oscillators — Indicator plots (RSI, MACD, etc.) synchronised with the price chart.
- Library Statistics — Heatmap of optimisation results across parameter space.
- Trades — The full trade report table (see above).
Differential Evolution Optimizer
Foresight uses differential evolution (DE) to search for optimal parameter configurations intelligently rather than testing every combination by brute force. The optimizer explores parameter space efficiently, converging on high-performing configurations in seconds.
Controls
- Run — Start the optimisation. The button turns red and becomes Stop while running.
- Stop — Gracefully halt the current run.
- Reset — Clear results and restart from the current parameter values.
- Multithreading — Enable to use all CPU cores. Shows thread count when active.
The optimizer displays the current iteration, population size, and best score in real time.
Parameter Controls
Each input.* parameter from your Pine Script appears as a slider in the left sidebar.
Parameters can be toggled active (red — included in optimisation) or inactive (blue — held at the slider value).
- Move a slider to set its value. The backtest re-runs instantly.
- Uncheck a parameter to fix it at its current value during optimisation.
- Parameter ranges are determined from your script's
input()definitions.
Results Library
Every parameter configuration tested by the optimizer is stored in the results library. The library table shows the score, Sharpe ratio, win rate, max drawdown, and trade count for each result.
- Click a row to select it and view its statistics.
- Double-click a row to open a detailed view with the full trade report, equity curve, and monthly returns for that configuration.
- Click column headers to sort results.
- Use the toolbar buttons to Save / Load individual results or the entire library.
Script Editor
The built-in editor supports Pine Script syntax highlighting, error markers, and standard editing features. Compilation errors appear as red markers on the relevant line numbers — hover to see the error message.
- Edit your script directly and the backtest updates on save.
- Font size is adjustable (Normal, Medium, Large) from the editor toolbar.
- If a script uses unsupported features (maps, matrices,
request.security), a dialog lists them.
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| Ctrl+O | Open script |
| Ctrl+Shift+O | Open data file |
| Ctrl+S | Save script |
| Ctrl+Z | Undo |
| Ctrl+Y | Redo |
| Ctrl+F | Find / Replace |
| Ctrl+G | Go to line |
| Ctrl+/ | Toggle comment |
Supported Pine Script Features
Foresight supports Pine Script V5 and V6 including:
- All
strategy.*functions (entry, exit, close, order sizing) - All
ta.*indicators (SMA, EMA, RSI, MACD, Bollinger Bands, ATR, SuperTrend, etc.) math.*andstr.*standard library functions- User-defined functions (UDFs) and methods
- User-defined types (UDTs / structs)
- Enums and switch expressions
- For / for-in / while loops
- Multi-assignment tuple returns
- Ternary chains and conditional expressions
- Drawing objects:
label,line,box - Table functions
input.*parameters (int, float, bool, string, color, source, timeframe)- Series access with
[]history operator varandvarippersistence
Not yet supported
request.security()and otherrequest.*functions (multi-timeframe data)matrix<T>map<K,V>- Custom library imports (
import Author/Library/...)
File Formats
Data (CSV)
Foresight reads standard OHLCV CSV files. Expected columns: timestamp (or date), open, high, low, close, volume. Any CSV exported from TradingView, Yahoo Finance, or similar tools should work directly. The Data Manager downloads data in this format automatically.
Scripts (.pine)
Standard Pine Script V5/V6 files as used on TradingView. You can copy-paste a strategy from
TradingView's editor into a .pine file and load it directly.