Changed around line 1
+ // Initialize trade data
+ let trades = [];
+ let currencyPairs = new Set();
+
+ // DOM Elements
+ const tradeForm = document.getElementById('tradeForm');
+ const tradeList = document.querySelector('.trade-list');
+ const filterCurrency = document.getElementById('filterCurrency');
+ const totalTrades = document.getElementById('totalTrades');
+ const winRate = document.getElementById('winRate');
+ const avgProfit = document.getElementById('avgProfit');
+ const totalPL = document.getElementById('totalPL');
+ const performanceChart = document.getElementById('performanceChart');
+
+ // Chart initialization
+ const ctx = performanceChart.getContext('2d');
+ const chart = new Chart(ctx, {
+ type: 'line',
+ data: {
+ labels: [],
+ datasets: [{
+ label: 'Cumulative P&L',
+ data: [],
+ borderColor: '#3498db',
+ fill: false
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ scales: {
+ y: {
+ beginAtZero: true
+ }
+ }
+ }
+ });
+
+ // Add trade event
+ tradeForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ const trade = {
+ currencyPair: document.getElementById('currencyPair').value,
+ entryPrice: parseFloat(document.getElementById('entryPrice').value),
+ exitPrice: parseFloat(document.getElementById('exitPrice').value),
+ positionSize: parseFloat(document.getElementById('positionSize').value),
+ notes: document.getElementById('notes').value,
+ date: new Date().toLocaleString()
+ };
+
+ trades.push(trade);
+ currencyPairs.add(trade.currencyPair);
+ updateCurrencyFilter();
+ renderTrades();
+ updateAnalytics();
+ tradeForm.reset();
+ });
+
+ // Render trades
+ function renderTrades(filter = '') {
+ tradeList.innerHTML = '';
+ const filteredTrades = filter ? trades.filter(t => t.currencyPair === filter) : trades;
+
+ filteredTrades.forEach(trade => {
+ const tradeDiv = document.createElement('div');
+ tradeDiv.className = 'trade-entry';
+ const pnl = (trade.exitPrice - trade.entryPrice) * trade.positionSize;
+
+ tradeDiv.innerHTML = `
+
${trade.currencyPair}
+
Entry: ${trade.entryPrice} | Exit: ${trade.exitPrice}
+
Position Size: ${trade.positionSize}
+ ${trade.date}
+ `;
+
+ tradeList.appendChild(tradeDiv);
+ });
+ }
+
+ // Update currency filter options
+ function updateCurrencyFilter() {
+ filterCurrency.innerHTML = '';
+ currencyPairs.forEach(pair => {
+ const option = document.createElement('option');
+ option.value = pair;
+ option.textContent = pair;
+ filterCurrency.appendChild(option);
+ });
+ }
+
+ // Update analytics
+ function updateAnalytics() {
+ totalTrades.textContent = trades.length;
+
+ const winningTrades = trades.filter(t => (t.exitPrice - t.entryPrice) * t.positionSize > 0).length;
+ winRate.textContent = trades.length ? `${((winningTrades / trades.length) * 100).toFixed(1)}%` : '0%';
+
+ const totalProfit = trades.reduce((sum, t) => sum + (t.exitPrice - t.entryPrice) * t.positionSize, 0);
+ totalPL.textContent = totalProfit.toFixed(2);
+ avgProfit.textContent = trades.length ? (totalProfit / trades.length).toFixed(2) : '0';
+
+ // Update chart
+ const cumulativePL = [];
+ let runningTotal = 0;
+ trades.forEach(t => {
+ runningTotal += (t.exitPrice - t.entryPrice) * t.positionSize;
+ cumulativePL.push(runningTotal);
+ });
+
+ chart.data.labels = trades.map((_, i) => `Trade ${i + 1}`);
+ chart.data.datasets[0].data = cumulativePL;
+ chart.update();
+ }
+
+ // Filter trades by currency
+ filterCurrency.addEventListener('change', function() {
+ renderTrades(this.value);
+ });
+
+ // Initial setup
+ updateCurrencyFilter();
+ renderTrades();