/// <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>
        /// Sets the journal's current data
        /// </summary>
        public void SetUpJournal()
        {
            if (ShowTransfers)
            {
                _positions = StatsBuffer.PositionsTotal;
            }
            else
            {
                _posNumbers = StatsBuffer.PositionsTotal > 0 ? new int[StatsBuffer.PositionsTotal] : new int[1];
                _positions  = 0;
                for (int bar = 0; bar < Data.Bars; bar++)
                {
                    for (int pos = 0; pos < StatsBuffer.Positions(bar); pos++)
                    {
                        Transaction transaction = StatsBuffer.PosTransaction(bar, pos);
                        if (transaction == Transaction.None || transaction == Transaction.Transfer)
                        {
                            continue;
                        }
                        _posNumbers[_positions] = StatsBuffer.PosNumb(bar, pos);
                        _positions++;
                    }
                }
            }

            if (_positions == 0)
            {
                _firstPos    = 0;
                _lastPos     = 0;
                _shownPos    = 0;
                _selectedRow = 0;

                _vScrollBar.Enabled = false;
            }
            else if (_positions < _rows)
            {
                _firstPos    = 0;
                _lastPos     = _rows;
                _shownPos    = _positions;
                _selectedRow = 0;

                _vScrollBar.Enabled = false;
            }
            else
            {
                _vScrollBar.Enabled = true;
                _vScrollBar.Maximum = _positions - 1;

                _firstPos = _vScrollBar.Value;
                if (_firstPos + _rows > _positions)
                {
                    _lastPos  = _positions - 1;
                    _shownPos = _lastPos - _firstPos + 1;
                }
                else
                {
                    _shownPos = _rows;
                    _lastPos  = _firstPos + _shownPos - 1;
                }
            }

            _selectedRow = Math.Min(_selectedRow, _shownPos - 1);
            _selectedRow = Math.Max(_selectedRow, 0);

            UpdateJournalData();
            SetJournalColors();
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Sets the journal's current data
        /// </summary>
        public void SetUpJournal()
        {
            if (!StatsBuffer.IsStatsBufferValid)
            {
                return;
            }

            if (ShowTransfers)
            {
                positions = StatsBuffer.PositionsTotal;
            }
            else
            {
                posNumbers = StatsBuffer.PositionsTotal > 0 ? new int[StatsBuffer.PositionsTotal] : new int[1];
                positions  = 0;
                for (int bar = 0; bar < Data.Bars; bar++)
                {
                    for (int pos = 0; pos < StatsBuffer.Positions(bar); pos++)
                    {
                        Transaction transaction = StatsBuffer.PosTransaction(bar, pos);
                        if (transaction == Transaction.None || transaction == Transaction.Transfer)
                        {
                            continue;
                        }
                        posNumbers[positions] = StatsBuffer.PosNumb(bar, pos);
                        positions++;
                    }
                }
            }

            if (positions == 0)
            {
                firstPos    = 0;
                lastPos     = 0;
                shownPos    = 0;
                selectedRow = 0;

                vScrollBar.Enabled = false;
            }
            else if (positions < rows)
            {
                firstPos    = 0;
                lastPos     = rows;
                shownPos    = positions;
                selectedRow = 0;

                vScrollBar.Enabled = false;
            }
            else
            {
                vScrollBar.Enabled = true;
                vScrollBar.Maximum = positions - 1;

                firstPos = vScrollBar.Value;
                if (firstPos + rows > positions)
                {
                    lastPos  = positions - 1;
                    shownPos = lastPos - firstPos + 1;
                }
                else
                {
                    shownPos = rows;
                    lastPos  = firstPos + shownPos - 1;
                }
            }

            selectedRow = Math.Min(selectedRow, shownPos - 1);
            selectedRow = Math.Max(selectedRow, 0);

            UpdateJournalData();
            SetJournalColors();
        }