fbpx




حاسبة التداول


حاسبة عدد الصفقات لتحقيق الهدف









#الرصيد الحاليقيمة الصفقة (##%)الربح / الخسارةالرصيد الجديد

function calculateTrades() { // قراءة القيم من المستخدم let target = parseFloat(document.getElementById("target").value); let balance = parseFloat(document.getElementById("balance").value); let investmentPercentInput = parseFloat(document.getElementById("investmentPercent").value); let investmentPercent = investmentPercentInput / 100; let profitPercent = parseFloat(document.getElementById("profitPercent").value) / 100; let lossPercent = parseFloat(document.getElementById("lossPercent").value) / 100; let winRate = parseFloat(document.getElementById("winRate").value);

// عرض الجدول والمخطط document.getElementById("tradesTable").style.display = "table"; document.getElementById("chartContainer").style.display = "block";

// مسح الجدول والمخطط القديم const tableBody = document.getElementById("tableBody"); tableBody.innerHTML = ""; balanceHistory = [balance];

// التحقق من صحة البيانات if (target <= balance || isNaN(target)) { document.getElementById("result").innerText = "يرجى إدخال هدف مالي أكبر من الرصيد الحالي."; return; } if (balance <= 0 || isNaN(balance)) { document.getElementById("result").innerText = "يرجى إدخال مبلغ أولي صحيح."; return; } if (investmentPercent <= 0 || investmentPercent > 1) { document.getElementById("result").innerText = "النسبة المتداولة يجب أن تكون بين 1 و 100."; return; } if (profitPercent <= 0) { document.getElementById("result").innerText = "نسبة الربح يجب أن تكون أكبر من 0."; return; } if (lossPercent < 0 || lossPercent > 100) { document.getElementById("result").innerText = "نسبة الخسارة يجب أن تكون بين 0 و 100."; return; } if (winRate < 0 || winRate > 100 || isNaN(winRate)) { document.getElementById("result").innerText = "نسبة النجاح يجب أن تكون بين 0 و 100."; return; }

let totalTrades = 0; let successfulTrades = 0; let failedTrades = 0;

let currentBalance = balance;

while (currentBalance > 0 && currentBalance < target && totalTrades < 1000) { let investment = currentBalance * investmentPercent; let isWin = Math.random() * 100 < winRate;let profitOrLoss; let newBalance;if (isWin) { profitOrLoss = investment * profitPercent; newBalance = currentBalance + profitOrLoss; successfulTrades++; } else { profitOrLoss = -investment * lossPercent; newBalance = currentBalance + profitOrLoss; failedTrades++; }// تحديث التاريخ balanceHistory.push(newBalance.toFixed(2));// إضافة صفقة إلى الجدول const row = document.createElement("tr");row.innerHTML = `

${totalTrades + 1}${currentBalance.toFixed(2)}${investment.toFixed(2)} (${investmentPercentInput}%)${profitOrLoss.toFixed(2)}${newBalance.toFixed(2)}

`;

tableBody.appendChild(row);

currentBalance = newBalance; totalTrades++; }

document.getElementById("result").innerText = "تحتاج إلى حوالي " + totalTrades + " صفقة للوصول إلى الهدف.\n" + "عدد الصفقات الرابحة: " + successfulTrades + "\n" + "عدد الصفقات الخاسرة: " + failedTrades;

drawChart(); }

function drawChart() { const ctx = document.getElementById('balanceChart').getContext('2d');

if (window.myChart) window.myChart.destroy(); // إذا كان هناك رسم سابق

window.myChart = new Chart(ctx, { type: 'line', { labels: [...Array(balanceHistory.length).keys()], datasets: [{ label: 'الرصيد عبر الصفقات', balanceHistory, borderColor: 'rgba(0, 123, 255, 1)', backgroundColor: 'rgba(0, 123, 255, 0.2)', fill: true, tension: 0.3 }] }, options: { responsive: true, scales: { x: { title: { display: true, text: 'رقم الصفقة' } }, y: { title: { display: true, text: 'الرصيد' } } } } }); }

function exportTableToCSV() { let csv = "رقم الصفقة,الرصيد الحالي,قيمة الصفقة,الربح/الخسارة,الرصيد الجديد\n"; const rows = document.querySelectorAll("table tr");

for (let i = 1; i < rows.length; i++) { let row = [], cols = rows[i].querySelectorAll("td"); for (let j = 0; j < cols.length; j++) row.push(cols[j].innerText); csv += row.join(",") + "\n"; }let blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); let link = document.createElement("a"); let url = URL.createObjectURL(blob); link.setAttribute("href", url); link.setAttribute("download", "سجل_الصفقات.csv"); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); }


حاسبة التداول

حاسبة عدد الصفقات لتحقيق الهدف













#الرصيد الحاليقيمة الصفقة (##%)الربح / الخسارةالرصيد الجديد