コード例 #1
0
 private string GetPositionFloatingPLString(int bar)
 {
     if (StatsBuffer.SummaryTrans(bar) == Transaction.Close)
     {
         return("-");
     }
     return(Configs.AccountInMoney
                ? StatsBuffer.MoneyFloatingPL(bar).ToString("F2")
                : StatsBuffer.FloatingPL(bar).ToString(CultureInfo.InvariantCulture));
 }
コード例 #2
0
        private string GetPositionAmmountString(int bar)
        {
            string sign = StatsBuffer.SummaryDir(bar) == PosDirection.Short ? "-" : "";

            if (Configs.AccountInMoney)
            {
                return(sign + StatsBuffer.SummaryAmount(bar).ToString(CultureInfo.InvariantCulture));
            }
            return(StatsBuffer.SummaryLots(bar).ToString(CultureInfo.InvariantCulture));
        }
コード例 #3
0
        private string GetPositionProfitString(int bar)
        {
            Transaction trans = StatsBuffer.SummaryTrans(bar);

            if (trans == Transaction.Close || trans == Transaction.Reduce || trans == Transaction.Reverse)
            {
                return(Configs.AccountInMoney
                           ? StatsBuffer.MoneyProfitLoss(bar).ToString("F2")
                           : StatsBuffer.ProfitLoss(bar).ToString(CultureInfo.InvariantCulture));
            }
            return("-");
        }
コード例 #4
0
        private int[] ArrangeOrderNumbers()
        {
            var ordNumbers = new int[orders];
            int index      = 0;

            for (int wayPoint = 0; wayPoint < StatsBuffer.WayPoints(selectedBar); wayPoint++)
            {
                int          ordNumb = StatsBuffer.WayPoint(selectedBar, wayPoint).OrdNumb;
                WayPointType wpType  = StatsBuffer.WayPoint(selectedBar, wayPoint).WpType;

                if (ordNumb == -1)
                {
                    continue;                // There is no order
                }
                if (ordNumb < StatsBuffer.OrdNumb(selectedBar, 0))
                {
                    continue;                                                // For a transferred position
                }
                if (wpType == WayPointType.Add || wpType == WayPointType.Cancel ||
                    wpType == WayPointType.Entry || wpType == WayPointType.Exit ||
                    wpType == WayPointType.Reduce || wpType == WayPointType.Reverse)
                {
                    ordNumbers[index] = ordNumb;
                    index++;
                }
            }

            for (int ord = 0; ord < orders; ord++)
            {
                int  ordNumb    = StatsBuffer.OrdNumb(selectedBar, ord);
                bool toIncluded = true;
                for (int i = 0; i < index; i++)
                {
                    if (ordNumb != ordNumbers[i])
                    {
                        continue;
                    }
                    toIncluded = false;
                    break;
                }
                if (!toIncluded)
                {
                    continue;
                }
                ordNumbers[index] = ordNumb;
                index++;
            }

            return(ordNumbers);
        }
コード例 #5
0
        /// <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;
            }
        }
コード例 #6
0
        /// <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();
        }
コード例 #7
0
        /// <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;
        }
コード例 #8
0
        /// <summary>
        ///     Sets the size and position of the controls
        /// </summary>
        private void SetSizes()
        {
            orders = Data.IsResult ? StatsBuffer.Orders(selectedBar) : 0;
            rows   = ClientSize.Height > 2 * rowHeight + Border
                       ? (ClientSize.Height - 2 * rowHeight - Border) / rowHeight
                       : 0;

            if (orders == 0)
            {
                firstOrd = 0;
                lastOrd  = 0;
                shownOrd = 0;

                VScrollBar.Visible = false;
                visibleWidth       = ClientSize.Width;
            }
            else if (orders < rows)
            {
                firstOrd = 0;
                lastOrd  = rows;
                shownOrd = orders;

                VScrollBar.Visible = false;
                visibleWidth       = ClientSize.Width;
            }
            else
            {
                VScrollBar.Visible = true;
                if (selectedBar != selectedBarOld)
                {
                    VScrollBar.Value = 0;
                }
                VScrollBar.Maximum = orders - 1;
                visibleWidth       = VScrollBar.Left;

                firstOrd = VScrollBar.Value;
                if (firstOrd + rows > orders)
                {
                    lastOrd  = orders - 1;
                    shownOrd = lastOrd - firstOrd + 1;
                }
                else
                {
                    shownOrd = rows;
                    lastOrd  = firstOrd + shownOrd - 1;
                }
            }

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

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

            selectedBarOld = selectedBar;
        }
