Example #1
0
        /// <summary>
        ///     Updates the chart after a tick.
        /// </summary>
        public void UpdateChartOnTick(bool repaintChart, ChartData data)
        {
            chartData = data;

            if (repaintChart)
                SetupChartTitle();

            bool updateWholeChart = repaintChart;
            double oldMaxPrice = maxPrice;
            double oldMinPrice = minPrice;

            if (isChartAutoScroll || repaintChart)
                SetFirstLastBar();

            SetPriceChartMinMaxValues();

            if (Math.Abs(maxPrice - oldMaxPrice) > chartData.InstrumentProperties.Point ||
                Math.Abs(minPrice - oldMinPrice) > chartData.InstrumentProperties.Point)
                updateWholeChart = true;

            if (updateWholeChart)
            {
                PnlPrice.Invalidate();
            }
            else
            {
                int left = spcLeft + (chartBars - 2)*barPixels;
                int width = PnlPrice.ClientSize.Width - left;
                var rect = new Rectangle(left, 0, width, yBottom + 1);
                PnlPrice.Invalidate(rect);
            }

            for (int i = 0; i < PnlInd.Length; i++)
            {
                var slot = (int) PnlInd[i].Tag;
                oldMaxPrice = sepChartMaxValue[slot];
                oldMinPrice = sepChartMinValue[slot];
                SetSepChartsMinMaxValues(i);
                if (Math.Abs(sepChartMaxValue[slot] - oldMaxPrice) > 0.000001 ||
                    Math.Abs(sepChartMinValue[slot] - oldMinPrice) > 0.000001)
                    updateWholeChart = true;

                if (updateWholeChart)
                {
                    PnlInd[i].Invalidate();
                }
                else
                {
                    int left = spcLeft + (chartBars - 2)*barPixels;
                    int width = PnlInd[i].ClientSize.Width - left;
                    var rect = new Rectangle(left, 0, width, yBottom + 1);
                    PnlInd[i].Invalidate(rect);
                }
            }

            if (isInfoPanelShown && !isCrossShown)
                GenerateDynamicInfo(lastBar);
        }
Example #2
0
 /// <summary>
 ///     Performs post initialization settings.
 /// </summary>
 public void InitChart(ChartData data)
 {
     chartData = data;
     ScrollBar.Select();
 }
 void UpdateChartThreadSafely(bool repaintChart, ChartData chartData)
 {
     if (chart.InvokeRequired)
     {
         chart.BeginInvoke(new UpdateChartDelegate(UpdateChartThreadSafely), new object[] { repaintChart, chartData });
     }
     else
     {
         chart.UpdateChartOnTick(repaintChart, chartData);
     }
 }
