simgold / index.html
alsaif66's picture
it all looks nice but nothing works - Follow Up Deployment
4f6e821 verified
Raw History Blame Contribute Delete
63.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Gold Futures Pro Trading Platform</title> <script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-crosshair@1.2.0"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation@2.1.0/dist/chartjs-plugin-annotation.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/hammerjs@2.0.8"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <script> tailwind.config = { darkMode: 'class', theme: { extend: { colors: { 'trade-green': '#10b981', 'trade-red': '#ef4444', 'trade-blue': '#3b82f6', 'trade-yellow': '#eab308', 'trade-purple': '#a855f7', 'dark-bg': '#0f172a', 'dark-panel': '#1e293b', 'dark-border': '#334155', 'dark-text': '#e2e8f0', 'dark-hover': '#334155' } } } } </script> <style> .candle-up { background-color: #10b981; border-color: #10b981; } .candle-down { background-color: #ef4444; border-color: #ef4444; } .position-long { border-left: 4px solid #10b981; } .position-short { border-left: 4px solid #ef4444; } .indicator-line { border-top-width: 2px; } .chart-container { height: 60vh; } @media (max-width: 768px) { .chart-container { height: 50vh; } } .position-card { transition: all 0.2s ease; } .position-card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); } .indicator-selector { transition: all 0.2s ease; } .indicator-selector:hover { background-color: #334155; } .trade-line { position: absolute; height: 2px; width: 100%; cursor: pointer; z-index: 10; } .trade-line-handle { position: absolute; width: 12px; height: 12px; border-radius: 50%; cursor: move; z-index: 11; } .trade-marker { position: absolute; width: 8px; height: 8px; border-radius: 50%; z-index: 9; } .glow { box-shadow: 0 0 15px rgba(59, 130, 246, 0.5); } .price-change-up { animation: priceUp 1s ease; } .price-change-down { animation: priceDown 1s ease; } @keyframes priceUp { 0% { background-color: rgba(16, 185, 129, 0.3); } 100% { background-color: transparent; } } @keyframes priceDown { 0% { background-color: rgba(239, 68, 68, 0.3); } 100% { background-color: transparent; } } .order-book-row { transition: all 0.2s ease; } .order-book-row:hover { background-color: #334155; } .depth-bar { position: absolute; top: 0; right: 0; height: 100%; opacity: 0.2; z-index: -1; } </style> </head> <body class="bg-dark-bg text-dark-text"> <div class="flex flex-col min-h-screen"> <!-- Header --> <header class="bg-dark-panel border-b border-dark-border p-3 shadow-lg"> <div class="container mx-auto flex flex-col md:flex-row justify-between items-center"> <div class="flex items-center mb-3 md:mb-0"> <div class="bg-gradient-to-r from-trade-yellow to-amber-600 w-10 h-10 rounded-lg flex items-center justify-center mr-3"> <i class="fas fa-coins text-white text-xl"></i> </div> <div> <h1 class="text-xl font-bold">Gold Futures Pro</h1> <div class="flex items-center text-sm text-gray-400"> <span>GCZ2023</span> <span class="mx-2">•</span> <span>COMEX</span> <span class="mx-2">•</span> <span>100 oz</span> </div> </div> </div> <div class="flex flex-wrap justify-center gap-3"> <div class="bg-dark-panel px-4 py-2 rounded-lg border border-dark-border flex items-center"> <div class="mr-3"> <div class="text-xs text-gray-400">Last Price</div> <div class="text-xl font-bold" id="last-price">$1,923.50</div> </div> <div class="mr-3"> <div class="text-xs text-gray-400">Change</div> <div class="text-trade-green font-bold" id="price-change">+12.30 (+0.64%)</div> </div> <div class="mr-3"> <div class="text-xs text-gray-400">Bid/Ask</div> <div class="font-medium" id="bid-ask">1923.4 / 1923.6</div> </div> <div> <div class="text-xs text-gray-400">Volume</div> <div class="font-medium" id="volume">24,523</div> </div> </div> </div> <div class="flex flex-wrap justify-center gap-3 mt-3 md:mt-0"> <div class="bg-dark-panel px-4 py-2 rounded-lg border border-dark-border"> <span class="text-gray-400">Balance:</span> <span class="font-bold ml-2">$<span id="balance">10,000.00</span></span> </div> <div class="bg-dark-panel px-4 py-2 rounded-lg border border-dark-border"> <span class="text-gray-400">Equity:</span> <span class="font-bold ml-2">$<span id="equity">10,000.00</span></span> </div> <div class="bg-dark-panel px-4 py-2 rounded-lg border border-dark-border"> <span class="text-gray-400">Margin:</span> <span class="font-bold ml-2">$<span id="margin">0.00</span></span> </div> </div> </div> </header> <!-- Main Content --> <div class="flex flex-col lg:flex-row flex-1 overflow-hidden"> <!-- Left Panel - Order Entry & Order Book --> <div class="w-full lg:w-80 bg-dark-panel p-4 border-r border-dark-border overflow-y-auto"> <div class="mb-6"> <h2 class="text-lg font-semibold mb-3 flex items-center"> <i class="fas fa-ticket-alt mr-2 text-trade-blue"></i> Order Entry </h2> <div class="bg-dark-bg rounded-lg p-4 mb-4"> <div class="grid grid-cols-2 gap-3 mb-3"> <div> <label class="block text-sm font-medium mb-1">Type</label> <select class="w-full bg-dark-panel border border-dark-border rounded px-3 py-2"> <option>Market</option> <option>Limit</option> <option>Stop</option> </select> </div> <div> <label class="block text-sm font-medium mb-1">Duration</label> <select class="w-full bg-dark-panel border border-dark-border rounded px-3 py-2"> <option>Day</option> <option>GTC</option> </select> </div> </div> <div class="mb-3"> <label class="block text-sm font-medium mb-1">Price</label> <input type="text" class="w-full bg-dark-panel border border-dark-border rounded px-3 py-2" value="1923.50" disabled> </div> <div class="mb-4"> <label class="block text-sm font-medium mb-1">Quantity (oz)</label> <div class="flex"> <button class="bg-dark-hover px-3 py-2 rounded-l" id="qty-down">-</button> <input type="number" id="trade-qty" class="w-full bg-dark-panel border-y border-dark-border px-2 py-2 text-center" min="1" max="100" value="1"> <button class="bg-dark-hover px-3 py-2 rounded-r" id="qty-up">+</button> </div> </div> <div class="grid grid-cols-2 gap-2"> <button id="btn-buy" class="bg-trade-green text-white py-2 rounded-lg font-semibold hover:bg-green-600 transition glow"> <i class="fas fa-arrow-up mr-1"></i> Buy </button> <button id="btn-sell" class="bg-trade-red text-white py-2 rounded-lg font-semibold hover:bg-red-600 transition glow"> <i class="fas fa-arrow-down mr-1"></i> Sell </button> </div> </div> </div> <div class="mb-6"> <h2 class="text-lg font-semibold mb-3 flex items-center"> <i class="fas fa-book mr-2 text-trade-purple"></i> Order Book </h2> <div class="bg-dark-bg rounded-lg overflow-hidden"> <div class="grid grid-cols-3 text-xs text-gray-400 bg-dark-panel px-3 py-2 border-b border-dark-border"> <div>Qty</div> <div>Bid</div> <div>Ask</div> </div> <div id="order-book"> <!-- Order book rows will be generated here --> </div> </div> </div> </div> <!-- Chart Area --> <div class="flex-1 flex flex-col"> <!-- Chart Controls --> <div class="bg-dark-panel border-b border-dark-border p-3 flex flex-wrap gap-2"> <div class="flex"> <button class="px-3 py-1 bg-dark-bg border border-dark-border border-r-0 rounded-l hover:bg-dark-hover" data-timeframe="1">1m</button> <button class="px-3 py-1 bg-dark-bg border border-dark-border border-r-0 hover:bg-dark-hover" data-timeframe="5">5m</button> <button class="px-3 py-1 bg-dark-bg border border-dark-border border-r-0 hover:bg-dark-hover" data-timeframe="15">15m</button> <button class="px-3 py-1 bg-dark-bg border border-dark-border hover:bg-dark-hover" data-timeframe="60">1H</button> <button class="px-3 py-1 bg-dark-bg border border-dark-border border-l-0 hover:bg-dark-hover" data-timeframe="240">4H</button> <button class="px-3 py-1 bg-dark-bg border border-dark-border border-l-0 rounded-r hover:bg-dark-hover" data-timeframe="D">D</button> </div> <div class="flex"> <button class="px-3 py-1 bg-dark-bg border border-dark-border border-r-0 rounded-l hover:bg-dark-hover" data-type="candle">Candles</button> <button class="px-3 py-1 bg-dark-bg border border-dark-border rounded-r hover:bg-dark-hover" data-type="ohlc">OHLC</button> </div> <div class="flex ml-auto gap-2"> <button class="px-3 py-1 bg-trade-blue text-white rounded hover:bg-blue-600" id="btn-refresh"> <i class="fas fa-sync-alt mr-1"></i> Refresh </button> <button class="px-3 py-1 bg-trade-green text-white rounded hover:bg-green-600" id="btn-start"> <i class="fas fa-play mr-1"></i> Start </button> <button class="px-3 py-1 bg-trade-red text-white rounded hover:bg-red-600" id="btn-stop" disabled> <i class="fas fa-stop mr-1"></i> Stop </button> </div> </div> <!-- Chart Container --> <div class="chart-container relative bg-dark-bg p-2"> <canvas id="price-chart"></canvas> <div id="trade-markers"></div> </div> <!-- Sub Chart (Indicators) --> <div class="h-1/4 bg-dark-panel border-t border-dark-border p-2"> <canvas id="indicator-chart"></canvas> </div> </div> <!-- Right Panel - Positions & Tools --> <div class="w-full lg:w-80 bg-dark-panel p-4 border-l border-dark-border overflow-y-auto"> <div class="flex justify-between items-center mb-4"> <h2 class="text-lg font-semibold flex items-center"> <i class="fas fa-tools mr-2 text-trade-yellow"></i> Trading Tools </h2> <div class="flex"> <button class="p-2 bg-dark-bg rounded hover:bg-dark-hover mr-1" id="tool-hline"> <i class="fas fa-grip-lines"></i> </button> <button class="p-2 bg-dark-bg rounded hover:bg-dark-hover mr-1" id="tool-trend"> <i class="fas fa-slash"></i> </button> <button class="p-2 bg-dark-bg rounded hover:bg-dark-hover" id="tool-clear"> <i class="fas fa-trash"></i> </button> </div> </div> <div class="mb-6"> <h2 class="text-lg font-semibold mb-3 flex items-center"> <i class="fas fa-wave-square mr-2 text-trade-purple"></i> Indicators </h2> <div class="space-y-2"> <div class="indicator-selector flex items-center p-2 rounded cursor-pointer bg-dark-bg" data-indicator="ma"> <i class="fas fa-chart-line mr-2 text-trade-blue"></i> <span>Moving Averages</span> </div> <div class="indicator-selector flex items-center p-2 rounded cursor-pointer bg-dark-bg" data-indicator="macd"> <i class="fas fa-chart-bar mr-2 text-trade-purple"></i> <span>MACD</span> </div> <div class="indicator-selector flex items-center p-2 rounded cursor-pointer bg-dark-bg" data-indicator="rsi"> <i class="fas fa-chart-area mr-2 text-trade-yellow"></i> <span>RSI</span> </div> <div class="indicator-selector flex items-center p-2 rounded cursor-pointer bg-dark-bg" data-indicator="bollinger"> <i class="fas fa-arrows-alt-h mr-2 text-trade-green"></i> <span>Bollinger Bands</span> </div> </div> </div> <div class="mb-6"> <h2 class="text-lg font-semibold mb-3 flex items-center"> <i class="fas fa-list mr-2 text-trade-green"></i> Open Positions </h2> <div id="open-positions" class="space-y-3"> <!-- Positions will be added here dynamically --> </div> </div> <div> <h2 class="text-lg font-semibold mb-3 flex items-center"> <i class="fas fa-history mr-2 text-trade-purple"></i> Closed Positions </h2> <div id="closed-positions" class="space-y-3"> <!-- Closed positions will be added here dynamically --> </div> </div> </div> </div> <!-- Footer --> <footer class="bg-dark-panel border-t border-dark-border p-3 text-xs text-gray-500"> <div class="container mx-auto flex flex-col md:flex-row justify-between items-center"> <div class="mb-2 md:mb-0"> <span>Gold Futures Pro Trading Platform v1.0</span> <span class="mx-2">•</span> <span>Simulated Trading</span> </div> <div> <span>Data: Simulated</span> <span class="mx-2">•</span> <span>Prices delayed by 0ms</span> <span class="mx-2">•</span> <span>Last update: <span id="last-update">--:--:--</span></span> </div> </div> </footer> </div> <script> // Trading Platform State const state = { balance: 10000, equity: 10000, margin: 0, positions: [], closedPositions: [], indicators: { ma: { enabled: true, periods: [20, 50, 100] }, macd: { enabled: true }, rsi: { enabled: true, period: 14 }, bollinger: { enabled: true, period: 20, stdDev: 2 }, fib: { enabled: false } }, chartType: 'candle', timeframe: 5, // minutes tradeQuantity: 1, tradeLines: [], markers: [], drawingMode: null, drawings: [], lastPrice: 1923.50, bid: 1923.40, ask: 1923.60, volume: 24523, priceChange: 12.30, priceChangePercent: 0.64 }; // Initialize Charts const priceCtx = document.getElementById('price-chart').getContext('2d'); const indicatorCtx = document.getElementById('indicator-chart').getContext('2d'); // Generate initial price data with realistic gold patterns function generatePriceData(count = 200) { const data = []; let price = state.lastPrice; let trend = 0; // Current trend direction (-1 to 1) let volatility = 1.5; // Base volatility // Simulate economic news events const newsEvents = []; for (let i = 0; i < count / 20; i++) { newsEvents.push(Math.floor(Math.random() * count)); } for (let i = 0; i < count; i++) { // Adjust volatility based on time (higher during NY/London overlap) const hour = (new Date(Date.now() - (count - i) * state.timeframe * 60000)).getHours(); const isActiveHours = (hour >= 8 && hour < 17); // 8am-5pm NY time const currentVolatility = isActiveHours ? volatility * 1.5 : volatility; // Occasionally change trend direction if (Math.random() < 0.05) { trend = Math.max(-1, Math.min(1, trend + (Math.random() - 0.5) * 0.5)); } // Apply trend with some randomness let changePercent = trend * currentVolatility + (Math.random() - 0.5) * currentVolatility * 0.5; // Simulate news events if (newsEvents.includes(i)) { changePercent += (Math.random() > 0.5 ? 1 : -1) * currentVolatility * 2; } // Mean reversion - pull price back toward 1900-2000 range if (price > 2000) { changePercent -= 0.1 * currentVolatility; } else if (price < 1900) { changePercent += 0.1 * currentVolatility; } const changeAmount = price * changePercent / 100; const newPrice = price + changeAmount; // Create candle with realistic wicks const open = price; const close = newPrice; const range = Math.abs(changeAmount) * 2; const high = Math.max(open, close) + Math.random() * range * 0.7; const low = Math.min(open, close) - Math.random() * range * 0.7; data.push({ time: new Date(Date.now() - (count - i) * state.timeframe * 60000), open: open, high: high, low: low, close: close }); price = newPrice; // Gradually adjust volatility volatility = Math.max(0.5, Math.min(3, volatility + (Math.random() - 0.5) * 0.1)); } return data; } // Generate order book data function generateOrderBook() { const bids = []; const asks = []; // Generate bids let bidPrice = state.bid; for (let i = 0; i < 8; i++) { bids.push({ price: bidPrice, quantity: Math.floor(Math.random() * 20) + 1, total: Math.floor(Math.random() * 100) + 20 }); bidPrice -= 0.1; } // Generate asks let askPrice = state.ask; for (let i = 0; i < 8; i++) { asks.push({ price: askPrice, quantity: Math.floor(Math.random() * 20) + 1, total: Math.floor(Math.random() * 100) + 20 }); askPrice += 0.1; } return { bids, asks }; } // Render order book function renderOrderBook() { const orderBook = generateOrderBook(); const orderBookEl = document.getElementById('order-book'); orderBookEl.innerHTML = ''; // Find max total for depth visualization let maxTotal = 0; [...orderBook.bids, ...orderBook.asks].forEach(order => { if (order.total > maxTotal) maxTotal = order.total; }); // Render asks (top to bottom) for (let i = 7; i >= 0; i--) { const ask = orderBook.asks[i]; const row = document.createElement('div'); row.className = 'order-book-row grid grid-cols-3 px-3 py-1 relative'; const depthWidth = (ask.total / maxTotal) * 100; row.innerHTML = ` <div class="text-right">${ask.quantity}</div> <div></div> <div class="text-trade-red">${ask.price.toFixed(2)}</div> <div class="depth-bar bg-trade-red" style="width: ${depthWidth}%"></div> `; orderBookEl.appendChild(row); } // Render spread const spreadRow = document.createElement('div'); spreadRow.className = 'order-book-row grid grid-cols-3 px-3 py-2 bg-dark-panel border-y border-dark-border'; spreadRow.innerHTML = ` <div class="text-center text-xs text-gray-400">Spread</div> <div class="text-center font-semibold">${(state.ask - state.bid).toFixed(2)}</div> <div class="text-center text-xs text-gray-400">${((state.ask - state.bid) / state.lastPrice * 10000).toFixed(1)} pips</div> `; orderBookEl.appendChild(spreadRow); // Render bids for (let i = 0; i < 8; i++) { const bid = orderBook.bids[i]; const row = document.createElement('div'); row.className = 'order-book-row grid grid-cols-3 px-3 py-1 relative'; const depthWidth = (bid.total / maxTotal) * 100; row.innerHTML = ` <div></div> <div class="text-trade-green">${bid.price.toFixed(2)}</div> <div class="text-right">${bid.quantity}</div> <div class="depth-bar bg-trade-green" style="width: ${depthWidth}%"></div> `; orderBookEl.appendChild(row); } } // Update market data display function updateMarketData() { document.getElementById('last-price').textContent = `$${state.lastPrice.toFixed(2)}`; document.getElementById('bid-ask').textContent = `${state.bid.toFixed(1)} / ${state.ask.toFixed(1)}`; document.getElementById('volume').textContent = state.volume.toLocaleString(); const changeText = state.priceChange >= 0 ? `+${state.priceChange.toFixed(2)} (+${state.priceChangePercent.toFixed(2)}%)` : `${state.priceChange.toFixed(2)} (${state.priceChangePercent.toFixed(2)}%)`; document.getElementById('price-change').textContent = changeText; document.getElementById('price-change').className = state.priceChange >= 0 ? 'text-trade-green font-bold' : 'text-trade-red font-bold'; } // Calculate indicators function calculateIndicators(data) { // Moving Averages const maLines = []; if (state.indicators.ma.enabled) { for (const period of state.indicators.ma.periods) { const maData = []; for (let i = period - 1; i < data.length; i++) { let sum = 0; for (let j = 0; j < period; j++) { sum += data[i - j].close; } maData.push({ time: data[i].time, value: sum / period }); } maLines.push(maData); } } // RSI let rsiData = []; if (state.indicators.rsi.enabled) { const period = state.indicators.rsi.period; let avgGain = 0; let avgLoss = 0; // Initial calculation for (let i = 1; i <= period; i++) { const change = data[i].close - data[i-1].close; if (change > 0) avgGain += change; else avgLoss -= change; } avgGain /= period; avgLoss /= period; // First RSI value const rs = avgLoss === 0 ? 100 : avgGain / avgLoss; rsiData.push({ time: data[period].time, value: 100 - (100 / (1 + rs)) }); // Subsequent values for (let i = period + 1; i < data.length; i++) { const change = data[i].close - data[i-1].close; let currentGain = change > 0 ? change : 0; let currentLoss = change < 0 ? -change : 0; avgGain = (avgGain * (period-1) + currentGain) / period; avgLoss = (avgLoss * (period-1) + currentLoss) / period; const rs = avgLoss === 0 ? 100 : avgGain / avgLoss; rsiData.push({ time: data[i].time, value: 100 - (100 / (1 + rs)) }); } } // MACD let macdData = []; if (state.indicators.macd.enabled) { const ema12 = calculateEMA(data, 12); const ema26 = calculateEMA(data, 26); // Calculate MACD line (12-day EMA - 26-day EMA) for (let i = 0; i < ema26.length; i++) { macdData.push({ time: data[i + 25].time, macd: ema12[i + 14] - ema26[i], signal: 0 }); } // Calculate Signal line (9-day EMA of MACD) if (macdData.length >= 9) { const signalPeriod = 9; let signalSum = 0; // Initial signal calculation for (let i = 0; i < signalPeriod; i++) { signalSum += macdData[i].macd; } macdData[signalPeriod-1].signal = signalSum / signalPeriod; // Subsequent signal values for (let i = signalPeriod; i < macdData.length; i++) { macdData[i].signal = (macdData[i-1].signal * (signalPeriod-1) + macdData[i].macd) / signalPeriod; } } } // Bollinger Bands let bollingerData = []; if (state.indicators.bollinger.enabled) { const period = state.indicators.bollinger.period; const stdDev = state.indicators.bollinger.stdDev; for (let i = period - 1; i < data.length; i++) { let sum = 0; for (let j = 0; j < period; j++) { sum += data[i - j].close; } const sma = sum / period; let variance = 0; for (let j = 0; j < period; j++) { variance += Math.pow(data[i - j].close - sma, 2); } const std = Math.sqrt(variance / period); bollingerData.push({ time: data[i].time, upper: sma + (std * stdDev), middle: sma, lower: sma - (std * stdDev) }); } } return { ma: maLines, rsi: rsiData, macd: macdData, bollinger: bollingerData }; } // Helper functions for indicators function calculateEMA(data, period) { const ema = []; const k = 2 / (period + 1); let emaValue = data.slice(0, period).reduce((sum, d) => sum + d.close, 0) / period; for (let i = period; i < data.length; i++) { emaValue = (data[i].close - emaValue) * k + emaValue; ema.push(emaValue); } return ema; } function calculateSignal(macdData, index, period) { if (index < period) return 0; let sum = 0; for (let i = 0; i < period; i++) { sum += macdData[index - i].macd; } return sum / period; } // Initialize charts let priceChart, indicatorChart; let priceData = generatePriceData(); let indicators = calculateIndicators(priceData); function initCharts() { // Destroy existing charts if they exist if (priceChart) priceChart.destroy(); if (indicatorChart) indicatorChart.destroy(); // Create price chart // Register required plugins Chart.register(Chart.Zoom); Chart.register(Chart.Crosshair); priceChart = new Chart(priceCtx, { type: state.chartType === 'candle' ? 'bar' : 'bar', data: { datasets: [{ label: 'Gold Futures', data: priceData.map(d => ({ x: d.time, o: d.open, h: d.high, l: d.low, c: d.close })), color: { up: '#10b981', down: '#ef4444', unchanged: '#777' } }] }, options: { responsive: true, maintainAspectRatio: false, animation: { duration: 0 // Disable animations for better performance }, plugins: { zoom: { pan: { enabled: true, mode: 'xy' }, zoom: { wheel: { enabled: true }, pinch: { enabled: true }, mode: 'xy' } } }, scales: { x: { type: 'time', time: { unit: 'minute' }, grid: { color: 'rgba(255, 255, 255, 0.05)' }, ticks: { color: '#94a3b8' } }, y: { position: 'right', ticks: { callback: function(value) { return '$' + value.toFixed(2); }, color: '#94a3b8' }, grid: { color: 'rgba(255, 255, 255, 0.05)' } } }, plugins: { legend: { display: false }, tooltip: { backgroundColor: '#1e293b', titleColor: '#e2e8f0', bodyColor: '#cbd5e1', borderColor: '#334155', borderWidth: 1, callbacks: { label: function(context) { const data = context.raw; if (state.chartType === 'candle') { return [ `O: $${data.o.toFixed(2)}`, `H: $${data.h.toFixed(2)}`, `L: $${data.l.toFixed(2)}`, `C: $${data.c.toFixed(2)}` ]; } else { return `Price: $${data.c.toFixed(2)}`; } } } }, crosshair: { line: { color: '#3b82f6', width: 1, dash: [4, 4] }, sync: { enabled: true, group: 1 }, zoom: { enabled: true } } } }, plugins: [Chart.Crosshair] }); // Create indicator chart indicatorChart = new Chart(indicatorCtx, { type: 'line', data: { datasets: [ { label: 'RSI', data: indicators.rsi.map(d => ({x: d.time, y: d.value})), borderColor: '#a855f7', borderWidth: 2, pointRadius: 0, yAxisID: 'y' }, { label: 'Overbought', data: indicators.rsi.map(d => ({x: d.time, y: 70})), borderColor: '#ef4444', borderWidth: 1, borderDash: [5, 5], pointRadius: 0, yAxisID: 'y' }, { label: 'Oversold', data: indicators.rsi.map(d => ({x: d.time, y: 30})), borderColor: '#10b981', borderWidth: 1, borderDash: [5, 5], pointRadius: 0, yAxisID: 'y' } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { x: { type: 'time', time: { unit: 'minute' }, display: false }, y: { min: 0, max: 100, ticks: { stepSize: 20, color: '#94a3b8' }, grid: { color: 'rgba(255, 255, 255, 0.05)' } } }, plugins: { legend: { display: false }, crosshair: { line: { color: '#3b82f6', width: 1, dash: [4, 4] }, sync: { enabled: true, group: 1 } } } }, plugins: [Chart.Crosshair] }); // Add indicators to price chart addIndicatorsToChart(); } function addIndicatorsToChart() { // Add Moving Averages if (state.indicators.ma.enabled) { const colors = ['#3b82f6', '#eab308', '#a855f7']; state.indicators.ma.periods.forEach((period, idx) => { priceChart.data.datasets.push({ label: `MA ${period}`, data: indicators.ma[idx].map(d => ({x: d.time, y: d.value})), borderColor: colors[idx], borderWidth: 1.5, pointRadius: 0, type: 'line' }); }); } // Add Bollinger Bands if (state.indicators.bollinger.enabled) { priceChart.data.datasets.push({ label: 'Bollinger Upper', data: indicators.bollinger.map(d => ({x: d.time, y: d.upper})), borderColor: 'rgba(59, 130, 246, 0.5)', borderWidth: 1, pointRadius: 0, type: 'line' }); priceChart.data.datasets.push({ label: 'Bollinger Middle', data: indicators.bollinger.map(d => ({x: d.time, y: d.middle})), borderColor: '#3b82f6', borderWidth: 1, pointRadius: 0, type: 'line' }); priceChart.data.datasets.push({ label: 'Bollinger Lower', data: indicators.bollinger.map(d => ({x: d.time, y: d.lower})), borderColor: 'rgba(59, 130, 246, 0.5)', borderWidth: 1, pointRadius: 0, type: 'line' }); } priceChart.update(); } // Trading Functions function placeTrade(type) { if (!priceData || priceData.length === 0) return; const lastPrice = state.lastPrice; const position = { id: Date.now(), type: type, symbol: 'GC', quantity: state.tradeQuantity, entryPrice: lastPrice, entryTime: new Date(), takeProfit: type === 'buy' ? lastPrice * 1.01 : lastPrice * 0.99, stopLoss: type === 'buy' ? lastPrice * 0.99 : lastPrice * 1.01, currentPrice: lastPrice, closed: false }; state.positions.push(position); updatePositionPanels(); // Add trade marker addTradeMarker(position); // Show confirmation const toast = document.createElement('div'); toast.className = `fixed top-4 right-4 px-4 py-3 rounded-lg shadow-lg z-50 ${ type === 'buy' ? 'bg-trade-green' : 'bg-trade-red' } text-white`; toast.innerHTML = ` <div class="font-bold">${type === 'buy' ? 'Buy' : 'Sell'} Order Executed</div> <div>${state.tradeQuantity} oz at $${lastPrice.toFixed(2)}</div> `; document.body.appendChild(toast); setTimeout(() => { toast.remove(); }, 3000); } function closePosition(positionId) { const positionIndex = state.positions.findIndex(p => p.id === positionId); if (positionIndex === -1) return; const position = state.positions[positionIndex]; position.closed = true; position.exitPrice = priceData[priceData.length - 1].close; position.exitTime = new Date(); // Calculate P&L const priceDiff = position.exitPrice - position.entryPrice; position.profit = position.type === 'buy' ? priceDiff * position.quantity : -priceDiff * position.quantity; // Move to closed positions state.closedPositions.push(position); state.positions.splice(positionIndex, 1); // Update balance and equity state.balance += position.profit; state.equity = state.balance; updateBalance(); // Remove trade markers document.querySelector(`[data-id="${position.id}"]`)?.remove(); document.querySelector(`[data-id="${position.id}-tp"]`)?.remove(); document.querySelector(`[data-id="${position.id}-sl"]`)?.remove(); updatePositionPanels(); } function addTradeMarker(position) { const marker = document.createElement('div'); marker.className = `trade-marker ${position.type === 'buy' ? 'bg-trade-green' : 'bg-trade-red'}`; marker.dataset.id = position.id; // Position marker at entry price (simplified) const chartArea = priceChart.chartArea; const yScale = priceChart.scales.y; const yPos = yScale.getPixelForValue(position.entryPrice); marker.style.left = `${chartArea.right - 20}px`; marker.style.top = `${yPos - 4}px`; document.getElementById('trade-markers').appendChild(marker); // Add trade lines (TP/SL) addTradeLine(position, 'tp'); addTradeLine(position, 'sl'); } function addTradeLine(position, type) { const line = document.createElement('div'); line.className = `trade-line ${type === 'tp' ? 'bg-trade-green' : 'bg-trade-red'}`; line.dataset.id = `${position.id}-${type}`; const handle = document.createElement('div'); handle.className = `trade-line-handle ${type === 'tp' ? 'bg-trade-green' : 'bg-trade-red'}`; handle.dataset.id = `${position.id}-${type}-handle`; line.appendChild(handle); document.getElementById('trade-markers').appendChild(line); updateTradeLinePosition(position, type); } function updateTradeLinePosition(position, type) { const line = document.querySelector(`[data-id="${position.id}-${type}"]`); const handle = document.querySelector(`[data-id="${position.id}-${type}-handle"]`); if (!line) return; const chartArea = priceChart.chartArea; const yScale = priceChart.scales.y; const price = type === 'tp' ? position.takeProfit : position.stopLoss; const yPos = yScale.getPixelForValue(price); line.style.top = `${yPos}px`; handle.style.left = `${chartArea.right - 6}px`; handle.style.top = `${yPos - 6}px`; } // Update UI functions function updateBalance() { document.getElementById('balance').textContent = state.balance.toFixed(2); document.getElementById('equity').textContent = state.equity.toFixed(2); document.getElementById('margin').textContent = state.margin.toFixed(2); } function updatePositionPanels() { // Open Positions const openPositionsEl = document.getElementById('open-positions'); openPositionsEl.innerHTML = ''; state.positions.forEach(position => { const profit = (position.currentPrice - position.entryPrice) * (position.type === 'buy' ? 1 : -1) * position.quantity; const profitPercent = ((position.currentPrice / position.entryPrice) - 1) * (position.type === 'buy' ? 100 : -100); const positionEl = document.createElement('div'); positionEl.className = `position-card position-${position.type} bg-dark-bg rounded-lg shadow p-4 border-l-4 ${position.type === 'buy' ? 'border-trade-green' : 'border-trade-red'}`; positionEl.innerHTML = ` <div class="flex justify-between items-center mb-2"> <div class="font-semibold">${position.symbol} ${position.type.toUpperCase()}</div> <div class="${profit >= 0 ? 'text-trade-green' : 'text-trade-red'} font-semibold"> ${profit >= 0 ? '+' : ''}${profit.toFixed(2)} (${profitPercent.toFixed(2)}%) </div> </div> <div class="grid grid-cols-2 gap-2 text-sm"> <div class="text-gray-400">Qty:</div> <div>${position.quantity} oz</div> <div class="text-gray-400">Entry:</div> <div>$${position.entryPrice.toFixed(2)}</div> <div class="text-gray-400">Current:</div> <div>$${position.currentPrice.toFixed(2)}</div> <div class="text-gray-400">TP:</div> <div>$${position.takeProfit.toFixed(2)}</div> <div class="text-gray-400">SL:</div> <div>$${position.stopLoss.toFixed(2)}</div> </div> <div class="mt-3 flex justify-end"> <button class="close-btn bg-dark-panel hover:bg-dark-hover px-3 py-1 rounded text-sm" data-id="${position.id}"> Close Position </button> </div> `; openPositionsEl.appendChild(positionEl); }); // Closed Positions const closedPositionsEl = document.getElementById('closed-positions'); closedPositionsEl.innerHTML = ''; state.closedPositions.slice(-5).reverse().forEach(position => { const positionEl = document.createElement('div'); positionEl.className = `position-card bg-dark-bg rounded-lg shadow p-3`; positionEl.innerHTML = ` <div class="flex justify-between items-center mb-1"> <div class="font-semibold">${position.symbol} ${position.type.toUpperCase()}</div> <div class="${position.profit >= 0 ? 'text-trade-green' : 'text-trade-red'} font-semibold"> ${position.profit >= 0 ? '+' : ''}${position.profit.toFixed(2)} </div> </div> <div class="grid grid-cols-2 gap-1 text-xs text-gray-400"> <div>Qty: ${position.quantity} oz</div> <div>Entry: $${position.entryPrice.toFixed(2)}</div> <div>Exit: $${position.exitPrice.toFixed(2)}</div> <div>Duration: ${Math.round((position.exitTime - position.entryTime) / 60000)} min</div> </div> `; closedPositionsEl.appendChild(positionEl); }); // Add event listeners to close buttons document.querySelectorAll('.close-btn').forEach(btn => { btn.addEventListener('click', () => { closePosition(parseInt(btn.dataset.id)); }); }); } // Simulate price updates with realistic gold patterns function simulatePriceUpdate() { const lastCandle = priceData[priceData.length - 1]; let volatility = 1.5; // Adjust volatility based on time (higher during NY/London overlap) const hour = new Date().getHours(); const isActiveHours = (hour >= 8 && hour < 17); // 8am-5pm NY time volatility = isActiveHours ? volatility * 1.5 : volatility; // Calculate current trend (50-period moving average direction) const trendPeriod = 50; let trend = 0; if (priceData.length > trendPeriod) { const ma1 = priceData.slice(-trendPeriod).reduce((sum, d) => sum + d.close, 0) / trendPeriod; const ma2 = priceData.slice(-trendPeriod*2, -trendPeriod).reduce((sum, d) => sum + d.close, 0) / trendPeriod; trend = (ma1 - ma2) / lastCandle.close; } // Apply trend with some randomness let changePercent = trend * volatility * 2 + (Math.random() - 0.5) * volatility * 0.5; // Occasionally add news events (5% chance) if (Math.random() < 0.05) { changePercent += (Math.random() > 0.5 ? 1 : -1) * volatility * 2; } // Mean reversion - pull price back toward 1900-2000 range if (lastCandle.close > 2000) { changePercent -= 0.1 * volatility; } else if (lastCandle.close < 1900) { changePercent += 0.1 * volatility; } const changeAmount = lastCandle.close * changePercent / 100; const newPrice = lastCandle.close + changeAmount; // Update market data const priceChange = newPrice - state.lastPrice; state.lastPrice = newPrice; state.priceChange = priceChange; state.priceChangePercent = (priceChange / state.lastPrice) * 100; state.bid = newPrice - 0.1; state.ask = newPrice + 0.1; state.volume += Math.floor(Math.random() * 100); updateMarketData(); // Highlight price change const priceEl = document.getElementById('last-price'); priceEl.classList.remove('price-change-up', 'price-change-down'); void priceEl.offsetWidth; // Trigger reflow priceEl.classList.add(priceChange >= 0 ? 'price-change-up' : 'price-change-down'); // Simulate intra-candle movement const candleRange = Math.abs(changeAmount) * 3; const open = lastCandle.close; const close = newPrice; const high = Math.max(open, close) + (Math.random() * candleRange * 0.5); const low = Math.min(open, close) - (Math.random() * candleRange * 0.5); const newCandle = { time: new Date(), open: open, high: high, low: low, close: close }; priceData.push(newCandle); priceData.shift(); // Remove oldest data point // Update positions with current price state.positions.forEach(position => { position.currentPrice = newPrice; }); // Update charts priceChart.data.datasets[0].data = priceData.map(d => ({ x: d.time, o: d.open, h: d.high, l: d.low, c: d.close })); // Recalculate indicators indicators = calculateIndicators(priceData); // Update charts priceChart.update(); updatePositionPanels(); // Update trade lines and check for TP/SL state.positions.forEach(position => { updateTradeLinePosition(position, 'tp'); updateTradeLinePosition(position, 'sl'); // Check if price hit TP/SL if ((position.type === 'buy' && newPrice >= position.takeProfit) || (position.type === 'sell' && newPrice <= position.takeProfit)) { closePosition(position.id); } else if ((position.type === 'buy' && newPrice <= position.stopLoss) || (position.type === 'sell' && newPrice >= position.stopLoss)) { closePosition(position.id); } }); // Update last update time const now = new Date(); document.getElementById('last-update').textContent = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`; } // Simulation control let simulationInterval; let orderBookInterval; // Initialize the platform function init() { initCharts(); updateBalance(); updateMarketData(); renderOrderBook(); updatePositionPanels(); // Event listeners document.getElementById('btn-buy').addEventListener('click', () => placeTrade('buy')); document.getElementById('btn-sell').addEventListener('click', () => placeTrade('sell')); document.getElementById('qty-up').addEventListener('click', () => { state.tradeQuantity = Math.min(100, state.tradeQuantity + 1); document.getElementById('trade-qty').value = state.tradeQuantity; }); document.getElementById('qty-down').addEventListener('click', () => { state.tradeQuantity = Math.max(1, state.tradeQuantity - 1); document.getElementById('trade-qty').value = state.tradeQuantity; }); document.getElementById('trade-qty').addEventListener('change', (e) => { state.tradeQuantity = Math.max(1, Math.min(100, parseInt(e.target.value) || 1)); e.target.value = state.tradeQuantity; }); document.getElementById('btn-refresh').addEventListener('click', () => { priceData = generatePriceData(); indicators = calculateIndicators(priceData); initCharts(); }); // Timeframe buttons document.querySelectorAll('[data-timeframe]').forEach(btn => { btn.addEventListener('click', () => { state.timeframe = btn.dataset.timeframe === 'D' ? 1440 : parseInt(btn.dataset.timeframe); priceData = generatePriceData(); indicators = calculateIndicators(priceData); initCharts(); }); }); // Chart type buttons document.querySelectorAll('[data-type]').forEach(btn => { btn.addEventListener('click', () => { state.chartType = btn.dataset.type; initCharts(); }); }); // Indicator selectors document.querySelectorAll('.indicator-selector').forEach(el => { el.addEventListener('click', () => { const indicator = el.dataset.indicator; state.indicators[indicator].enabled = !state.indicators[indicator].enabled; el.classList.toggle('bg-dark-hover'); initCharts(); }); }); // Start/stop simulation function startSimulation() { if (!simulationInterval) { simulationInterval = setInterval(() => { simulatePriceUpdate(); renderOrderBook(); }, 2000); document.getElementById('btn-start').disabled = true; document.getElementById('btn-stop').disabled = false; } } function stopSimulation() { if (simulationInterval) { clearInterval(simulationInterval); simulationInterval = null; document.getElementById('btn-start').disabled = false; document.getElementById('btn-stop').disabled = true; } } // Reset zoom button document.getElementById('btn-reset-zoom').addEventListener('click', () => { if (priceChart) { priceChart.resetZoom(); } if (indicatorChart) { indicatorChart.resetZoom(); } }); // Event listeners for start/stop document.getElementById('btn-start').addEventListener('click', startSimulation); document.getElementById('btn-stop').addEventListener('click', stopSimulation); } // Initialize when DOM is loaded document.addEventListener('DOMContentLoaded', init); </script> <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=alsaif66/simgold" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gold Futures Pro Trading Platform</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-crosshair@1.2.0"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation@2.1.0/dist/chartjs-plugin-annotation.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hammerjs@2.0.8"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
'trade-green': '#10b981',
'trade-red': '#ef4444',
'trade-blue': '#3b82f6',
'trade-yellow': '#eab308',
'trade-purple': '#a855f7',
'dark-bg': '#0f172a',
'dark-panel': '#1e293b',
'dark-border': '#334155',
'dark-text': '#e2e8f0',
'dark-hover': '#334155'
}
}
}
}
</script>
<style>
.candle-up {
background-color: #10b981;
border-color: #10b981;
}
.candle-down {
background-color: #ef4444;
border-color: #ef4444;
}
.position-long {
border-left: 4px solid #10b981;
}
.position-short {
border-left: 4px solid #ef4444;
}
.indicator-line {
border-top-width: 2px;
}
.chart-container {
height: 60vh;
}
@media (max-width: 768px) {
.chart-container {
height: 50vh;
}
}
.position-card {
transition: all 0.2s ease;
}
.position-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.indicator-selector {
transition: all 0.2s ease;
}
.indicator-selector:hover {
background-color: #334155;
}
.trade-line {
position: absolute;
height: 2px;
width: 100%;
cursor: pointer;
z-index: 10;
}
.trade-line-handle {
position: absolute;
width: 12px;
height: 12px;
border-radius: 50%;
cursor: move;
z-index: 11;
}
.trade-marker {
position: absolute;
width: 8px;
height: 8px;
border-radius: 50%;
z-index: 9;
}
.glow {
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}
.price-change-up {
animation: priceUp 1s ease;