public static bool SetCurrentAccount(DateTime time, double balance, double equity, double profit, double freeMargin) { bool balanceChanged = false; bool equityChanged = false; balanceDataChganged = false; if (Math.Abs(accountBalance - balance) > 0.01) { balanceChanged = true; } if (Math.Abs(accountEquity - equity) > 0.01) { equityChanged = true; } accountBalance = balance; accountEquity = equity; accountProfit = profit; accountFreeMargin = freeMargin; if (balance > 0.01 && (equityChanged || balanceChanged)) { Balance_Chart_Unit chartUnit = new Balance_Chart_Unit(); chartUnit.Time = time; chartUnit.Balance = balance; chartUnit.Equity = equity; if (balanceDataPoints == 0) { balanceData[balanceDataPoints] = chartUnit; balanceDataPoints++; } if (balanceDataPoints == BALANCE_LENGHT) { for (int i = 0; i < BALANCE_LENGHT - 1; i++) { balanceData[i] = balanceData[i + 1]; } balanceDataPoints = BALANCE_LENGHT - 1; } if (balanceDataPoints < BALANCE_LENGHT) { balanceData[balanceDataPoints] = chartUnit; balanceDataPoints++; } balanceDataChganged = true; } return(balanceChanged); }
/// <summary> /// Updates the chart. /// </summary> protected void UpdateBalanceChart(Balance_Chart_Unit[] balanceData, int balancePoints) { if (balanceChart.InvokeRequired) { balanceChart.BeginInvoke(new UpdateBalanceChartDelegate(UpdateBalanceChart), new object[] { balanceData, balancePoints }); } else { balanceChart.UpdateChartData(balanceData, balancePoints); balanceChart.RefreshChart(); } return; }
public static bool SetCurrentAccount(DateTime time, double balance, double equity, double profit, double freeMargin) { bool balanceChanged = false; bool equityChanged = false; balanceDataChganged = false; if (Math.Abs(accountBalance - balance) > 0.01) balanceChanged = true; if (Math.Abs(accountEquity - equity) > 0.01) equityChanged = true; accountBalance = balance; accountEquity = equity; accountProfit = profit; accountFreeMargin = freeMargin; if (balance > 0.01 && (equityChanged || balanceChanged)) { Balance_Chart_Unit chartUnit = new Balance_Chart_Unit(); chartUnit.Time = time; chartUnit.Balance = balance; chartUnit.Equity = equity; if (balanceDataPoints == 0) { balanceData[balanceDataPoints] = chartUnit; balanceDataPoints++; } if (balanceDataPoints == BALANCE_LENGHT) { for (int i = 0; i < BALANCE_LENGHT - 1; i++) balanceData[i] = balanceData[i + 1]; balanceDataPoints = BALANCE_LENGHT - 1; } if (balanceDataPoints < BALANCE_LENGHT) { balanceData[balanceDataPoints] = chartUnit; balanceDataPoints++; } balanceDataChganged = true; } return balanceChanged; }
/// <summary> /// Sets data to be displayed. /// </summary> public void UpdateChartData(Balance_Chart_Unit[] data, int points) { if (data == null || points < 1) return; balanceData = new double[points]; equityData = new double[points];; for (int p = 0; p < points; p++) { balanceData[p] = data[p].Balance; equityData[p] = data[p].Equity; } maxBalance = int.MinValue; minBalance = int.MaxValue; maxEquity = int.MinValue; minEquity = int.MaxValue; foreach (double balance in balanceData) { if (balance > maxBalance) maxBalance = (int)balance; if (balance < minBalance) minBalance = (int)balance; } foreach (double equity in equityData) { if (equity > maxEquity) maxEquity = (int)equity; if (equity < minEquity) minEquity = (int)equity; } startTime = data[0].Time; InitChart(); return; }