Example #1
0
        /// <summary>
        /// Chart tab page is shown.
        /// </summary>
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            if (chart != null)
            {
                Chart_Data chartData = GetChartDataObject();
                chart.InitChart(chartData);
            }
        }
Example #2
0
 void UpdateChartThreadSafely(bool repaintChart, Chart_Data chartData)
 {
     if (chart.InvokeRequired)
     {
         chart.BeginInvoke(new UpdateChartDelegate(UpdateChartThreadSafely), new object[] { repaintChart, chartData });
     }
     else
     {
         chart.UpdateChartOnTick(repaintChart, chartData);
     }
 }
Example #3
0
        /// <summary>
        /// Creates a new chart.
        /// </summary>
        void CreateChart()
        {
            if (tabControlBase.SelectedTab == tabPageChart)
            {
                Chart_Data chartData = GetChartDataObject();
                chart        = new Chart(chartData);
                chart.Parent = tabPageChart;
                chart.Dock   = DockStyle.Fill;
                chart.InitChart(chartData);
            }

            return;
        }
Example #4
0
        /// <summary>
        /// Updates the chart.
        /// </summary>
        protected void UpdateChart()
        {
            if (chart == null)
            {
                return;
            }

            bool repaintChart = (
                chartSymbol != Data.Symbol ||
                chartPeriod != Data.Period ||
                chartBars != Data.Bars ||
                chartTime != Data.Time[Data.Bars - 1] ||
                chartTime10 != Data.Time[Data.Bars - 11]);

            chartSymbol = Data.Symbol;
            chartPeriod = Data.Period;
            chartBars   = Data.Bars;
            chartTime   = Data.Time[Data.Bars - 1];
            chartTime10 = Data.Time[Data.Bars - 11];

            // Prepares chart data.
            Chart_Data chartData = GetChartDataObject();

            try
            {
                UpdateChartThreadSafely(repaintChart, chartData);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, Language.T("Indicator Chart"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                DisposeChart();
                CreateChart();
            }

            return;
        }
Example #5
0
        Chart_Data GetChartDataObject()
        {
            Chart_Data chartData = new Chart_Data();

            chartData.InstrumentProperties = Data.InstrProperties.Clone();
            chartData.Bars   = Data.Bars;
            chartData.Time   = new DateTime[Data.Bars];
            chartData.Open   = new double[Data.Bars];
            chartData.High   = new double[Data.Bars];
            chartData.Low    = new double[Data.Bars];
            chartData.Close  = new double[Data.Bars];
            chartData.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);
        }
 void UpdateChartThreadSafely(bool repaintChart, Chart_Data chartData)
 {
     if (chart.InvokeRequired)
     {
         chart.BeginInvoke(new UpdateChartDelegate(UpdateChartThreadSafely), new object[] { repaintChart, chartData });
     }
     else
     {
         chart.UpdateChartOnTick(repaintChart, chartData);
     }
 }
        Chart_Data GetChartDataObject()
        {
            Chart_Data chartData = new Chart_Data();
            chartData.InstrumentProperties = Data.InstrProperties.Clone();
            chartData.Bars   = Data.Bars;
            chartData.Time   = new DateTime[Data.Bars];
            chartData.Open   = new double[Data.Bars];
            chartData.High   = new double[Data.Bars];
            chartData.Low    = new double[Data.Bars];
            chartData.Close  = new double[Data.Bars];
            chartData.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;
        }
        /// <summary>
        /// Updates the chart after a tick.
        /// </summary>
        public void UpdateChartOnTick(bool repaintChart, Chart_Data chartData)
        {
            this.chartData = chartData;

            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;
                Rectangle rect = new Rectangle(left, 0, width, YBottom + 1);
                pnlPrice.Invalidate(rect);
            }

            for (int i = 0; i < pnlInd.Length; i++)
            {
                int 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;
                    Rectangle rect = new Rectangle(left, 0, width, YBottom + 1);
                    pnlInd[i].Invalidate(rect);
                }
            }

            if (isInfoPanelShown && !isCrossShown)
                GenerateDynamicInfo(lastBar);

            return;
        }
        /// <summary>
        /// Performs post initialization settings.
        /// </summary>
        public void InitChart(Chart_Data chartData)
        {
            this.chartData = chartData;

            scroll.Select();

            return;
        }
        int YTop; // pnlPrice top coordinate

        #endregion Fields

        #region Constructors

        // ------------------------------------------------------------
        /// <summary>
        /// The default constructor.
        /// </summary>
        public Chart(Chart_Data chartData)
        {
            this.chartData = chartData;

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

            pnlCharts = new Panel();
            pnlCharts.Parent = this;
            pnlCharts.Dock   = DockStyle.Fill;

            pnlInfo = new Panel();
            pnlInfo.Parent    = this;
            pnlInfo.BackColor = LayoutColors.ColorControlBack;
            pnlInfo.Dock      = DockStyle.Right;
            pnlInfo.Paint    += new PaintEventHandler(PnlInfo_Paint);

            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 += new EventHandler(PnlCharts_Resize);
            pnlPrice.Resize  += new EventHandler(PnlPrice_Resize);

            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);
            brushBarWhite    = new SolidBrush(LayoutColors.ColorBarWhite);
            brushBarBlack    = new SolidBrush(LayoutColors.ColorBarBlack);
            brushSignalRed   = new SolidBrush(LayoutColors.ColorSignalRed);

            penGrid       = new Pen(LayoutColors.ColorChartGrid);
            penGridSolid  = new Pen(LayoutColors.ColorChartGrid);
            penAxes       = new Pen(LayoutColors.ColorChartFore);
            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);

            return;
        }