private void GenerateData()
        {
            WebExamplesUtilities.GenerateOHLCData(m_Stock, 100, 200, new NRange1DD(50, 350));

            double min = (double)m_Stock.LowValues[m_Stock.LowValues.FindMinValue()];
            double max = (double)m_Stock.HighValues[m_Stock.HighValues.FindMaxValue()];

            m_MinIndicator.Value = min;
            m_MaxIndicator.Value = max;

            int    count = m_Stock.CloseValues.Count;
            double sum   = 0;

            for (int i = 0; i < count; i++)
            {
                sum += (double)m_Stock.CloseValues[i];
            }

            if (count > 0)
            {
                m_AvgIndicator.Value = sum / count;
            }
            else
            {
                m_AvgIndicator.Value = 0;
            }
        }
        private void GenerateData(NStockSeries stock)
        {
            const double initialPrice = 100;
            const int    numDataPoits = 50;

            WebExamplesUtilities.GenerateOHLCData(stock, initialPrice, numDataPoits);
            FillStockDates(stock, numDataPoits, new DateTime(2010, 1, 11));
        }
Example #3
0
        private void GenerateData(NStockSeries stock, NAreaSeries volume, NLineSeries line)
        {
            WebExamplesUtilities.GenerateOHLCData(stock, prevCloseValue, numDataPoits);
            FillStockDates(stock, numDataPoits, new DateTime(2010, 1, 11));
            GenerateVolumeData(volume, prevVolumeValue, numDataPoits);

            volume.XValues.Clear();
            volume.XValues.AddRange(stock.XValues);

            line.XValues.Clear();
            line.XValues.AddRange(stock.XValues);
        }
        private void GenerateData(DateTime dtStart, DateTime dtEnd, NDateTimeSpan span)
        {
            long count = span.GetSpanCountInRange(new NDateTimeRange(dtStart, dtEnd));

            WebExamplesUtilities.GenerateOHLCData(m_Stock, 100, (int)count);
            m_Stock.XValues.Clear();

            DateTime dtNow = dtStart;

            for (int i = 0; i < m_Stock.Values.Count; i++)
            {
                m_Stock.XValues.Add(dtNow.ToOADate());
                dtNow = span.Add(dtNow);
            }
        }
        private void GenerateData(DateTime dtStart, DateTime dtEnd, NDateTimeSpan span)
        {
            long count = span.GetSpanCountInRange(new NDateTimeRange(dtStart, dtEnd));

            WebExamplesUtilities.GenerateOHLCData(m_Stock, 100, (int)count);
            m_Stock.XValues.Clear();

            DateTime dtNow = dtStart;

            for (int i = 0; i < m_Stock.Values.Count; i++)
            {
                m_Stock.XValues.Add(dtNow.ToOADate());
                dtNow = span.Add(dtNow);
            }

            m_Chart.Axis(StandardAxis.PrimaryX).PagingView.Enabled = false;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CandleStyleDropDownList.Items.Add("Candle");
                CandleStyleDropDownList.Items.Add("Stick");
                CandleStyleDropDownList.SelectedIndex = 0;
            }

            const int nNumberOfWeeks  = 20;
            const int nWorkDaysInWeek = 5;
            const int nTotalWorkDays  = nNumberOfWeeks * nWorkDaysInWeek;

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set chart title
            NLabel title = nChartControl1.Labels.AddHeader("Financial Chart");

            title.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            title.ContentAlignment           = ContentAlignment.BottomCenter;
            title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            // setup chart
            NChart chart = nChartControl1.Charts[0];

            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(new NLength(5, NRelativeUnit.ParentPercentage), new NLength(12, NRelativeUnit.ParentPercentage));
            chart.Size       = new NSizeL(new NLength(90, NRelativeUnit.ParentPercentage), new NLength(84, NRelativeUnit.ParentPercentage));
            chart.Height     = 30;

            // setup y axis
            NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;

            scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            scaleY.MajorGridStyle.LineStyle.Color   = Color.Gray;
            scaleY.MajorGridStyle.ShowAtWalls       = new ChartWallType[] { ChartWallType.Back };

            // add interlaced stripe
            NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1);

            stripStyle.Interlaced  = true;
            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleY.StripStyles.Add(stripStyle);

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // create a line series for the simple moving average
            NLineSeries lineSMA = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineSMA.Name = "SMA(20)";
            lineSMA.Legend.TextStyle.FontStyle.EmSize = new NLength(8, NGraphicsUnit.Point);
            lineSMA.DataLabelStyle.Visible            = false;
            lineSMA.BorderStyle.Color = Color.DarkOrange;
            lineSMA.UseXValues        = true;

            // create the stock series
            NStockSeries stock = (NStockSeries)chart.Series.Add(SeriesType.Stock);

            stock.Name                   = "Stock Data";
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Bar;
            stock.CandleWidth            = new NLength(2, NGraphicsUnit.Point);
            stock.InflateMargins         = true;
            stock.UseXValues             = true;
            stock.UpFillStyle            = new NColorFillStyle(Green);
            stock.UpStrokeStyle.Color    = Color.Black;
            stock.DownFillStyle          = new NColorFillStyle(DarkOrange);
            stock.DownStrokeStyle.Color  = Color.Black;

            // add the bollinger bands as high low area
            NHighLowSeries highLow = (NHighLowSeries)chart.Series.Add(SeriesType.HighLow);

            highLow.Name = "BB(20, 2)";
            highLow.Legend.TextStyle.FontStyle.EmSize = new NLength(8, NGraphicsUnit.Point);
            highLow.DataLabelStyle.Visible            = false;
            highLow.HighFillStyle         = new NColorFillStyle(Color.FromArgb(80, 130, 134, 168));
            highLow.HighBorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel);
            highLow.UseXValues            = true;

            // generate some stock data
            WebExamplesUtilities.GenerateOHLCData(stock, 400, nTotalWorkDays + 20);
            FillStockDates(stock, nTotalWorkDays + 20);

            // create a function calculator
            NFunctionCalculator fc = new NFunctionCalculator();

            stock.CloseValues.Name = "close";
            fc.Arguments.Add(stock.CloseValues);

            // calculate the bollinger bands
            fc.Expression      = "BOLLINGER(close; 20; 2)";
            highLow.HighValues = fc.Calculate();

            fc.Expression     = "BOLLINGER(close; 20; -2)";
            highLow.LowValues = fc.Calculate();

            // calculate the simple moving average
            fc.Expression  = "SMA(close; 20)";
            lineSMA.Values = fc.Calculate();

            // remove data that won't be charted
            stock.HighValues.RemoveRange(0, 20);
            stock.LowValues.RemoveRange(0, 20);
            stock.OpenValues.RemoveRange(0, 20);
            stock.CloseValues.RemoveRange(0, 20);
            stock.XValues.RemoveRange(0, 20);

            highLow.HighValues.RemoveRange(0, 20);
            highLow.LowValues.RemoveRange(0, 20);
            highLow.XValues = (NDataSeriesDouble)stock.XValues.Clone();

            lineSMA.Values.RemoveRange(0, 20);
            lineSMA.XValues = (NDataSeriesDouble)stock.XValues.Clone();

            stock.CandleStyle = (CandleStyle)CandleStyleDropDownList.SelectedIndex;
            lineSMA.Visible   = SMACheckBox.Checked;
            highLow.Visible   = SBBCheckBox.Checked;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            NStockSeries stock;

            if (!IsPostBack)
            {
                // set a chart title
                nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

                NLabel title = nChartControl1.Labels.AddHeader("Stock Data Grouping");
                title.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
                title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;

                // no legend
                nChartControl1.Legends.Clear();

                // setup chart
                NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
                chart.BoundsMode = BoundsMode.Stretch;

                NRangeSelection rs = new NRangeSelection();
                rs.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
                chart.RangeSelections.Add(rs);

                // setup X axis
                NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();
                scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
                scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
                scaleX.FirstRow.UseGridStyle            = true;
                scaleX.FirstRow.InnerTickStyle.Visible  = false;
                scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
                scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
                scaleX.SecondRow.UseGridStyle           = true;
                scaleX.SecondRow.InnerTickStyle.Visible = false;
                scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
                scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
                scaleX.ThirdRow.UseGridStyle            = true;
                scaleX.ThirdRow.InnerTickStyle.Visible  = false;

                // calendar
                NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);
                wdr.Saturday = false;
                wdr.Sunday   = false;
                scaleX.Calendar.Rules.Add(wdr);
                scaleX.EnableCalendar = true;

                // set configurator
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;
                chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;

                // setup Y axis
                NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;
                scaleY.OuterMajorTickStyle.Length  = new NLength(3, NGraphicsUnit.Point);
                scaleY.InnerMajorTickStyle.Visible = false;

                NFillStyle       stripFill  = new NColorFillStyle(Color.FromArgb(234, 233, 237));
                NScaleStripStyle stripStyle = new NScaleStripStyle(stripFill, null, true, 1, 0, 1, 1);
                stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
                stripStyle.Interlaced  = true;
                scaleY.StripStyles.Add(stripStyle);

                // setup stock series
                stock = (NStockSeries)chart.Series.Add(SeriesType.Stock);
                stock.DataLabelStyle.Visible   = false;
                stock.UpFillStyle              = new NColorFillStyle(Color.White);
                stock.UpStrokeStyle.Color      = Color.Black;
                stock.DownFillStyle            = new NColorFillStyle(Color.Crimson);
                stock.DownStrokeStyle.Color    = Color.Crimson;
                stock.HighLowStrokeStyle.Color = Color.Black;
                stock.CandleWidth              = new NLength(1.2f, NRelativeUnit.ParentPercentage);
                stock.UseXValues            = true;
                stock.InflateMargins        = true;
                stock.DataLabelStyle.Format = "open - <open>\r\nclose - <close>";

                // add some stock items
                const int numDataPoints = 1000;
                WebExamplesUtilities.GenerateOHLCData(stock, 100.0, numDataPoints, new NRange1DD(60, 140));
                FillStockDates(stock, numDataPoints, DateTime.Now - new TimeSpan((int)(numDataPoints * 1.2), 0, 0, 0));

                // apply layout
                ApplyLayoutTemplate(0, nChartControl1, chart, title, null);

                // update form controls
                CustomDateTimeSpanDropDownList.Items.Add("1 Week");
                CustomDateTimeSpanDropDownList.Items.Add("2 Weeks");
                CustomDateTimeSpanDropDownList.Items.Add("1 Month");
                CustomDateTimeSpanDropDownList.Items.Add("3 Months");

                WebExamplesUtilities.FillComboWithEnumNames(GroupingModeDropDownList, typeof(StockGroupingMode));

                CustomDateTimeSpanDropDownList.SelectedIndex = 2;
                GroupingModeDropDownList.SelectedIndex       = (int)StockGroupingMode.SynchronizeWithMajorTick;

                WebExamplesUtilities.FillComboWithPercents(GroupPercendWidthDropDownList, 10);
                GroupPercendWidthDropDownList.SelectedIndex = 2;

                WebExamplesUtilities.FillComboWithValues(MinGroupDistanceDropDownList, 2, 20, 2);
                MinGroupDistanceDropDownList.SelectedIndex = 2;
            }
            else
            {
                stock = (NStockSeries)nChartControl1.Charts[0].Series[0];
            }

            MinGroupDistanceDropDownList.Enabled   = false;
            CustomDateTimeSpanDropDownList.Enabled = false;
            GroupPercendWidthDropDownList.Enabled  = true;

            switch (GroupingModeDropDownList.SelectedIndex)
            {
            case (int)StockGroupingMode.None:
                stock.GroupingMode = StockGroupingMode.None;
                GroupPercendWidthDropDownList.Enabled = false;
                break;

            case (int)StockGroupingMode.AutoDateTimeSpan:
                stock.GroupingMode = StockGroupingMode.AutoDateTimeSpan;
                MinGroupDistanceDropDownList.Enabled = true;
                break;

            case (int)StockGroupingMode.CustomDateTimeSpan:
                stock.GroupingMode = StockGroupingMode.CustomDateTimeSpan;
                CustomDateTimeSpanDropDownList.Enabled = true;
                break;

            case (int)StockGroupingMode.SynchronizeWithMajorTick:
                stock.GroupingMode = StockGroupingMode.SynchronizeWithMajorTick;
                break;

            default:
                break;
            }

            stock.MinAutoGroupLength = new NLength((float)MinGroupDistanceDropDownList.SelectedIndex * 2 + 2, NGraphicsUnit.Point);

            switch (CustomDateTimeSpanDropDownList.SelectedIndex)
            {
            case 0:                     // 1 Week
                stock.CustomGroupStep = new NDateTimeSpan(1, NDateTimeUnit.Week);
                break;

            case 1:                     // 2 Weeks
                stock.CustomGroupStep = new NDateTimeSpan(2, NDateTimeUnit.Week);
                break;

            case 2:                     // 1 Month
                stock.CustomGroupStep = new NDateTimeSpan(1, NDateTimeUnit.Month);
                break;

            case 3:                     // 3 Months
                stock.CustomGroupStep = new NDateTimeSpan(3, NDateTimeUnit.Month);
                break;
            }

            stock.GroupPercentWidth = (float)GroupPercendWidthDropDownList.SelectedIndex * 10;
        }