Example #4
0
        private int yTop; // pnlPrice top coordinate

        #endregion Fields

        #region Constructors

        // ------------------------------------------------------------
        /// <summary>
        ///     The default constructor.
        /// </summary>
        public Chart(ChartData data)
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque,
                     true);

            chartData = data;

            BackColor = LayoutColors.ColorFormBack;
            Padding = new Padding(0);

            PnlCharts = new Panel {Parent = this, Dock = DockStyle.Fill};

            PnlInfo = new Panel {Parent = this, BackColor = LayoutColors.ColorControlBack, Dock = DockStyle.Right};
            PnlInfo.Paint += PnlInfoPaint;

            barPixels = Configs.ChartZoom;
            isGridShown = Configs.ChartGrid;
            isCrossShown = Configs.ChartCross;
            isVolumeShown = Configs.ChartVolume;
            isPositionLotsShown = Configs.ChartLots;
            isOrdersShown = Configs.ChartOrders;
            isPositionPriceShown = Configs.ChartPositionPrice;
            isInfoPanelShown = Configs.ChartInfoPanel;
            isTrueChartsShown = Configs.ChartTrueCharts;
            isChartShift = Configs.ChartShift;
            isChartAutoScroll = Configs.ChartAutoScroll;

            dynInfoScrollValue = 0;

            font = new Font(Font.FontFamily, 8);

            // Dynamic info fonts
            fontDi = new Font(Font.FontFamily, 9);
            fontDiInd = new Font(Font.FontFamily, 10);

            Graphics g = CreateGraphics();
            szDate = g.MeasureString("99/99 99:99", font).ToSize();
            szDateL = g.MeasureString("99/99/99 99:99", font).ToSize();
            // TODO checking exact price with.
            szPrice = g.MeasureString("9.99999", font).ToSize();
            szSL = g.MeasureString(" SL", font).ToSize();
            g.Dispose();

            SetupDynInfoWidth();
            SetupIndicatorPanels();
            SetupButtons();
            SetupDynamicInfo();
            SetupChartTitle();

            PnlInfo.Visible = isInfoPanelShown;
            PnlCharts.Padding = isInfoPanelShown ? new Padding(0, 0, 2, 0) : new Padding(0);

            PnlCharts.Resize += PnlChartsResize;
            PnlPrice.Resize += PnlPriceResize;

            spcTop = font.Height;
            spcBottom = font.Height*8/5;
            spcLeft = 0;
            spcRight = szPrice.Width + szSL.Width + 2;

            brushBack = new SolidBrush(LayoutColors.ColorChartBack);
            brushFore = new SolidBrush(LayoutColors.ColorChartFore);
            brushLabelBkgrd = new SolidBrush(LayoutColors.ColorLabelBack);
            brushLabelFore = new SolidBrush(LayoutColors.ColorLabelText);
            brushDynamicInfo = new SolidBrush(LayoutColors.ColorControlText);
            brushDiIndicator = new SolidBrush(LayoutColors.ColorSlotIndicatorText);
            brushEvenRows = new SolidBrush(LayoutColors.ColorEvenRowBack);
            brushTradeLong = new SolidBrush(LayoutColors.ColorTradeLong);
            brushTradeShort = new SolidBrush(LayoutColors.ColorTradeShort);
            brushTradeClose = new SolidBrush(LayoutColors.ColorTradeClose);

            penGrid = new Pen(LayoutColors.ColorChartGrid);
            penGridSolid = new Pen(LayoutColors.ColorChartGrid);
            penCross = new Pen(LayoutColors.ColorChartCross);
            penVolume = new Pen(LayoutColors.ColorVolume);
            penBarBorder = new Pen(LayoutColors.ColorBarBorder);
            penBarThick = new Pen(LayoutColors.ColorBarBorder, 3);
            penTradeLong = new Pen(LayoutColors.ColorTradeLong);
            penTradeShort = new Pen(LayoutColors.ColorTradeShort);
            penTradeClose = new Pen(LayoutColors.ColorTradeClose);

            penGrid.DashStyle = DashStyle.Dash;
            penGrid.DashPattern = new float[] {4, 2};

            colorBarWhite1 = Data.ColorChanage(LayoutColors.ColorBarWhite, 30);
            colorBarWhite2 = Data.ColorChanage(LayoutColors.ColorBarWhite, -30);
            colorBarBlack1 = Data.ColorChanage(LayoutColors.ColorBarBlack, 30);
            colorBarBlack2 = Data.ColorChanage(LayoutColors.ColorBarBlack, -30);

            colorLongTrade1 = Data.ColorChanage(LayoutColors.ColorTradeLong, 30);
            colorLongTrade2 = Data.ColorChanage(LayoutColors.ColorTradeLong, -30);
            colorShortTrade1 = Data.ColorChanage(LayoutColors.ColorTradeShort, 30);
            colorShortTrade2 = Data.ColorChanage(LayoutColors.ColorTradeShort, -30);
            colorClosedTrade1 = Data.ColorChanage(LayoutColors.ColorTradeClose, 30);
            colorClosedTrade2 = Data.ColorChanage(LayoutColors.ColorTradeClose, -30);
        }
        ChartData GetChartDataObject()
        {
            var chartData = new ChartData
                                {
                                    InstrumentProperties = Data.InstrProperties.Clone(),
                                    Bars = Data.Bars,
                                    Time = new DateTime[Data.Bars],
                                    Open = new double[Data.Bars],
                                    High = new double[Data.Bars],
                                    Low = new double[Data.Bars],
                                    Close = new double[Data.Bars],
                                    Volume = new int[Data.Bars]
                                };
            Data.Time.CopyTo(chartData.Time, 0);
            Data.Open.CopyTo(chartData.Open, 0);
            Data.High.CopyTo(chartData.High, 0);
            Data.Low.CopyTo(chartData.Low, 0);
            Data.Close.CopyTo(chartData.Close, 0);
            Data.Volume.CopyTo(chartData.Volume, 0);
            chartData.StrategyName = Data.StrategyName;
            chartData.Strategy  = Data.Strategy.Clone();
            chartData.FirstBar  = Data.FirstBar;
            chartData.Symbol    = Data.Symbol;
            chartData.PeriodStr = Data.PeriodStr;
            chartData.Bid       = Data.Bid;
            chartData.BarStatistics = new Dictionary<DateTime, BarStats>();
            foreach (KeyValuePair<DateTime, BarStats> timeStat in Data.BarStatistics)
                chartData.BarStatistics.Add(timeStat.Key, timeStat.Value.Clone());
            chartData.PositionDirection  = Data.PositionDirection;
            chartData.PositionOpenPrice  = Data.PositionOpenPrice;
            chartData.PositionProfit     = Data.PositionProfit;
            chartData.PositionStopLoss   = Data.PositionStopLoss;
            chartData.PositionTakeProfit = Data.PositionTakeProfit;

            return chartData;
        }