Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const canvas = document.getElementById('chart');
+ const ctx = canvas.getContext('2d');
+ let bankrollHistory = [];
+
+ function resetChart() {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ bankrollHistory = [];
+ }
+
+ function updateStats(finalBankroll, initialBankroll, wins, totalBets) {
+ document.getElementById('finalBankroll').textContent = `$${finalBankroll.toFixed(2)}`;
+ document.getElementById('profitLoss').textContent = `$${(finalBankroll - initialBankroll).toFixed(2)}`;
+ document.getElementById('winRate').textContent = `${((wins/totalBets) * 100).toFixed(1)}%`;
+ }
+
+ function drawChart() {
+ const width = canvas.width;
+ const height = canvas.height;
+ const padding = 40;
+
+ ctx.clearRect(0, 0, width, height);
+
+ // Draw axes
+ ctx.beginPath();
+ ctx.moveTo(padding, padding);
+ ctx.lineTo(padding, height - padding);
+ ctx.lineTo(width - padding, height - padding);
+ ctx.strokeStyle = '#2c3e50';
+ ctx.stroke();
+
+ // Plot points
+ if (bankrollHistory.length > 1) {
+ const max = Math.max(...bankrollHistory);
+ const min = Math.min(...bankrollHistory);
+ const xStep = (width - 2 * padding) / (bankrollHistory.length - 1);
+ const yScale = (height - 2 * padding) / (max - min);
+
+ ctx.beginPath();
+ ctx.moveTo(padding, height - padding - (bankrollHistory[0] - min) * yScale);
+
+ for (let i = 1; i < bankrollHistory.length; i++) {
+ const x = padding + i * xStep;
+ const y = height - padding - (bankrollHistory[i] - min) * yScale;
+ ctx.lineTo(x, y);
+ }
+
+ ctx.strokeStyle = '#3498db';
+ ctx.lineWidth = 2;
+ ctx.stroke();
+ }
+ }
+
+ function simulateBets() {
+ const initialBet = parseFloat(document.getElementById('initialBet').value);
+ const initialBankroll = parseFloat(document.getElementById('bankroll').value);
+ const progression = document.getElementById('progression').value;
+ const numBets = parseInt(document.getElementById('numBets').value);
+
+ let currentBankroll = initialBankroll;
+ let currentBet = initialBet;
+ let wins = 0;
+ resetChart();
+ bankrollHistory.push(currentBankroll);
+
+ for (let i = 0; i < numBets; i++) {
+ // Simulate bet outcome (50/50 chance)
+ const win = Math.random() >= 0.5;
+
+ if (win) {
+ currentBankroll += currentBet;
+ wins++;
+ // Adjust bet size based on progression
+ switch(progression) {
+ case 'martingale':
+ currentBet = initialBet;
+ break;
+ case 'dalembert':
+ currentBet = Math.max(initialBet, currentBet - initialBet);
+ break;
+ case 'fibonacci':
+ currentBet = initialBet;
+ break;
+ case 'flat':
+ currentBet = initialBet;
+ break;
+ }
+ } else {
+ currentBankroll -= currentBet;
+ // Adjust bet size based on progression
+ switch(progression) {
+ case 'martingale':
+ currentBet *= 2;
+ break;
+ case 'dalembert':
+ currentBet += initialBet;
+ break;
+ case 'fibonacci':
+ currentBet = currentBet * 1.618;
+ break;
+ case 'flat':
+ currentBet = initialBet;
+ break;
+ }
+ }
+
+ // Ensure bet size doesn't exceed bankroll
+ currentBet = Math.min(currentBet, currentBankroll);
+ bankrollHistory.push(currentBankroll);
+ }
+
+ updateStats(currentBankroll, initialBankroll, wins, numBets);
+ drawChart();
+ }
+
+ document.getElementById('simulate').addEventListener('click', simulateBets);
+
+ // Initial chart setup
+ function resizeCanvas() {
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ drawChart();
+ }
+
+ window.addEventListener('resize', resizeCanvas);
+ resizeCanvas();
+ });