Changed around line 1
+ class TradeSimulator {
+ constructor() {
+ this.initialBalance = 10000;
+ this.currentBalance = this.initialBalance;
+ this.trades = [];
+ this.strategy = 'martingale';
+ this.currentBet = 100;
+ this.baseRisk = 0.01;
+ }
+
+ setStrategy(strategy) {
+ this.strategy = strategy;
+ this.resetBet();
+ }
+
+ resetBet() {
+ this.currentBet = this.currentBalance * this.baseRisk;
+ }
+
+ calculateNextBet(lastOutcome) {
+ switch(this.strategy) {
+ case 'martingale':
+ return lastOutcome ? this.baseRisk : this.currentBet * 2;
+ case 'antimartingale':
+ return lastOutcome ? this.currentBet * 2 : this.baseRisk;
+ case 'dalembert':
+ return lastOutcome ? Math.max(this.currentBet - this.baseRisk, this.baseRisk) : this.currentBet + this.baseRisk;
+ case 'fibonacci':
+ return this.calculateFibonacciBet(lastOutcome);
+ default:
+ return this.baseRisk;
+ }
+ }
+
+ calculateFibonacciBet(lastOutcome) {
+ const fibSequence = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
+ let currentIndex = this.trades.length % fibSequence.length;
+ return this.baseRisk * fibSequence[currentIndex];
+ }
+
+ executeTrade() {
+ const outcome = Math.random() >= 0.5;
+ const profit = outcome ? this.currentBet : -this.currentBet;
+ this.currentBalance += profit;
+
+ this.trades.push({
+ tradeNumber: this.trades.length + 1,
+ amount: this.currentBet,
+ outcome: outcome,
+ balance: this.currentBalance
+ });
+
+ this.currentBet = this.calculateNextBet(outcome);
+ this.updateUI();
+ }
+
+ updateUI() {
+ document.getElementById('currentBalance').textContent =
+ new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
+ .format(this.currentBalance);
+
+ const tradeTable = document.getElementById('tradeTable').getElementsByTagName('tbody')[0];
+ const lastTrade = this.trades[this.trades.length - 1];
+
+ const row = tradeTable.insertRow();
+ row.innerHTML = `
+
${lastTrade.tradeNumber} | +
${new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(lastTrade.amount)} | +
${lastTrade.outcome ? 'Win' : 'Loss'} | +
${new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(lastTrade.balance)} | + `;
+
+ this.updateStats();
+ }
+
+ updateStats() {
+ const wins = this.trades.filter(trade => trade.outcome).length;
+ const winRate = (wins / this.trades.length) * 100;
+ const profitLoss = this.currentBalance - this.initialBalance;
+
+ document.getElementById('winRate').textContent = `${winRate.toFixed(1)}%`;
+ document.getElementById('profitLoss').textContent =
+ new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
+ .format(profitLoss);
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ const simulator = new TradeSimulator();
+
+ document.getElementById('strategySelect').addEventListener('change', (e) => {
+ simulator.setStrategy(e.target.value);
+ });
+
+ document.getElementById('startSim').addEventListener('click', () => {
+ simulator.executeTrade();
+ });
+
+ document.getElementById('initialBalance').addEventListener('change', (e) => {
+ simulator.initialBalance = parseFloat(e.target.value);
+ simulator.currentBalance = simulator.initialBalance;
+ simulator.resetBet();
+ });
+
+ document.getElementById('riskPerTrade').addEventListener('change', (e) => {
+ simulator.baseRisk = parseFloat(e.target.value) / 100;
+ simulator.resetBet();
+ });
+ });