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

  1. Launch Foresight.
  2. Open a Pine Script file via File → Open Script (or drag-and-drop a .pine file onto the window).
  3. Load market data via File → Open Data (any OHLCV CSV), or use the Data Manager to download data directly.
  4. The backtest runs automatically. Results appear in the charts and statistics panels.
  5. 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

  1. Select a provider from the dropdown (Yahoo Finance, TradingView, or Dukascopy).
  2. Choose a timeframe (1m, 5m, 15m, 1H, 4H, Daily, Weekly). Only timeframes supported by the selected provider are shown.
  3. Type in the search box to filter symbols by name, ticker, or asset class.
  4. Click a symbol to select it, then click Download — or simply double-click a symbol to start the download immediately.
  5. 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
SymbolTicker symbol (e.g. BTCUSD, AAPL)
ProviderData source (Yahoo, TradingView, Dukascopy)
TimeframeBar interval (1m through Weekly)
Last UpdatedWhen the dataset was last refreshed
SizeFile size on disk
Auto-updateToggle to enable background updates

Interactions

Auto-Update

Enable the auto-update checkbox on any dataset to keep it current in the background. Foresight checks for staleness automatically:

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
TypeLong or Short
Entry DateEntry timestamp
Entry PriceFill price at entry
Exit DateExit timestamp
Exit PriceFill price at exit
P&LAbsolute profit or loss
P&L %Percentage return
BarsTrade 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 RatioRisk-adjusted return (higher is better)
Win Rate %Percentage of trades that were profitable
Max Drawdown %Worst peak-to-trough equity decline
Profit FactorGross profit divided by gross loss
Trade CountTotal 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:

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).

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.

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.

Keyboard Shortcuts

Shortcut Action
Ctrl+OOpen script
Ctrl+Shift+OOpen data file
Ctrl+SSave script
Ctrl+ZUndo
Ctrl+YRedo
Ctrl+FFind / Replace
Ctrl+GGo to line
Ctrl+/Toggle comment

Supported Pine Script Features

Foresight supports Pine Script V5 and V6 including:

Not yet supported

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.