public static LongMoneyBalance ( int bar ) : double | ||
bar | int | |
Результат | double |
/// <summary> /// Sets the chart parameters /// </summary> private void InitChart(int width, int height) { Chart = new Bitmap(width, height); if (!Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar) { return; } const int border = 1; const int space = 2; int maximum; int minimum; int firstBar = Data.FirstBar; int bars = Data.Bars; int chartBars = Data.Bars - firstBar; int maxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance; int minBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance; int maxEquity = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity : Backtester.MaxEquity; int minEquity = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity : Backtester.MinEquity; if (Configs.AdditionalStatistics) { int maxLongBalance = Configs.AccountInMoney ? (int)Backtester.MaxLongMoneyBalance : Backtester.MaxLongBalance; int minLongBalance = Configs.AccountInMoney ? (int)Backtester.MinLongMoneyBalance : Backtester.MinLongBalance; int maxShortBalance = Configs.AccountInMoney ? (int)Backtester.MaxShortMoneyBalance : Backtester.MaxShortBalance; int minShortBalance = Configs.AccountInMoney ? (int)Backtester.MinShortMoneyBalance : Backtester.MinShortBalance; int maxLSBalance = Math.Max(maxLongBalance, maxShortBalance); int minLSBalance = Math.Min(minLongBalance, minShortBalance); maximum = Math.Max(Math.Max(maxBalance, maxEquity), maxLSBalance) + 1; minimum = Math.Min(Math.Min(minBalance, minEquity), minLSBalance) - 1; } else { maximum = Math.Max(maxBalance, maxEquity) + 1; minimum = Math.Min(minBalance, minEquity) - 1; } const int yTop = border + space; int yBottom = height - border - space; const int xLeft = border; int xRight = width - border - space; float xScale = (xRight - xLeft) / (float)chartBars; float yScale = (yBottom - yTop) / (float)(maximum - minimum); var penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border); var balancePoints = new PointF[chartBars]; var equityPoints = new PointF[chartBars]; var longBalancePoints = new PointF[chartBars]; var shortBalancePoints = new PointF[chartBars]; int index = 0; for (int bar = firstBar; bar < bars; bar++) { balancePoints[index].X = xLeft + index * xScale; equityPoints[index].X = xLeft + index * xScale; if (Configs.AccountInMoney) { balancePoints[index].Y = (float)(yBottom - (Backtester.MoneyBalance(bar) - minimum) * yScale); equityPoints[index].Y = (float)(yBottom - (Backtester.MoneyEquity(bar) - minimum) * yScale); } else { balancePoints[index].Y = yBottom - (Backtester.Balance(bar) - minimum) * yScale; equityPoints[index].Y = yBottom - (Backtester.Equity(bar) - minimum) * yScale; } if (Configs.AdditionalStatistics) { longBalancePoints[index].X = xLeft + index * xScale; shortBalancePoints[index].X = xLeft + index * xScale; if (Configs.AccountInMoney) { longBalancePoints[index].Y = (float)(yBottom - (Backtester.LongMoneyBalance(bar) - minimum) * yScale); shortBalancePoints[index].Y = (float)(yBottom - (Backtester.ShortMoneyBalance(bar) - minimum) * yScale); } else { longBalancePoints[index].Y = yBottom - (Backtester.LongBalance(bar) - minimum) * yScale; shortBalancePoints[index].Y = yBottom - (Backtester.ShortBalance(bar) - minimum) * yScale; } } index++; } Graphics g = Graphics.FromImage(Chart); // Paints the background by gradient var rectField = new RectangleF(1, 1, width - 2, height - 2); g.FillRectangle(new SolidBrush(LayoutColors.ColorChartBack), rectField); // Border g.DrawRectangle(penBorder, 0, 0, width - 1, height - 1); // Equity line g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), equityPoints); // Draw Long and Short balance if (Configs.AdditionalStatistics) { g.DrawLines(new Pen(Color.Red), shortBalancePoints); g.DrawLines(new Pen(Color.Green), longBalancePoints); } // Draw the balance line g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), balancePoints); }
/// <summary> /// Sets the chart params /// </summary> void InitChart(int width, int height) { chart = new Bitmap(width, height); if (!Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar) { return; } int border = 1; int space = 2; int XLeft, XRight, YTop, YBottom; float XScale, YScale; int bars; int chartBars; int maximum; int minimum; int firstBar; Pen penBorder; PointF[] apntBalance; PointF[] apntEquity; PointF[] apntLongBalance; PointF[] apntShortBalance; firstBar = Data.FirstBar; bars = Data.Bars; chartBars = Data.Bars - firstBar; int iMaxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance; int iMinBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance; int iMaxEquity = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity : Backtester.MaxEquity; int iMinEquity = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity : Backtester.MinEquity; if (Configs.AdditionalStatistics) { int iMaxLongBalance = Configs.AccountInMoney ? (int)Backtester.MaxLongMoneyBalance : Backtester.MaxLongBalance; int iMinLongBalance = Configs.AccountInMoney ? (int)Backtester.MinLongMoneyBalance : Backtester.MinLongBalance; int iMaxShortBalance = Configs.AccountInMoney ? (int)Backtester.MaxShortMoneyBalance : Backtester.MaxShortBalance; int iMinShortBalance = Configs.AccountInMoney ? (int)Backtester.MinShortMoneyBalance : Backtester.MinShortBalance; int iMaxLSBalance = Math.Max(iMaxLongBalance, iMaxShortBalance); int iMinLSBalance = Math.Min(iMinLongBalance, iMinShortBalance); maximum = Math.Max(Math.Max(iMaxBalance, iMaxEquity), iMaxLSBalance) + 1; minimum = Math.Min(Math.Min(iMinBalance, iMinEquity), iMinLSBalance) - 1; } else { maximum = Math.Max(iMaxBalance, iMaxEquity) + 1; minimum = Math.Min(iMinBalance, iMinEquity) - 1; } YTop = border + space; YBottom = height - border - space; XLeft = border; XRight = width - border - space; XScale = (XRight - XLeft) / (float)chartBars; YScale = (YBottom - YTop) / (float)(maximum - minimum); penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border); apntBalance = new PointF[chartBars]; apntEquity = new PointF[chartBars]; apntLongBalance = new PointF[chartBars]; apntShortBalance = new PointF[chartBars]; int index = 0; for (int iBar = firstBar; iBar < bars; iBar++) { apntBalance[index].X = XLeft + index * XScale; apntEquity[index].X = XLeft + index * XScale; if (Configs.AccountInMoney) { apntBalance[index].Y = (float)(YBottom - (Backtester.MoneyBalance(iBar) - minimum) * YScale); apntEquity[index].Y = (float)(YBottom - (Backtester.MoneyEquity(iBar) - minimum) * YScale); } else { apntBalance[index].Y = YBottom - (Backtester.Balance(iBar) - minimum) * YScale; apntEquity[index].Y = YBottom - (Backtester.Equity(iBar) - minimum) * YScale; } if (Configs.AdditionalStatistics) { apntLongBalance[index].X = XLeft + index * XScale; apntShortBalance[index].X = XLeft + index * XScale; if (Configs.AccountInMoney) { apntLongBalance[index].Y = (float)(YBottom - (Backtester.LongMoneyBalance(iBar) - minimum) * YScale); apntShortBalance[index].Y = (float)(YBottom - (Backtester.ShortMoneyBalance(iBar) - minimum) * YScale); } else { apntLongBalance[index].Y = YBottom - (Backtester.LongBalance(iBar) - minimum) * YScale; apntShortBalance[index].Y = YBottom - (Backtester.ShortBalance(iBar) - minimum) * YScale; } } index++; } Graphics g = Graphics.FromImage(chart); // Paints the background by gradient RectangleF rectField = new RectangleF(1, 1, width - 2, height - 2); g.FillRectangle(new SolidBrush(LayoutColors.ColorChartBack), rectField); // Border g.DrawRectangle(penBorder, 0, 0, width - 1, height - 1); // Equity line g.DrawLines(new Pen(LayoutColors.ColorChartEquityLine), apntEquity); // Draw Long and Short balance if (Configs.AdditionalStatistics) { g.DrawLines(new Pen(Color.Red), apntShortBalance); g.DrawLines(new Pen(Color.Green), apntLongBalance); } // Draw the balance line g.DrawLines(new Pen(LayoutColors.ColorChartBalanceLine), apntBalance); }
/// <summary> /// Sets chart's back testing data. /// </summary> public void SetChartData() { _isNotPaint = !Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar; if (_isNotPaint) { return; } _showPriceLine = Configs.ShowPriceChartOnAccountChart && Backtester.ExecutedOrders > 0; _isScanPerformed = Backtester.IsScanPerformed; _data.FirstBar = Data.FirstBar; _data.Bars = Data.Bars; _chartBars = Data.Bars - Data.FirstBar; int maxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance; int minBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance; int maxEquity = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity : Backtester.MaxEquity; int minEquity = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity : Backtester.MinEquity; if (Configs.AdditionalStatistics) { int maxLongBalance = Configs.AccountInMoney ? (int)Backtester.MaxLongMoneyBalance : Backtester.MaxLongBalance; int minLongBalance = Configs.AccountInMoney ? (int)Backtester.MinLongMoneyBalance : Backtester.MinLongBalance; int maxShortBalance = Configs.AccountInMoney ? (int)Backtester.MaxShortMoneyBalance : Backtester.MaxShortBalance; int minShortBalance = Configs.AccountInMoney ? (int)Backtester.MinShortMoneyBalance : Backtester.MinShortBalance; int maxLongShortBalance = Math.Max(maxLongBalance, maxShortBalance); int minLongShortBalance = Math.Min(minLongBalance, minShortBalance); _data.Maximum = Math.Max(Math.Max(maxBalance, maxEquity), maxLongShortBalance) + 1; _data.Minimum = Math.Min(Math.Min(minBalance, minEquity), minLongShortBalance) - 1; } else { _data.Maximum = Math.Max(maxBalance, maxEquity) + 1; _data.Minimum = Math.Min(minBalance, minEquity) - 1; } _data.Minimum = (int)(Math.Floor(_data.Minimum / 10f) * 10); _data.DataMaxPrice = Data.MaxPrice; _data.DataMinPrice = Data.MinPrice; if (_showPriceLine) { _data.ClosePrice = new double[_data.Bars]; Data.Close.CopyTo(_data.ClosePrice, 0); } if (Configs.AccountInMoney) { _data.MoneyBalance = new double[_data.Bars]; _data.MoneyEquity = new double[_data.Bars]; } else { _data.Balance = new int[_data.Bars]; _data.Equity = new int[_data.Bars]; } if (Configs.AdditionalStatistics) { if (Configs.AccountInMoney) { _data.LongMoneyBalance = new double[_data.Bars]; _data.ShortMoneyBalance = new double[_data.Bars]; } else { _data.LongBalance = new int[_data.Bars]; _data.ShortBalance = new int[_data.Bars]; } } for (int bar = _data.FirstBar; bar < _data.Bars; bar++) { if (Configs.AccountInMoney) { _data.MoneyBalance[bar] = Backtester.MoneyBalance(bar); _data.MoneyEquity[bar] = Backtester.MoneyEquity(bar); } else { _data.Balance[bar] = Backtester.Balance(bar); _data.Equity[bar] = Backtester.Equity(bar); } if (Configs.AdditionalStatistics) { if (Configs.AccountInMoney) { _data.LongMoneyBalance[bar] = Backtester.LongMoneyBalance(bar); _data.ShortMoneyBalance[bar] = Backtester.ShortMoneyBalance(bar); } else { _data.LongBalance[bar] = Backtester.LongBalance(bar); _data.ShortBalance[bar] = Backtester.ShortBalance(bar); } } } _data.MarginCallBar = Backtester.MarginCallBar; if (IsOOS && OOSBar > _data.FirstBar) { _data.NetBalance = (float)(Configs.AccountInMoney ? Backtester.MoneyBalance(OOSBar) : Backtester.Balance(OOSBar)); _data.DataTimeBarOOS = Data.Time[OOSBar]; } else { _data.NetBalance = (float)(Configs.AccountInMoney ? Backtester.NetMoneyBalance : Backtester.NetBalance); } }
/// <summary> /// Generates dynamic info on the status bar /// when we are Moving the mouse over the SmallBalanceChart. /// </summary> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (!isShowDynamicInfo || !Data.IsData || !Data.IsResult) { return; } int bar = (int)((e.X - XLeft) / XScale) + firstBar; bar = Math.Max(firstBar, bar); bar = Math.Min(Data.Bars - 1, bar); if (Configs.AccountInMoney) { strStatusBarText = String.Format("{0} {1} {2}: {3} {4} {5}: {6} {7}", Data.Time[bar].ToString(Data.DF), Data.Time[bar].ToString("HH:mm"), Language.T("Balance"), Backtester.MoneyBalance(bar).ToString("F2"), Configs.AccountCurrency, Language.T("Equity"), Backtester.MoneyEquity(bar).ToString("F2"), Configs.AccountCurrency); } else { strStatusBarText = String.Format("{0} {1} {2}: {3} {4} {5}: {6} {7}", Data.Time[bar].ToString(Data.DF), Data.Time[bar].ToString("HH:mm"), Language.T("Balance"), Backtester.Balance(bar), Language.T("pips"), Language.T("Equity"), Backtester.Equity(bar), Language.T("pips")); } if (Configs.AdditionalStatistics) { if (Configs.AccountInMoney) { strStatusBarText += String.Format(" {0}: {1} {2} {3}: {4} {5}", Language.T("Long balance"), Backtester.LongMoneyBalance(bar).ToString("F2"), Configs.AccountCurrency, Language.T("Short balance"), Backtester.ShortMoneyBalance(bar).ToString("F2"), Configs.AccountCurrency); } else { strStatusBarText += String.Format(" {0}: {1} {2} {3}: {4} {5}", Language.T("Long balance"), Backtester.LongBalance(bar), Language.T("pips"), Language.T("Short balance"), Backtester.ShortBalance(bar), Language.T("pips")); } } if (Configs.ShowPriceChartOnAccountChart) { strStatusBarText += String.Format(" {0}: {1}", Language.T("Price close"), Data.Close[bar]); } }
/// <summary> /// Sets chart's instrument and back testing data. /// </summary> public void SetChartData() { isNotPaint = !Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar; if (isNotPaint) { return; } showPriceLine = Configs.ShowPriceChartOnAccountChart && Backtester.ExecutedOrders > 0; isScanPerformed = Backtester.IsScanPerformed; firstBar = Data.FirstBar; bars = Data.Bars; chartBars = Data.Bars - firstBar; int maxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance; int minBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance; int maxEquity = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity : Backtester.MaxEquity; int minEquity = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity : Backtester.MinEquity; if (Configs.AdditionalStatistics) { int maxLongBalance = Configs.AccountInMoney ? (int)Backtester.MaxLongMoneyBalance : Backtester.MaxLongBalance; int minLongBalance = Configs.AccountInMoney ? (int)Backtester.MinLongMoneyBalance : Backtester.MinLongBalance; int maxShortBalance = Configs.AccountInMoney ? (int)Backtester.MaxShortMoneyBalance : Backtester.MaxShortBalance; int minShortBalance = Configs.AccountInMoney ? (int)Backtester.MinShortMoneyBalance : Backtester.MinShortBalance; int maxLSBalance = Math.Max(maxLongBalance, maxShortBalance); int minLSBalance = Math.Min(minLongBalance, minShortBalance); maximum = Math.Max(Math.Max(maxBalance, maxEquity), maxLSBalance) + 1; minimum = Math.Min(Math.Min(minBalance, minEquity), minLSBalance) - 1; } else { maximum = Math.Max(maxBalance, maxEquity) + 1; minimum = Math.Min(minBalance, minEquity) - 1; } minimum = (int)(Math.Floor(minimum / 10f) * 10); dataMaxPrice = Data.MaxPrice; dataMinPrice = Data.MinPrice; if (showPriceLine) { dataClose = new double[bars]; Data.Close.CopyTo(dataClose, 0); } if (Configs.AccountInMoney) { backtesterMoneyBalance = new double[bars]; backtesterMoneyEquity = new double[bars]; } else { backtesterBalance = new int[bars]; backtesterEquity = new int[bars]; } if (Configs.AdditionalStatistics) { if (Configs.AccountInMoney) { backtesterLongMoneyBalance = new double[bars]; backtesterShortMoneyBalance = new double[bars]; } else { backtesterLongBalance = new int[bars]; backtesterShortBalance = new int[bars]; } } for (int bar = firstBar; bar < bars; bar++) { if (Configs.AccountInMoney) { backtesterMoneyBalance[bar] = Backtester.MoneyBalance(bar); backtesterMoneyEquity[bar] = Backtester.MoneyEquity(bar); } else { backtesterBalance[bar] = Backtester.Balance(bar); backtesterEquity[bar] = Backtester.Equity(bar); } if (Configs.AdditionalStatistics) { if (Configs.AccountInMoney) { backtesterLongMoneyBalance[bar] = Backtester.LongMoneyBalance(bar); backtesterShortMoneyBalance[bar] = Backtester.ShortMoneyBalance(bar); } else { backtesterLongBalance[bar] = Backtester.LongBalance(bar); backtesterShortBalance[bar] = Backtester.ShortBalance(bar); } } } marginCallBar = Backtester.MarginCallBar; if (isOOS && barOOS > firstBar) { balance = (float)(Configs.AccountInMoney ? Backtester.MoneyBalance(barOOS) : Backtester.Balance(barOOS)); dataTimeBarOOS = Data.Time[barOOS]; } else { balance = (float)(Configs.AccountInMoney ? Backtester.NetMoneyBalance : Backtester.NetBalance); } return; }
/// <summary> /// Sets the chart params /// </summary> public void InitChart() { if (!Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar) { return; } firstBar = Data.FirstBar; bars = Data.Bars; chartBars = Data.Bars - firstBar; int iMaxBalance = Configs.AccountInMoney ? (int)Backtester.MaxMoneyBalance : Backtester.MaxBalance; int iMinBalance = Configs.AccountInMoney ? (int)Backtester.MinMoneyBalance : Backtester.MinBalance; int iMaxEquity = Configs.AccountInMoney ? (int)Backtester.MaxMoneyEquity : Backtester.MaxEquity; int iMinEquity = Configs.AccountInMoney ? (int)Backtester.MinMoneyEquity : Backtester.MinEquity; if (Configs.AdditionalStatistics) { int iMaxLongBalance = Configs.AccountInMoney ? (int)Backtester.MaxLongMoneyBalance : Backtester.MaxLongBalance; int iMinLongBalance = Configs.AccountInMoney ? (int)Backtester.MinLongMoneyBalance : Backtester.MinLongBalance; int iMaxShortBalance = Configs.AccountInMoney ? (int)Backtester.MaxShortMoneyBalance : Backtester.MaxShortBalance; int iMinShortBalance = Configs.AccountInMoney ? (int)Backtester.MinShortMoneyBalance : Backtester.MinShortBalance; int iMaxLSBalance = Math.Max(iMaxLongBalance, iMaxShortBalance); int iMinLSBalance = Math.Min(iMinLongBalance, iMinShortBalance); maximum = Math.Max(Math.Max(iMaxBalance, iMaxEquity), iMaxLSBalance) + 1; minimum = Math.Min(Math.Min(iMinBalance, iMinEquity), iMinLSBalance) - 1; } else { maximum = Math.Max(iMaxBalance, iMaxEquity) + 1; minimum = Math.Min(iMinBalance, iMinEquity) - 1; } YTop = border + space; YBottom = ClientSize.Height - border - space; XLeft = border; XRight = ClientSize.Width - border - space; XScale = (XRight - XLeft) / (float)chartBars; YScale = (YBottom - YTop) / (float)(maximum - minimum); penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border); apntBalance = new PointF[chartBars]; apntEquity = new PointF[chartBars]; if (Configs.AdditionalStatistics) { apntLongBalance = new PointF[chartBars]; apntShortBalance = new PointF[chartBars]; } int index = 0; for (int iBar = firstBar; iBar < bars; iBar++) { apntBalance[index].X = XLeft + index * XScale; apntEquity[index].X = XLeft + index * XScale; if (Configs.AccountInMoney) { apntBalance[index].Y = (float)(YBottom - (Backtester.MoneyBalance(iBar) - minimum) * YScale); apntEquity[index].Y = (float)(YBottom - (Backtester.MoneyEquity(iBar) - minimum) * YScale); } else { apntBalance[index].Y = YBottom - (Backtester.Balance(iBar) - minimum) * YScale; apntEquity[index].Y = YBottom - (Backtester.Equity(iBar) - minimum) * YScale; } if (Configs.AdditionalStatistics) { apntLongBalance[index].X = XLeft + index * XScale; apntShortBalance[index].X = XLeft + index * XScale; if (Configs.AccountInMoney) { apntLongBalance[index].Y = (float)(YBottom - (Backtester.LongMoneyBalance(iBar) - minimum) * YScale); apntShortBalance[index].Y = (float)(YBottom - (Backtester.ShortMoneyBalance(iBar) - minimum) * YScale); } else { apntLongBalance[index].Y = YBottom - (Backtester.LongBalance(iBar) - minimum) * YScale; apntShortBalance[index].Y = YBottom - (Backtester.ShortBalance(iBar) - minimum) * YScale; } } index++; } }