Changed around line 1
+ const tradeForm = document.getElementById('tradeForm');
+ const tradeTable = document.getElementById('tradeTable').getElementsByTagName('tbody')[0];
+ const ctx = document.getElementById('profitChart').getContext('2d');
+
+ let trades = [];
+ let chart;
+
+ function calculatePL(entry, exit, size, direction) {
+ const pips = (exit - entry) * (direction === 'buy' ? 1 : -1);
+ return pips * size;
+ }
+
+ function addTradeToTable(trade) {
+ const row = tradeTable.insertRow();
+ row.innerHTML = `
+
${trade.pair} | +
${trade.date} | +
${trade.direction} | +
${trade.entry} | +
${trade.exit} | +
${trade.size} | +
${calculatePL(trade.entry, trade.exit, trade.size, trade.direction).toFixed(2)} | + `;
+ }
+
+ function updateChart() {
+ const labels = trades.map(trade => trade.date);
+ const data = trades.map(trade => calculatePL(trade.entry, trade.exit, trade.size, trade.direction));
+
+ if (chart) {
+ chart.destroy();
+ }
+
+ chart = new Chart(ctx, {
+ type: 'line',
+ data: {
+ labels: labels,
+ datasets: [{
+ label: 'Profit/Loss',
+ data: data,
+ borderColor: '#4CAF50',
+ fill: false
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ scales: {
+ y: {
+ beginAtZero: true
+ }
+ }
+ }
+ });
+ }
+
+ tradeForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ const trade = {
+ pair: document.getElementById('pair').value,
+ date: document.getElementById('date').value,
+ direction: document.getElementById('direction').value,
+ entry: parseFloat(document.getElementById('entry').value),
+ exit: parseFloat(document.getElementById('exit').value),
+ size: parseFloat(document.getElementById('size').value)
+ };
+
+ trades.push(trade);
+ addTradeToTable(trade);
+ updateChart();
+
+ tradeForm.reset();
+ });