Technical Analysis Training Simulator
Recent Prices: ${prices.slice(-3).join(', ')}
3-Period SMA: ${sma.toFixed(2)}
`; } else if (strategy === "ema") { const k = 2 / (prices.length + 1); let ema = prices[0]; for (let i = 1; i < prices.length; i++) { ema = prices[i] * k + ema * (1 - k); } result = `Strategy: Exponential Moving Average
All Prices: ${prices.join(', ')}
EMA: ${ema.toFixed(2)}
`; } document.getElementById('simulationResult').innerHTML = result; } window.downloadSimulationPDF = function () { const resultElement = document.getElementById('simulationResult'); const button = document.getElementById('downloadPDF'); if (!resultElement.innerHTML.trim()) { alert("Please simulate a strategy before downloading the PDF."); return; } button.style.display = 'none'; html2canvas(resultElement).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF(); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 10, pdfWidth, pdfHeight); pdf.save("Technical_Analysis_Simulation.pdf"); button.style.display = 'inline-block'; }); } });