/// <summary>
        ///     Calculates Data to draw in histogram
        /// </summary>
        private void CalculateHistogramData()
        {
            InitChartData();

            for (int bar = 0; bar < Data.Bars; bar++)
            {
                int positions = StatsBuffer.Positions(bar);
                for (int pos = 0; pos < positions; pos++)
                {
                    if (!IsTrade(StatsBuffer.PosTransaction(bar, pos)))
                    {
                        continue;
                    }

                    double result  = GetProfit(bar, pos);
                    var    index   = (int)Math.Round(result);
                    bool   isIndex = chartData.ContainsKey(index);
                    int    count   = isIndex ? chartData[index].TradesCount + 1 : 1;
                    double total   = isIndex ? chartData[index].TotalResult + result : result;
                    var    data    = new HistogramData {
                        TradesCount = count, Result = result, TotalResult = total
                    };

                    if (isIndex)
                    {
                        chartData[index] = data;
                    }
                    else
                    {
                        chartData.Add(index, data);
                    }

                    SetMinMaxValues(index, count, total);
                }
            }

            chartData.Sort();
        }
Пример #2
0
        /// <summary>
        /// Calculates Data to draw in histogram
        /// </summary>
        private static void CalculateHistogramData()
        {
            // crummy way to get number of trades for init array
            // TBD -- find better property
            int ctr = 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.Close ||
                        transaction == Transaction.Reduce ||
                        transaction == Transaction.Reverse)
                    {
                        ctr++;
                    }
                }
            }

            _tradeResults = new int[ctr];
            ctr           = 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.Close ||
                        transaction == Transaction.Reduce ||
                        transaction == Transaction.Reverse)
                    {
                        _tradeResults[ctr] = (int)StatsBuffer.PosProfitLoss(bar, pos);
                        ctr++;
                    }
                }
            }

            int min = 0;
            int max = 0;

            foreach (int result in _tradeResults)
            {
                if (min > result)
                {
                    min = result;
                }
                if (max < result)
                {
                    max = result;
                }
            }
            _tradeIndexes     = new int[(max - min) + 1];
            _tradeCounts      = new int[(max - min) + 1];
            _tradeCumulatives = new int[(max - min) + 1];

            // fill _tradeIndexes with index values, then count how many in _tradeResults
            for (int ctr1 = 0; ctr1 < _tradeIndexes.Length; ctr1++)
            {
                _tradeIndexes[ctr1] = min + ctr1;
                int count = 0;
                for (int ctr2 = 0; ctr2 < _tradeResults.Length; ctr2++)
                {
                    if (_tradeResults[ctr2] == _tradeIndexes[ctr1])
                    {
                        count++;
                    }
                }
                _tradeCounts[ctr1]      = count;
                _tradeCumulatives[ctr1] = _tradeIndexes[ctr1] * count;
            }
        }
        /// <summary>
        /// Sets the size and position of the controls
        /// </summary>
        private void SetSizes()
        {
            _positions = Data.IsResult ? StatsBuffer.Positions(SelectedBar) : 0;
            _rows      = ClientSize.Height > 2 * _rowHeight + Border ? (ClientSize.Height - 2 * _rowHeight - Border) / _rowHeight : 0;

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

                VScrollBar.Visible = false;
                _visibalWidth      = ClientSize.Width;
            }
            else if (_positions < _rows)
            {
                _firstPos = 0;
                _lastPos  = _rows;
                _shownPos = _positions;

                VScrollBar.Visible = false;
                _visibalWidth      = ClientSize.Width;
            }
            else
            {
                VScrollBar.Visible = true;
                if (SelectedBar != _selectedBarOld)
                {
                    VScrollBar.Value = 0;
                }
                VScrollBar.Maximum = _positions - 1;
                _visibalWidth      = VScrollBar.Left;

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

            if (_visibalWidth <= _xColumns[_columns])
            {
                _xColumns.CopyTo(_xScaled, 0);
            }
            else
            {
                // Scales the columns position
                float fScale = (float)_visibalWidth / _xColumns[_columns];
                for (int i = 0; i <= _columns; i++)
                {
                    _xScaled[i] = (int)(_xColumns[i] * fScale);
                }
            }

            if (_visibalWidth < _xColumns[_columns])
            {
                HScrollBar.Visible = true;
                int iPoinShort = _xColumns[_columns] - _visibalWidth;
                if (HScrollBar.Value > iPoinShort)
                {
                    HScrollBar.Value = iPoinShort;
                }
                HScrollBar.Maximum = iPoinShort + HScrollBar.LargeChange - 2;
            }
            else
            {
                HScrollBar.Value   = 0;
                HScrollBar.Visible = false;
            }

            _selectedBarOld = SelectedBar;
        }
        /// <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();
        }
        /// <summary>
        ///     Sets the size and position of the controls
        /// </summary>
        private void SetSizes()
        {
            positions = Data.IsResult ? StatsBuffer.Positions(SelectedBar) : 0;
            rows      = ClientSize.Height > 2 * rowHeight + Border ? (ClientSize.Height - 2 * rowHeight - Border) / rowHeight : 0;

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

                vScrollBar.Visible = false;
                visibleWidth       = ClientSize.Width;
            }
            else if (positions < rows)
            {
                firstPos = 0;
                lastPos  = rows;
                shownPos = positions;

                vScrollBar.Visible = false;
                visibleWidth       = ClientSize.Width;
            }
            else
            {
                vScrollBar.Visible = true;
                if (SelectedBar != selectedBarOld)
                {
                    vScrollBar.Value = 0;
                }
                vScrollBar.Maximum = positions - 1;
                visibleWidth       = vScrollBar.Left;

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

            if (visibleWidth <= xColumns[columns])
            {
                xColumns.CopyTo(xScaled, 0);
            }
            else
            {
                // Scales the columns position
                float fScale = (float)visibleWidth / xColumns[columns];
                for (int i = 0; i <= columns; i++)
                {
                    xScaled[i] = (int)(xColumns[i] * fScale);
                }
            }

            if (visibleWidth < xColumns[columns])
            {
                hScrollBar.Visible = true;
                int iPoinShort = xColumns[columns] - visibleWidth;
                if (hScrollBar.Value > iPoinShort)
                {
                    hScrollBar.Value = iPoinShort;
                }
                hScrollBar.Maximum = iPoinShort + hScrollBar.LargeChange - 2;
            }
            else
            {
                hScrollBar.Value   = 0;
                hScrollBar.Visible = false;
            }

            selectedBarOld = SelectedBar;
        }
Пример #6
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();
        }