コード例 #9
0
 public ThreadPoolLogger(TimeSpan logFrequency, StatsBuffer <MachineStat> buf) : base(logFrequency, buf)
 {
 }
コード例 #10
0
 public BandwidthLogger(TimeSpan logFrequency, StatsBuffer <MachineStat> buf) : base(logFrequency, buf)
 {
     _previousComputeTime = DateTimeOffset.UtcNow;
     GetNetworkUsage(out _previousReadBytes, out _previousWriteBytes);
 }
コード例 #11
0
        /// <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;
        }
コード例 #12
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 pips
                    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);
            }
        }
コード例 #13
0
        /// <summary>
        /// Prepare the parameters
        /// </summary>
        private void SetUpPaintData()
        {
            // Panel caption
            _captionText         = Language.T("Indicator Chart");
            _captionFont         = new Font(Font.FontFamily, 9);
            _captionHeight       = Math.Max(_captionFont.Height, 18);
            _captionWidth        = ClientSize.Width;
            _captionBrush        = new SolidBrush(LayoutColors.ColorCaptionText);
            _captionRectangle    = new RectangleF(0, 0, _captionWidth, _captionHeight);
            _captionStringFormat = new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter,
                FormatFlags   = StringFormatFlags.NoWrap
            };

            if (!Data.IsData || !Data.IsResult || Data.Bars <= StatsBuffer.FirstBar)
            {
                return;
            }

            _xLeft                         = Space;
            _xRight                        = ClientSize.Width - Space;
            _yTop                          = (int)_captionHeight + Space;
            _yBottom                       = ClientSize.Height - _scrollBar.Height - Space;
            _yPriceBottom                  = _yBottom;
            _separateIndicatorsCount       = 0;
            _separateIndicatorsChartHeight = 0;
            _indicatorSlots                = new int[Configs.MaxEntryFilters + Configs.MaxExitFilters + 2];

            _penFore   = new Pen(LayoutColors.ColorChartFore);
            _penVolume = new Pen(LayoutColors.ColorVolume);
            _penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption),
                                 Border);

            for (int slot = StatsBuffer.Strategy.Slots - 1; slot >= 0; slot--)
            {
                if (StatsBuffer.Strategy.Slot[slot].SeparatedChart)
                {
                    _indicatorSlots[_separateIndicatorsCount++] = slot;
                }
            }

            if (_separateIndicatorsCount > 0)
            {
                _separateIndicatorsChartHeight = (_yBottom - _yTop) / (2 + _separateIndicatorsCount);
                _yPriceBottom = _yBottom - _separateIndicatorsCount * _separateIndicatorsChartHeight;
            }

            _maxPrice  = double.MinValue;
            _minPrice  = double.MaxValue;
            _maxVolume = int.MinValue;

            for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
            {
                if (Data.High[bar] > _maxPrice)
                {
                    _maxPrice = Data.High[bar];
                }
                if (Data.Low[bar] < _minPrice)
                {
                    _minPrice = Data.Low[bar];
                }
                if (Data.Volume[bar] > _maxVolume)
                {
                    _maxVolume = Data.Volume[bar];
                }
            }
            _minPrice = Math.Round(_minPrice, Data.InstrProperties.Point < 0.001 ? 3 : 1) -
                        Data.InstrProperties.Point * 10;
            _maxPrice = Math.Round(_maxPrice, Data.InstrProperties.Point < 0.001 ? 3 : 1) +
                        Data.InstrProperties.Point * 10;
            _scaleY    = (_yPriceBottom - _yTop) / (_maxPrice - _minPrice);
            _scaleYVol = _maxVolume > 0 ? ((_yPriceBottom - _yTop) / 8d) / _maxVolume : 0d;

            // Volume, Lots and Price
            _x             = new int[_chartBars];
            _yOpen         = new int[_chartBars];
            _yHigh         = new int[_chartBars];
            _yLow          = new int[_chartBars];
            _yClose        = new int[_chartBars];
            _yVolume       = new int[_chartBars];
            _rectPosition  = new Rectangle[_chartBars];
            _brushPosition = new Brush[_chartBars];

            int index = 0;

            for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
            {
                _x[index]       = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                _yOpen[index]   = (int)(_yPriceBottom - (Data.Open[bar] - _minPrice) * _scaleY);
                _yHigh[index]   = (int)(_yPriceBottom - (Data.High[bar] - _minPrice) * _scaleY);
                _yLow[index]    = (int)(_yPriceBottom - (Data.Low[bar] - _minPrice) * _scaleY);
                _yClose[index]  = (int)(_yPriceBottom - (Data.Close[bar] - _minPrice) * _scaleY);
                _yVolume[index] = (int)(_yPriceBottom - Data.Volume[bar] * _scaleYVol);

                // Draw position lots
                if (StatsBuffer.IsPos(bar))
                {
                    var posHight = (int)(Math.Max(StatsBuffer.SummaryLots(bar) * 2, 2));
                    int yPos     = _yPriceBottom - posHight;

                    switch (StatsBuffer.SummaryDir(bar))
                    {
                    case PosDirection.Long:
                        _rectPosition[index]  = new Rectangle(_x[index], yPos, 1, posHight);
                        _brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeLong);
                        break;

                    case PosDirection.Short:
                        _rectPosition[index]  = new Rectangle(_x[index], yPos, 1, posHight);
                        _brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeShort);
                        break;

                    case PosDirection.Closed:
                        _rectPosition[index]  = new Rectangle(_x[index], yPos - 2, 1, 2);
                        _brushPosition[index] = new SolidBrush(LayoutColors.ColorTradeClose);
                        break;
                    }
                }
                else
                {
                    // There is no position
                    _rectPosition[index]  = Rectangle.Empty;
                    _brushPosition[index] = new SolidBrush(LayoutColors.ColorChartBack);
                }
                index++;
            }

            // Indicators in the chart
            int slots = StatsBuffer.Strategy.Slots;

            _isSeparatedChart = new bool[slots];
            _componentLenght  = new int[slots];
            _chartType        = new IndChartType[slots][];
            _chartLine        = new Point[slots][][];
            _chartDot         = new Rectangle[slots][][];
            _chartLevel       = new Rectangle[slots][][];
            _chartValue       = new double[slots][][];
            _chartPen         = new Pen[slots][][];
            _chartBrush       = new Brush[slots][];

            for (int slot = 0; slot < slots; slot++)
            {
                _isSeparatedChart[slot] = StatsBuffer.Strategy.Slot[slot].SeparatedChart;
                int count = StatsBuffer.Strategy.Slot[slot].Component.Length;
                _componentLenght[slot] = count;
                _chartType[slot]       = new IndChartType[count];
                _chartLine[slot]       = new Point[count][];
                _chartDot[slot]        = new Rectangle[count][];
                _chartLevel[slot]      = new Rectangle[count][];
                _chartValue[slot]      = new double[count][];
                _chartPen[slot]        = new Pen[count][];
                _chartBrush[slot]      = new Brush[count];
            }

            for (int slot = 0; slot < slots; slot++)
            {
                if (_isSeparatedChart[slot])
                {
                    continue;
                }

                for (int comp = 0; comp < _componentLenght[slot]; comp++)
                {
                    _chartType[slot][comp] = StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType;
                    switch (StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType)
                    {
                    case IndChartType.Line:
                    case IndChartType.CloudUp:
                    case IndChartType.CloudDown:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartLine[slot][comp] = new Point[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yPriceBottom - (value - _minPrice) * _scaleY);

                            if (Math.Abs(value - 0) < 0.0001)
                            {
                                _chartLine[slot][comp][bar - _chartFirstBar] =
                                    _chartLine[slot][comp][Math.Max(bar - _chartFirstBar - 1, 0)];
                            }
                            else
                            {
                                _chartLine[slot][comp][bar - _chartFirstBar] = new Point(x, y);
                            }
                        }
                        break;

                    case IndChartType.Dot:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartDot[slot][comp] = new Rectangle[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yPriceBottom - (value - _minPrice) * _scaleY);
                            _chartDot[slot][comp][bar - _chartFirstBar] = new Rectangle(x, y, 1, 1);
                        }
                        break;

                    case IndChartType.Level:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartLevel[slot][comp] = new Rectangle[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yPriceBottom - (value - _minPrice) * _scaleY);
                            _chartLevel[slot][comp][bar - _chartFirstBar] = new Rectangle(x, y, _chartBarWidth, 1);
                        }
                        break;
                    }
                }
            }

            // Separate indicators
            _yIndTop    = new int[_separateIndicatorsCount];
            _yIndBottom = new int[_separateIndicatorsCount];
            _maxValues  = new double[_separateIndicatorsCount];
            _minValues  = new double[_separateIndicatorsCount];
            _scales     = new double[_separateIndicatorsCount];

            for (int ind = 0; ind < _separateIndicatorsCount; ind++)
            {
                _yIndTop[ind]    = _yBottom - (ind + 1) * _separateIndicatorsChartHeight + 1;
                _yIndBottom[ind] = _yBottom - ind * _separateIndicatorsChartHeight - 1;
                _maxValues[ind]  = double.MinValue;
                _minValues[ind]  = double.MaxValue;
                int slot = _indicatorSlots[ind];

                for (int comp = 0; comp < _componentLenght[slot]; comp++)
                {
                    if (StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType != IndChartType.NoChart)
                    {
                        for (
                            int bar = Math.Max(_chartFirstBar, StatsBuffer.Strategy.Slot[slot].Component[comp].FirstBar);
                            bar <= _chartLastBar;
                            bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            if (value > _maxValues[ind])
                            {
                                _maxValues[ind] = value;
                            }
                            if (value < _minValues[ind])
                            {
                                _minValues[ind] = value;
                            }
                        }
                    }
                }

                _maxValues[ind] = Math.Max(_maxValues[ind], StatsBuffer.Strategy.Slot[slot].MaxValue);
                _minValues[ind] = Math.Min(_minValues[ind], StatsBuffer.Strategy.Slot[slot].MinValue);

                foreach (double specialValue in StatsBuffer.Strategy.Slot[slot].SpecValue)
                {
                    if (Math.Abs(specialValue - 0) < 0.0001)
                    {
                        _maxValues[ind] = Math.Max(_maxValues[ind], 0);
                        _minValues[ind] = Math.Min(_minValues[ind], 0);
                    }
                }

                _scales[ind] = (_yIndBottom[ind] - _yIndTop[ind] - 2) / (Math.Max(_maxValues[ind] - _minValues[ind], 0.0001f));

                // Indicator chart
                for (int comp = 0; comp < StatsBuffer.Strategy.Slot[slot].Component.Length; comp++)
                {
                    _chartType[slot][comp] = StatsBuffer.Strategy.Slot[slot].Component[comp].ChartType;
                    switch (_chartType[slot][comp])
                    {
                    case IndChartType.Line:
                        _chartBrush[slot][comp] =
                            new SolidBrush(StatsBuffer.Strategy.Slot[slot].Component[comp].ChartColor);
                        _chartLine[slot][comp] = new Point[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            int    x     = (bar - _chartFirstBar) * _chartBarWidth + _xLeft;
                            var    y     = (int)(_yIndBottom[ind] - 1 - (value - _minValues[ind]) * _scales[ind]);
                            _chartLine[slot][comp][bar - _chartFirstBar] = new Point(x, y);
                        }
                        break;

                    case IndChartType.Histogram:
                        _chartValue[slot][comp] = new double[_chartLastBar - _chartFirstBar + 1];
                        _chartPen[slot][comp]   = new Pen[_chartLastBar - _chartFirstBar + 1];
                        for (int bar = _chartFirstBar; bar <= _chartLastBar; bar++)
                        {
                            double value = StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar];
                            _chartValue[slot][comp][bar - _chartFirstBar] = value;
                            if (value > StatsBuffer.Strategy.Slot[slot].Component[comp].Value[bar - 1])
                            {
                                _chartPen[slot][comp][bar - _chartFirstBar] = _penGreen;
                            }
                            else
                            {
                                _chartPen[slot][comp][bar - _chartFirstBar] = _penRed;
                            }
                        }
                        break;
                    }
                }
            }
        }
コード例 #14
0
 public PageFaultLogger(TimeSpan logFrequency, StatsBuffer <MachineStat> buf) : base(logFrequency, buf)
 {
     pfHelper = new PageFaultHelper(logFrequency);
 }
コード例 #15
0
 private static double GetProfit(int bar, int pos)
 {
     return(Configs.AccountInMoney
                ? StatsBuffer.PosMoneyProfitLoss(bar, pos)
                : StatsBuffer.PosProfitLoss(bar, pos));
 }
コード例 #16
0
        /// <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();
        }
コード例 #17
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;
            }
        }
コード例 #18
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();
        }