/// <summary>
        ///     Updates the journal data from the backtester
        /// </summary>
        private void UpdateJournalData()
        {
            if (!Data.IsResult)
            {
                return;
            }

            journalData   = new string[positions, columns];
            positionIcons = new Image[shownPos];

            for (int pos = firstPos; pos < firstPos + shownPos; pos++)
            {
                int row = pos - firstPos;

                journalData[row, 0] = (StatsBuffer.PosNumb(SelectedBar, pos) + 1).ToString(CultureInfo.InvariantCulture);
                journalData[row, 1] = Language.T(StatsBuffer.PosTransaction(SelectedBar, pos).ToString());
                journalData[row, 2] = Language.T(StatsBuffer.PosDir(SelectedBar, pos).ToString());
                journalData[row, 3] = Configs.AccountInMoney
                                          ? (StatsBuffer.PosDir(SelectedBar, pos) == PosDirection.Short ? "-" : "") +
                                      (StatsBuffer.PosLots(SelectedBar, pos) * Data.InstrProperties.LotSize)
                                          : StatsBuffer.PosLots(SelectedBar, pos).ToString(CultureInfo.InvariantCulture);
                journalData[row, 4] =
                    (StatsBuffer.PosOrdNumb(SelectedBar, pos) + 1).ToString(CultureInfo.InvariantCulture);
                journalData[row, 5] = StatsBuffer.PosOrdPrice(SelectedBar, pos).ToString(Data.Ff);
                journalData[row, 6] = StatsBuffer.PosPrice(SelectedBar, pos).ToString(Data.Ff);

                // Profit Loss
                if (StatsBuffer.PosTransaction(SelectedBar, pos) == Transaction.Close ||
                    StatsBuffer.PosTransaction(SelectedBar, pos) == Transaction.Reduce ||
                    StatsBuffer.PosTransaction(SelectedBar, pos) == Transaction.Reverse)
                {
                    journalData[row, 7] = Configs.AccountInMoney
                                              ? StatsBuffer.PosMoneyProfitLoss(SelectedBar, pos).ToString("F2")
                                              : Math.Round(StatsBuffer.PosProfitLoss(SelectedBar, pos))
                                          .ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    journalData[row, 7] = "-";
                }

                // Floating Profit Loss
                if (pos == positions - 1 && StatsBuffer.PosTransaction(SelectedBar, pos) != Transaction.Close)
                {
                    // Last bar position only
                    journalData[row, 8] = Configs.AccountInMoney
                                              ? StatsBuffer.PosMoneyFloatingPL(SelectedBar, pos).ToString("F2")
                                              : Math.Round(StatsBuffer.PosFloatingPL(SelectedBar, pos))
                                          .ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    journalData[row, 8] = "-";
                }

                // Icons
                positionIcons[row] = Position.PositionIconImage(StatsBuffer.PosIcon(SelectedBar, pos));
            }
        }
        /// <summary>
        ///     Updates the journal data from StatsBuffer
        /// </summary>
        public void UpdateJournalData()
        {
            journalData   = new string[shownBars, columns];
            positionIcons = new Image[shownBars];

            for (int bar = firstBar; bar < firstBar + shownBars; bar++)
            {
                int  row     = bar - firstBar;
                int  col     = 0;
                bool isPos   = StatsBuffer.IsPos(bar);
                bool inMoney = Configs.AccountInMoney;

                journalData[row, col++] = (bar + 1).ToString(CultureInfo.InvariantCulture);
                journalData[row, col++] = Data.Time[bar].ToString(Data.Df);
                journalData[row, col++] = Data.Time[bar].ToString("HH:mm");
                journalData[row, col++] = Data.Open[bar].ToString(Data.Ff);
                journalData[row, col++] = Data.High[bar].ToString(Data.Ff);
                journalData[row, col++] = Data.Low[bar].ToString(Data.Ff);
                journalData[row, col++] = Data.Close[bar].ToString(Data.Ff);
                journalData[row, col++] = Data.Volume[bar].ToString(CultureInfo.InvariantCulture);
                journalData[row, col++] = isPos ? Language.T(StatsBuffer.SummaryTrans(bar).ToString()) : "";
                journalData[row, col++] = isPos ? Language.T(StatsBuffer.SummaryDir(bar).ToString()) : "";
                journalData[row, col++] = isPos ? GetPositionAmmountString(bar) : "";
                journalData[row, col++] = isPos ? StatsBuffer.SummaryPrice(bar).ToString(Data.Ff) : "";
                journalData[row, col++] = isPos ? GetPositionProfitString(bar) : "";
                journalData[row, col++] = isPos ? GetPositionFloatingPLString(bar) : "";
                journalData[row, col++] = inMoney
                                              ? StatsBuffer.MoneyBalance(bar).ToString("F2")
                                              : StatsBuffer.Balance(bar).ToString(CultureInfo.InvariantCulture);
                journalData[row, col++] = inMoney
                                              ? StatsBuffer.MoneyEquity(bar).ToString("F2")
                                              : StatsBuffer.Equity(bar).ToString(CultureInfo.InvariantCulture);
                journalData[row, col++] = StatsBuffer.SummaryRequiredMargin(bar).ToString("F2");
                journalData[row, col++] = StatsBuffer.SummaryFreeMargin(bar).ToString("F2");
                journalData[row, col]   = Language.T(StatsBuffer.BackTestEvalToString(bar));

                positionIcons[row] = isPos
                                         ? Position.PositionIconImage(StatsBuffer.SummaryPositionIcon(bar))
                                         : Resources.pos_square;
            }
        }
