Changed around line 1
+ class TradingSimulator {
+ constructor() {
+ this.balance = 0;
+ this.initialBalance = 0;
+ this.riskPerTrade = 0;
+ this.trades = [];
+ this.strategy = 'flat';
+ this.currentBet = 0;
+ this.fibSequence = [1, 1, 2, 3, 5, 8, 13, 21];
+ this.fibIndex = 0;
+ }
+
+ initialize(initialBalance, riskPercentage, strategy) {
+ this.balance = initialBalance;
+ this.initialBalance = initialBalance;
+ this.riskPerTrade = riskPercentage / 100;
+ this.strategy = strategy;
+ this.trades = [];
+ this.currentBet = this.calculateBaseBet();
+ }
+
+ calculateBaseBet() {
+ return this.initialBalance * this.riskPerTrade;
+ }
+
+ executeTrade() {
+ const outcome = Math.random() > 0.5;
+ const profit = outcome ? this.currentBet : -this.currentBet;
+ this.balance += profit;
+ this.trades.push({
+ balance: this.balance,
+ outcome: outcome
+ });
+ this.updateBetSize(outcome);
+ return outcome;
+ }
+
+ updateBetSize(lastOutcome) {
+ switch(this.strategy) {
+ case 'martingale':
+ this.currentBet = lastOutcome ?
+ this.calculateBaseBet() :
+ this.currentBet * 2;
+ break;
+ case 'dalembert':
+ if (lastOutcome) {
+ this.currentBet = Math.max(
+ this.calculateBaseBet(),
+ this.currentBet - this.calculateBaseBet()
+ );
+ } else {
+ this.currentBet += this.calculateBaseBet();
+ }
+ break;
+ case 'fibonacci':
+ if (lastOutcome) {
+ this.fibIndex = Math.max(0, this.fibIndex - 2);
+ } else {
+ this.fibIndex = Math.min(
+ this.fibSequence.length - 1,
+ this.fibIndex + 1
+ );
+ }
+ this.currentBet = this.calculateBaseBet() *
+ this.fibSequence[this.fibIndex];
+ break;
+ default:
+ this.currentBet = this.calculateBaseBet();
+ }
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ const simulator = new TradingSimulator();
+ const startButton = document.getElementById('startTrading');
+ let chart = null;
+
+ startButton.addEventListener('click', () => {
+ const initialBalance = parseFloat(
+ document.getElementById('initialBalance').value
+ );
+ const riskPercentage = parseFloat(
+ document.getElementById('riskPercentage').value
+ );
+ const strategy = document.getElementById('tradingStrategy').value;
+
+ simulator.initialize(initialBalance, riskPercentage, strategy);
+
+ // Run 100 trades
+ for(let i = 0; i < 100; i++) {
+ simulator.executeTrade();
+ }
+
+ updateUI(simulator);
+ });
+
+ function updateUI(simulator) {
+ const currentBalance = document.getElementById('currentBalance');
+ const winRate = document.getElementById('winRate');
+ const totalTrades = document.getElementById('totalTrades');
+
+ const wins = simulator.trades.filter(t => t.outcome).length;
+ const winRateValue = (wins / simulator.trades.length * 100).toFixed(1);
+
+ currentBalance.textContent = `$${simulator.balance.toFixed(2)}`;
+ winRate.textContent = `${winRateValue}%`;
+ totalTrades.textContent = simulator.trades.length;
+
+ updateChart(simulator.trades);
+ }
+
+ function updateChart(trades) {
+ const ctx = document.getElementById('balanceChart').getContext('2d');
+
+ if (chart) {
+ chart.destroy();
+ }
+
+ chart = new Chart(ctx, {
+ type: 'line',
+ data: {
+ labels: trades.map((_, i) => i + 1),
+ datasets: [{
+ label: 'Balance',
+ data: trades.map(t => t.balance),
+ borderColor: '#2a6ef5',
+ tension: 0.1
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false
+ }
+ });
+ }
+ });