const lcjsTrader = require('@lightningchart/lcjs-trader')
const lcjs = require('@lightningchart/lcjs')
lcjsTrader.trader(TRADER_LICENSE).then(async (trader) => {
// Create a trading chart. Optionally, various chart settings can be provided.
const tradingChart = trader.tradingChart({ loadFromStorage: false })
tradingChart.showSearchbar(false)
await fetch(`${document.head.baseURI}examples/assets/0006/DemoData3.csv`).then((res) => res.text()).then((text) => {
tradingChart.loadCsvString(text)
const dataset = tradingChart.getData()
const volumes = tradingChart.getVolumeData()
tradingChart.clearData()
tradingChart.setChartTitle('Real-time demo')
// Add various technical indicators.
tradingChart.indicators().addRelativeStrengthIndex()
tradingChart.indicators().addParabolicSAR()
tradingChart.indicators().addSuperTrend()
tradingChart.indicators().addVolume()
// Add some initial data to the chart.
const initialData = dataset.slice(0, 30)
const date = new Date()
const startTime = new Date(date.setSeconds(date.getSeconds() - 30))
for (let i = 0; i < 30; i++) {
tradingChart.addDataPoint({ open: initialData[1][i], high: initialData[2][i], low: initialData[3][i], close: initialData[4][i],
dateTime: new Date(startTime.setSeconds(startTime.getSeconds() + 1)), volume: volumes[i] })
}
// Adding data points. Simulates real-time applications.
let i = 0
setInterval(function() {
tradingChart.addDataPoint({ open: dataset[1][i], high: dataset[2][i], low: dataset[3][i], close: dataset[4][i],
dateTime: new Date(), volume: volumes[i] }, tradingChart.getPointCount() >= 100)
i++
if (i >= dataset[0].length) {
i = 0
}
}, 1000)
})
})
Real-time Technical Analysis Chart - Editor
Example demonstrating how to add data to Technical Analysis Chart in real-time. addDataPoint() and addDataArray() methods allow pushing data to the chart at any time regardless of the data source. All technical indicators are automatically updated when new data is being pushed.