void openChart_Click(object sender, EventArgs e)
        {
            MenuItem mi = (MenuItem)sender;

            ChartControl chartControl = new ChartControl();
            chartControl.Online = true;
            chartControl.Symbol = mi.Tag.ToString();
            chartControl.Exchange = "";
            chartControl.Interval = 60;
            chartControl.Period = "1d";
            frm_chart newMDIchild = new frm_chart(chartControl);
            newMDIchild.MdiParent = this.MdiParent;
            newMDIchild.Show();
        }
Exemple #2
0
        public void dispayChart(ChartControl chartControl, ArrayList chartSource)
        {
            chart1.Series.Clear();
            chart1.ChartAreas.Clear();

            #region calculating min and max
            double maxHigh = 0;
            double minLow = 99999999;

            if (this.ChartControl.Online)
            {
                ArrayList liveChartSource = chartSource.GetRange(chartSource.Count - 200, 200);
                chartSource = liveChartSource;
            }

            foreach (Candle curCandle in chartSource)
            {
                if (curCandle.High > maxHigh) maxHigh = curCandle.High;
                if (curCandle.Low < minLow) minLow = curCandle.Low;
            }

            double delta = maxHigh - minLow;
            #endregion

            #region chart settings
            ChartArea chartArea = new ChartArea("ChartArea");
            Series line = new Series("line");
            Series price = new Series("price");
            chart1.ChartAreas.Add(chartArea);
            chart1.Series.Add(price);
            chart1.Series.Add(line);
            price.YValuesPerPoint = 4;
            chart1.Series["price"].ChartType = chartControl.ChartType;
            chart1.Series["line"].ChartType = SeriesChartType.Line;
            chart1.Series["price"].XValueType = ChartValueType.DateTime;
            chart1.Series["line"].XValueType = ChartValueType.DateTime;

            chartArea.AxisY.LabelStyle.Format = "F2";
            chartArea.AxisY.Maximum = maxHigh;
            chartArea.AxisY.Minimum = minLow;
            chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount;

            price["PriceUpColor"] = chartControl.PriceUpColor.ToArgb().ToString();
            price["PriceDownColor"] = chartControl.PriceDownColor.ToArgb().ToString();
            chart1.BackColor = chartControl.BackgroundColor;
            chartArea.BackColor = chartControl.BackgroundColor;
            price.Color = Color.Yellow;
            price.BorderColor = Color.Yellow;
            chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Yellow;
            chart1.ChartAreas[0].AxisX.LineColor = Color.Yellow;
            chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Yellow;
            chart1.ChartAreas[0].AxisY.LineColor = Color.Yellow;
            chart1.ChartAreas[0].AxisX.MajorTickMark.LineColor = Color.Yellow;
            chart1.ChartAreas[0].AxisY.MajorTickMark.LineColor = Color.Yellow;
            chart1.ChartAreas[0].AxisY.MinorTickMark.LineColor = Color.Yellow;
            chart1.ChartAreas[0].AxisX.MinorTickMark.LineColor = Color.Yellow;
            chart1.ChartAreas[0].AxisY.MajorTickMark.Size = 2;
            chart1.ChartAreas[0].AxisY.MinorTickMark.Size = 1;
            chart1.ChartAreas[0].AxisX.MajorTickMark.Size = 1;
            chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = 50;

            //enable user to zoom selected part of the graph
            if (this.ChartControl.Online)
            {
                chartArea.CursorX.IsUserEnabled = false;
                chartArea.CursorX.IsUserSelectionEnabled = false;
            }
            else
            {
                chartArea.CursorX.IsUserEnabled = true;
                chartArea.CursorX.IsUserSelectionEnabled = true;
            }

            chartArea.AxisX.ScrollBar.IsPositionedInside = false;

            chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
            chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;

            price.IsXValueIndexed = true;
            line.IsXValueIndexed = true;
            #endregion

            #region displaying price chart
            for (int i = 0; i < chartSource.Count; i++)
            {
                Candle curCandle = (Candle)chartSource[i];
                if (i == chartSource.Count - 1) chartControl.LastCandleTime = curCandle.DateTime;
                if ((curCandle.DateTime > chartControl.HistoryFrom) && (curCandle.DateTime < chartControl.HistoryTo.AddDays(1)))
                    price.Points.AddXY(curCandle.DateTime, curCandle.High, curCandle.Low, curCandle.Open, curCandle.Close);
            }
            #endregion

            #region displaying moving averages
            try
            {
                if (this.ChartControl.MovingAverages[0].IsShown)
                {
                    Series ma1 = new Series("ma1");
                    ma1.Name = "ma1";
                    chart1.Series.Add(ma1);
                    ma1.IsXValueIndexed = true;
                    chart1.Series["ma1"].ChartType = SeriesChartType.Line;
                    ma1.Color = ChartControl.MovingAverages[0].Color;
                    ma1.BorderWidth = 2;

                    chart1.DataManipulator.FinancialFormula(
                        ChartControl.MovingAverages[0].Type,
                        ChartControl.MovingAverages[0].Period.ToString(),
                        ChartControl.MovingAverages[0].Price, "ma1:Y");

                    for (int i = 0; i < ChartControl.MovingAverages[0].Period - 1; i++)
                        ma1.Points.InsertXY(i, price.Points[i].XValue, price.Points[i].YValues[2]);
                }

                if (this.ChartControl.MovingAverages[1].IsShown == true)
                {
                    Series ma2 = new Series("ma2");
                    ma2.Name = "ma2";
                    chart1.Series.Add(ma2);
                    ma2.IsXValueIndexed = true;
                    chart1.Series["ma2"].ChartType = SeriesChartType.Line;
                    ma2.Color = ChartControl.MovingAverages[1].Color;
                    ma2.BorderWidth = 2;

                    chart1.DataManipulator.FinancialFormula(
                        ChartControl.MovingAverages[1].Type,
                        ChartControl.MovingAverages[1].Period.ToString(),
                        ChartControl.MovingAverages[1].Price, "ma2:Y");

                    for (int i = 0; i < ChartControl.MovingAverages[1].Period - 1; i++)
                        ma2.Points.InsertXY(i, price.Points[i].XValue, price.Points[i].YValues[2]);
                }

                if (this.ChartControl.MovingAverages[2].IsShown == true)
                {
                    Series ma3 = new Series("ma3");
                    ma3.Name = "ma3";
                    chart1.Series.Add(ma3);
                    ma3.IsXValueIndexed = true;
                    chart1.Series["ma3"].ChartType = SeriesChartType.Line;
                    ma3.Color = ChartControl.MovingAverages[2].Color;
                    ma3.BorderWidth = 2;

                    chart1.DataManipulator.FinancialFormula(
                        ChartControl.MovingAverages[2].Type,
                        ChartControl.MovingAverages[2].Period.ToString(),
                        ChartControl.MovingAverages[2].Price, "ma3:Y");

                    for (int i = 0; i < ChartControl.MovingAverages[2].Period - 1; i++)
                        ma3.Points.InsertXY(i, price.Points[i].XValue, price.Points[i].YValues[2]);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion

            #region displaying last price line
            if (chartControl.ShowLastPrice)
            {
                //this loop adds line which represents last price
                for (int i = 0; i < price.Points.Count; i++)
                    line.Points.AddXY(price.Points[i].XValue, price.Points[price.Points.Count - 1].YValues[3]);

                //displaying lastprice label
                if (price.Points.Count > 0)
                {
                    line.Points[line.Points.Count - 1].IsValueShownAsLabel = true;
                    line.Points[line.Points.Count - 1].LabelBackColor = Color.Red;
                    line.SmartLabelStyle.Enabled = true;
                }
            }
            #endregion

            #region displaying titles
            try
            {
                DataPoint dp = price.Points[price.Points.Count - 1];

                foreach (Title title in chart1.Titles)
                {
                    if (title.Name == "close") title.Text = "close " + dp.YValues[3];
                    if (title.Name == "open") title.Text = "open " + dp.YValues[2];
                    if (title.Name == "high") title.Text = "high " + dp.YValues[0];
                    if (title.Name == "low") title.Text = "low " + dp.YValues[1];
                    String dt = DateTime.FromOADate(dp.XValue).ToShortTimeString();
                    if (title.Name == "time") title.Text = dt;
                    dt = DateTime.FromOADate(dp.XValue).ToShortDateString();
                    if (title.Name == "date") title.Text = dt;
                }
            }
            catch { };
            #endregion
        }
Exemple #3
0
 private void MenuItemClickHandler(object sender, EventArgs e)
 {
     ChartControl chartControl = new ChartControl();
     ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
     chartControl.Symbol = clickedItem.Text;
     frm_chart newMDIchild = new frm_chart(chartControl);
     newMDIchild.MdiParent = this;
     newMDIchild.Show();
 }
Exemple #4
0
 public frm_chart(ChartControl cc)
 {
     this.ChartControl = cc;
     InitializeComponent();
 }
Exemple #5
0
        private void frm_mainForm_Load(object sender, EventArgs e)
        {
            BuildMenuItems();
            this.Text = User.curName + ", " + User.curUsername;

            toolStripStatusLabel_date.Text = DateTime.Now.ToLongDateString();
            toolStripStatusLabel_connection.Text = "Not connected";
            toolStripStatusLabel_connection.Image = Properties.Resources.conLOST;
            isConnected = false;

            ArrayList quoteList = DataBase.getUsersQuoteList(User.curUsername);
            foreach (String quote in quoteList)
            {
                Quotes.Add(quote, new Candle());
            }

            frm_LiveQuotes newMDIchild = new frm_LiveQuotes();
            newMDIchild.MdiParent = this;
            newMDIchild.Show();

            frm_LiveNews newMDIchild2 = new frm_LiveNews();
            newMDIchild2.MdiParent = this;
            newMDIchild2.Show();

            frm_Alerts newMDIchild3 = new frm_Alerts();
            newMDIchild3.MdiParent = this;
            newMDIchild3.Show();

            alertsToolStripMenuItem.Enabled = false;
            liveQuotesToolStripMenuItem.Enabled = false;
            newsToolStripMenuItem.Enabled = false;

            ArrayList DefaultChartList = DataBase.getDefaultChartList();

            foreach (String symbol in DefaultChartList)
            {
                ChartControl chartControl = new ChartControl();
                chartControl.Symbol = symbol;
                frm_chart newMDIchild4 = new frm_chart(chartControl);
                newMDIchild4.MdiParent = this;
                newMDIchild4.Show();
            }

            this.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical);
        }