예제 #3
0
        /// <summary>
        ///     Updates the journal data from the StatsBuffer.
        /// </summary>
        private void UpdateJournalData()
        {
            journalData = new string[shownPos, columns];
            posIcons    = new Image[shownPos];

            for (int posIndex = firstPos; posIndex < firstPos + shownPos; posIndex++)
            {
                int posNumber = posIndex;

                if (!ShowTransfers)
                {
                    posNumber = posNumbers[posIndex];
                }

                int      row      = posIndex - firstPos;
                int      bar      = StatsBuffer.PosCoordinates[posNumber].Bar;
                Position position = StatsBuffer.PosFromNumb(posNumber);

                string posAmount = Configs.AccountInMoney
                                       ? (position.PosDir == PosDirection.Short ? "-" : "") +
                                   (position.PosLots * Data.InstrProperties.LotSize).ToString(
                    CultureInfo.InvariantCulture)
                                       : position.PosLots.ToString(CultureInfo.InvariantCulture);

                string profitLoss = Configs.AccountInMoney
                                        ? position.MoneyProfitLoss.ToString("F2")
                                        : position.ProfitLoss.ToString("F2");

                string floatingPL = Configs.AccountInMoney
                                        ? position.MoneyFloatingPL.ToString("F2")
                                        : position.FloatingPL.ToString("F2");

                int p = 0;
                journalData[row, p++] = (posNumber + 1).ToString(CultureInfo.InvariantCulture);
                journalData[row, p++] = (bar + 1).ToString(CultureInfo.InvariantCulture);
                journalData[row, p++] = Data.Time[bar].ToString(Data.Df) + Data.Time[bar].ToString(" HH:mm");
                journalData[row, p++] = Language.T(position.Transaction.ToString());
                journalData[row, p++] = Language.T(position.PosDir.ToString());
                journalData[row, p++] = posAmount;
                journalData[row, p++] = position.FormOrdPrice.ToString(Data.Ff);
                journalData[row, p++] = position.PosPrice.ToString(Data.Ff);
                journalData[row, p++] = position.RequiredMargin.ToString("F2");

                // Charges
                if (Configs.AccountInMoney)
                {
                    // in currency
                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reverse)
                    {
                        journalData[row, p++] = position.MoneySpread.ToString("F2");
                    }
                    else
                    {
                        journalData[row, p++] = "-";
                    }

                    journalData[row, p++] = position.Transaction == Transaction.Transfer
                                                ? position.MoneyRollover.ToString("F2")
                                                : "-";

                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Close ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reduce ||
                        position.Transaction == Transaction.Reverse)
                    {
                        journalData[row, p++] = position.MoneyCommission.ToString("F2");
                        journalData[row, p++] = position.MoneySlippage.ToString("F2");
                    }
                    else
                    {
                        journalData[row, p++] = "-";
                        journalData[row, p++] = "-";
                    }
                }
                else
                {
                    // In points
                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reverse)
                    {
                        journalData[row, p++] = position.Spread.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        journalData[row, p++] = "-";
                    }

                    journalData[row, p++] = position.Transaction == Transaction.Transfer
                                                ? position.Rollover.ToString("F2")
                                                : "-";

                    if (position.Transaction == Transaction.Open ||
                        position.Transaction == Transaction.Close ||
                        position.Transaction == Transaction.Add ||
                        position.Transaction == Transaction.Reduce ||
                        position.Transaction == Transaction.Reverse)
                    {
                        journalData[row, p++] = position.Commission.ToString("F2");
                        journalData[row, p++] = position.Slippage.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        journalData[row, p++] = "-";
                        journalData[row, p++] = "-";
                    }
                }

                // Profit Loss
                if (position.Transaction == Transaction.Close ||
                    position.Transaction == Transaction.Reduce ||
                    position.Transaction == Transaction.Reverse)
                {
                    journalData[row, p++] = profitLoss;
                }
                else
                {
                    journalData[row, p++] = "-";
                }

                // Floating Profit Loss
                if (position.PosNumb == StatsBuffer.SummaryPosNumb(bar) &&
                    position.Transaction != Transaction.Close)
                {
                    journalData[row, p++] = floatingPL; //Last position of the bar only
                }
                else
                {
                    journalData[row, p++] = "-";
                }

                // Balance / Equity
                if (Configs.AccountInMoney)
                {
                    journalData[row, p++] = position.MoneyBalance.ToString("F2");
                    journalData[row, p++] = position.MoneyEquity.ToString("F2");
                }
                else
                {
                    journalData[row, p++] = position.Balance.ToString("F2");
                    journalData[row, p++] = position.Equity.ToString("F2");
                }

                journalData[row, p] = Language.T(StatsBuffer.BackTestEvalToString(bar));

                // Icons
                posIcons[row] = Position.PositionIconImage(position.PositionIcon);
            }
        }