Skip to main content
v1.2.0

Reading data from csv

Trading data can be added to the Technical Analysis Chart via code or by reading it from a csv-file. The data itself can be of any source as long as it is given in correct formats. The data source is up to the user to define, as LightningChart does not offer any build-in data providers.

This section explains how to add data to the chart using csv-files. See Adding data in code to assign data to the chart in code.


Csv-file format

The CSV file should contain at least the following columns: Date, Open, Close, High, and Low. Optional fields include Volume and OpenInterest.

The Date column should contain date/time values in any format that can be parsed by the library. In Python Trader, date parsing is handled internally, supporting common formats.

Example of a valid CSV file:

Date,Open,Close,High,Low,Volume
2018-09-18,185.00,186.00,190.00,185.00,918
2018-09-19,187.60,185.20,188.00,185.20,702
2018-09-20,190.00,187.80,190.00,186.40,190
2018-09-21,188.20,186.20,188.40,186.20,234
2018-09-24,186.20,186.60,189.80,183.60,589
2018-09-25,187.40,188.40,188.60,186.80,375
2018-09-26,189.00,190.80,190.80,188.80,822
2018-09-27,190.00,193.40,193.60,184.00,430
2018-09-28,193.20,194.20,194.20,192.80,616

Note that reading trading data from csv-file replaces any existing data. Furthermore, the selected time range determines which data points from the file are shown on the chart.

Adding csv data via user interface

The chart user interface includes Dataset from file button in the left toolbar. Clicking this opens file explorer, allowing browsing csv-files.

Open a csv-file

Adding csv data in code

You can load trading data from a CSV file into the chart using the load_csv() method. This method accepts the path to a CSV file. It also supports the following optional parameters:
• dataset_name: Assign a custom name to the dataset, which will be displayed as the chart's title.
• delimiter: Define the delimiter used in the CSV file (default is ,).

from lightningchart_trader import TAChart

# Your license key
license_key = 'your-license-key'

# Initialize TAChart
trader = TAChart(license_key)

# Load data from a CSV file
trader.load_csv('data/trading_data.csv', dataset_name='Stock Data', delimiter=',')
trader.open()

The load_csv method also allows defining the delimiter used in csv-file to separate entries. This is comma by default.