예제 #1
0
        private void SetupStockChart(NCartesianChart chart)
        {
            // setup Y axis
            NAxis axisY = chart.Axis(StandardAxis.PrimaryY);

            axisY.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 40, 100);

            NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)axisY.ScaleConfigurator;

            scaleY.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleY.InnerMajorTickStyle.Length = new NLength(0);

            Color color1 = Color.FromArgb(100, 100, 150);
            Color color2 = Color.FromArgb(200, 120, 120);

            // setup the stock series
            m_Stock                          = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.Name                     = "Price";
            m_Stock.Legend.Mode              = SeriesLegendMode.None;
            m_Stock.DataLabelStyle.Visible   = false;
            m_Stock.CandleStyle              = CandleStyle.Bar;
            m_Stock.HighLowStrokeStyle.Color = color1;
            m_Stock.UpStrokeStyle.Color      = color1;
            m_Stock.DownStrokeStyle.Color    = color2;
            m_Stock.UpFillStyle              = new NColorFillStyle(color1);
            m_Stock.DownFillStyle            = new NColorFillStyle(color2);
            m_Stock.OpenValues.Name          = "open";
            m_Stock.HighValues.Name          = "high";
            m_Stock.LowValues.Name           = "low";
            m_Stock.CloseValues.Name         = "close";
            m_Stock.CandleWidth              = new NLength(0.4f, NRelativeUnit.ParentPercentage);
            m_Stock.UseXValues               = true;
            m_Stock.InflateMargins           = true;
        }
        private void UpdateFunctions(NStockSeries stock, NLineSeries lineDIPos, NLineSeries lineDINeg, NLineSeries lineADX, NFunctionCalculator calc)
        {
            StringBuilder sb      = new StringBuilder();
            int           nPeriod = PeriodDropDownList.SelectedIndex * 10;

            sb.AppendFormat("DI_POS(close; high; low; {0})", nPeriod);
            calc.Expression      = sb.ToString();
            lineDIPos.Values     = calc.Calculate();
            lineDIPos.XValues    = (NDataSeriesDouble)stock.XValues.Clone();
            lineDIPos.UseXValues = true;
            PosDITextBox.Text    = calc.Expression;

            sb.Remove(0, sb.Length);
            sb.AppendFormat("DI_NEG(close; high; low; {0})", nPeriod);
            calc.Expression      = sb.ToString();
            lineDINeg.Values     = calc.Calculate();
            lineDINeg.XValues    = (NDataSeriesDouble)stock.XValues.Clone();
            lineDINeg.UseXValues = true;
            NegDITextBox.Text    = calc.Expression;

            sb.Remove(0, sb.Length);
            sb.AppendFormat("MMA(DMI(close; high; low; {0}); {0})", nPeriod);
            calc.Expression    = sb.ToString();
            lineADX.Values     = calc.Calculate();
            lineADX.XValues    = (NDataSeriesDouble)stock.XValues.Clone();
            lineADX.UseXValues = true;
            ADXTextBox.Text    = calc.Expression;
        }
예제 #3
0
        private void GenerateData(NStockSeries stock)
        {
            GenerateOHLCData(stock, 200);

            DateTime dt = new DateTime(2006, 5, 15);

            for (int i = 0; i < 200; i++)
            {
                stock.XValues.Add(dt.ToOADate());

                dt += new TimeSpan(1, 0, 0, 0);
            }

            NMarkerStyle ms1 = new NMarkerStyle();

            ms1.Visible            = true;
            ms1.PointShape         = PointShape.Ellipse;
            ms1.FillStyle          = new NColorFillStyle(Color.Red);
            ms1.Width              = new NLength(0.4f, NRelativeUnit.ParentPercentage);;
            ms1.Height             = new NLength(0.4f, NRelativeUnit.ParentPercentage);;
            ms1.VertAlign          = VertAlign.Bottom;
            stock.MarkerStyles[20] = ms1;

            NMarkerStyle ms2 = new NMarkerStyle();

            ms2.Visible            = true;
            ms2.PointShape         = PointShape.Ellipse;
            ms2.FillStyle          = new NColorFillStyle(Color.Red);
            ms2.Width              = new NLength(0.4f, NRelativeUnit.ParentPercentage);;
            ms2.Height             = new NLength(0.4f, NRelativeUnit.ParentPercentage);;
            ms2.VertAlign          = VertAlign.Top;
            stock.MarkerStyles[80] = ms2;
        }
예제 #4
0
        private void SetupStockChart(NCartesianChart chart)
        {
            // setup Y axis
            NLinearScaleConfigurator scaleY = new NLinearScaleConfigurator();

            scaleY.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleY.InnerMajorTickStyle.Length = new NLength(0);

            NAxis axisY = chart.Axis(StandardAxis.PrimaryY);

            axisY.ScaleConfigurator = scaleY;

            // setup the stock series
            m_Stock                        = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.Name                   = "Price";
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Stick;

            m_Stock.UpStrokeStyle.Color = Color.RoyalBlue;
            m_Stock.OpenValues.Name     = "open";
            m_Stock.HighValues.Name     = "high";
            m_Stock.LowValues.Name      = "low";
            m_Stock.CloseValues.Name    = "close";
            m_Stock.CandleWidth         = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            m_Stock.UseXValues          = true;
            m_Stock.InflateMargins      = true;
        }
예제 #5
0
            void INCustomRequestCallback.OnCustomRequestCallback(NAspNetThinWebControl control, NRequestContext context, string argument)
            {
                NThinChartControl chartControl = (NThinChartControl)control;

                // make sure chart is recalculated
                chartControl.RecalcLayout();

                NChart       chart = chartControl.Charts[0];
                NStockSeries stock = (NStockSeries)chart.Series[0];

                switch (argument)
                {
                case "LastWeek":
                {
                    DateTime dt = DateTime.FromOADate((double)stock.XValues[stock.XValues.Count - 1]);
                    chart.Axis(StandardAxis.PrimaryX).PagingView.ZoomIn(new NRange1DD(dt.AddDays(-7).ToOADate(), dt.ToOADate()), 0.00001);
                }
                break;

                case "LastMonth":
                {
                    DateTime dt = DateTime.FromOADate((double)stock.XValues[stock.XValues.Count - 1]);
                    chart.Axis(StandardAxis.PrimaryX).PagingView.ZoomIn(new NRange1DD(dt.AddMonths(-1).ToOADate(), dt.ToOADate()), 0.00001);
                }
                break;

                case "LastYear":
                    chart.Axis(StandardAxis.PrimaryX).PagingView.Enabled = false;
                    break;
                }

                chartControl.Update();
            }
        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));
        }
예제 #7
0
        private NPointD GetLowPointFromStock(NStockSeries stock, int dataPointIndex)
        {
            NPointD result;

            result.X = (double)stock.XValues[dataPointIndex];
            result.Y = (double)stock.LowValues[dataPointIndex];

            return(result);
        }
예제 #8
0
        private void BuildExpression(NStockSeries stock, NSeries line)
        {
            NDataSeriesDouble arg;
            StringBuilder     sb = new StringBuilder();
            int nPeriod          = PeriodDropDownList.SelectedIndex;

            arg = stock.OpenValues;

            switch (ApplyFunctionToDropDownList.SelectedIndex)
            {
            case 0:
                arg = stock.OpenValues;
                break;

            case 1:
                arg = stock.HighValues;
                break;

            case 2:
                arg = stock.LowValues;
                break;

            case 3:
                arg = stock.CloseValues;
                break;
            }

            switch (FunctionDropDownList.SelectedIndex)
            {
            case 0:
                sb.AppendFormat("SMA({0}; {1})", arg.Name, nPeriod);
                line.Name = "Simple Moving Average";
                break;

            case 1:
                sb.AppendFormat("WMA({0}; {1})", arg.Name, nPeriod);
                line.Name = "Weighted Moving Average";
                break;

            case 2:
                sb.AppendFormat("EMA({0}; {1})", arg.Name, nPeriod);
                line.Name = "Exponential Moving Average";
                break;

            case 3:
                sb.AppendFormat("MMA({0}; {1})", arg.Name, nPeriod);
                line.Name = "Modified Moving Average";
                break;
            }

            nFunction.Arguments.Clear();
            nFunction.Arguments.Add(arg);
            nFunction.Expression = sb.ToString();

            // form controls
            ExpressionTextBox.Text = nFunction.Expression;
        }
예제 #9
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel header = nChartControl1.Labels.AddFooter("Volume Indicators");

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

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

            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(new NLength(5, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage));
            chart.Size       = new NSizeL(new NLength(90, NRelativeUnit.ParentPercentage), new NLength(80, NRelativeUnit.ParentPercentage));

            SetupTimeScale(chart.Axis(StandardAxis.PrimaryX));
            NStockSeries stock  = SetupStockChart(chart);
            NAreaSeries  volume = SetupVolumeChart(chart);
            NLineSeries  line   = SetupIndicatorChart(chart);

            // form controls
            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Accumulation Distribution");
                FunctionDropDownList.Items.Add("Chaikin Oscillator");
                FunctionDropDownList.Items.Add("Ease of Movement");
                FunctionDropDownList.Items.Add("Money Flow Index");
                FunctionDropDownList.Items.Add("Negative Volume Index");
                FunctionDropDownList.Items.Add("On Balance Volume");
                FunctionDropDownList.Items.Add("Positive Volume Index");
                FunctionDropDownList.Items.Add("Price and Volume Trend");

                FunctionDropDownList.SelectedIndex = 0;

                WebExamplesUtilities.FillComboWithValues(ParameterDropDownList, 0, 100, 10);
                ParameterDropDownList.SelectedIndex = 1;
            }

            NFunctionCalculator function = new NFunctionCalculator();

            // generate data
            GenerateData(stock, volume, line);
            GenerateVolumeData(volume, prevVolumeValue, numDataPoits);

            UpdateFunction(stock, volume, line, function);

            line.Values    = function.Calculate();
            line.XValues   = (NDataSeriesDouble)stock.XValues.Clone();
            volume.XValues = (NDataSeriesDouble)stock.XValues.Clone();
        }
예제 #10
0
        private void FinancialMarkerCombo_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            NChart       chart     = nChartControl1.Charts[0];
            NStockSeries stock     = (NStockSeries)chart.Series[chart.Series.Count - 1];
            NLineStudy   lineStudy = null;
            Color        lineColor = Color.Crimson;

            switch (FinancialMarkerCombo.SelectedIndex)
            {
            case 0:
                lineStudy = new NFibonacciArcs();
                TrendlineModeCombo.Enabled = false;
                break;

            case 1:
                lineStudy = new NFibonacciFans();
                TrendlineModeCombo.Enabled = true;
                break;

            case 2:
                lineStudy = new NFibonacciRetracements();
                ((NFibonacciRetracements)lineStudy).RetracementsStrokeStyle.Color = lineColor;
                TrendlineModeCombo.Enabled = true;
                break;

            case 3:
                lineStudy = new NSpeedResistanceLines();
                TrendlineModeCombo.Enabled = true;
                break;

            case 4:
                lineStudy = new NQuadrantLines();
                ((NQuadrantLines)lineStudy).CentralLineStrokeStyle.Color = lineColor;
                TrendlineModeCombo.Enabled = false;
                break;

            case 5:
                lineStudy = new NTrendLine();
                TrendlineModeCombo.Enabled = true;
                break;

            default:
                return;
            }

            UpdateLineStudyAnchor(stock, lineStudy);

            // set the primary line color
            lineStudy.StrokeStyle.Color = lineColor;

            InsertFinancialMarker(chart, lineStudy);
            SetTextVisibility();
            lineStudy.TrendLineMode = (TrendLineMode)TrendlineModeCombo.SelectedIndex;

            nChartControl1.Refresh();
        }
예제 #11
0
        private void GenerateOHLCData(NStockSeries stock, double dPrevClose)
        {
            double dGrowProbability = 0.0;
            double open, high, low, close;

            stock.ClearDataPoints();
            Random random = new Random();

            for (int nIndex = 0; nIndex < 200; nIndex++)
            {
                open = dPrevClose;

                if (dPrevClose < 25)
                {
                    dGrowProbability = 1.0;
                }
                else
                {
                    if (((nIndex >= 20) && (nIndex <= 80)) || ((nIndex >= 120) && (nIndex <= 180)))
                    {
                        dGrowProbability = 0.75;
                    }
                    else
                    {
                        dGrowProbability = 0.25;
                    }
                }

                if (Random.NextDouble() < dGrowProbability)
                {
                    // upward price change
                    close = open + (2 + (Random.NextDouble() * 20));
                    high  = close + (Random.NextDouble() * 10);
                    low   = open - (Random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (Random.NextDouble() * 20));
                    high  = open + (Random.NextDouble() * 10);
                    low   = close - (Random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                stock.OpenValues.Add(open);
                stock.HighValues.Add(high);
                stock.LowValues.Add(low);
                stock.CloseValues.Add(close);
            }
        }
예제 #12
0
        internal void GenerateOHLCData(NStockSeries s, double dPrevClose, int historicalDays)
        {
            DateTime  now = DateTime.Now;
            NTimeline timeline = m_Calendar.CreateTimeline(new NDateTimeRange(now, now + new TimeSpan(360, 0, 0, 0, 0)));
            double    open, high, low, close;

            s.ClearDataPoints();

            int numberOfWorkingDays = historicalDays;

            if (ZoomModeDropDownList.SelectedIndex == 0)
            {
                numberOfWorkingDays += 7;
            }
            else
            {
                numberOfWorkingDays += 31;
            }

            for (; numberOfWorkingDays > 0; numberOfWorkingDays--)
            {
                open = dPrevClose;

                if (dPrevClose < 25 || Random.NextDouble() > 0.5)
                {
                    // upward price change
                    close = open + (2 + (Random.NextDouble() * 20));
                    high  = close + (Random.NextDouble() * 10);
                    low   = open - (Random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (Random.NextDouble() * 20));
                    high  = open + (Random.NextDouble() * 10);
                    low   = close - (Random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
                s.XValues.Add(now.ToOADate());

                // advance to next working day
                now = timeline.AddTimeSpan(now, new NDateTimeSpan(1, NDateTimeUnit.Day));
            }
        }
예제 #13
0
        private void GenerateStockData(NStockSeries stock, int count, double dPrevClose)
        {
            DateTime dt = new DateTime(2006, 5, 15);
            double   dGrowProbability = 0.0;
            double   open, high, low, close;

            stock.ClearDataPoints();

            for (int nIndex = 0; nIndex < count; nIndex++)
            {
                open = dPrevClose;

                if ((nIndex % 100) <= 20)
                {
                    // downtrend
                    dGrowProbability = 0.20;
                }
                else
                {
                    // uptrend
                    dGrowProbability = 0.75;
                }

                if (Random.NextDouble() < dGrowProbability)
                {
                    // upward price change
                    close = open + 2 + (Random.NextDouble() * 20);
                    high  = close + (Random.NextDouble() * 10);
                    low   = open - (Random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (Random.NextDouble() * 20));
                    high  = open + (Random.NextDouble() * 10);
                    low   = close - (Random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                stock.OpenValues.Add(open);
                stock.HighValues.Add(high);
                stock.LowValues.Add(low);
                stock.CloseValues.Add(close);
                stock.XValues.Add(dt.ToOADate());

                dt += new TimeSpan(1, 0, 0, 0);
            }
        }
예제 #14
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);
        }
예제 #15
0
        internal void GenerateOHLCData(NStockSeries s, double dPrevClose, int nCount, NRange1DD range)
        {
            double open, high, low, close;

            s.ClearDataPoints();

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                open = dPrevClose;
                bool upward = false;

                if (range.Begin > dPrevClose)
                {
                    upward = true;
                }
                else if (range.End < dPrevClose)
                {
                    upward = false;
                }
                else
                {
                    upward = Random.NextDouble() > 0.5;
                }

                if (upward)
                {
                    // upward price change
                    close = open + (2 + (Random.NextDouble() * 20));
                    high  = close + (Random.NextDouble() * 10);
                    low   = open - (Random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (Random.NextDouble() * 20));
                    high  = open + (Random.NextDouble() * 10);
                    low   = close - (Random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
            }
        }
예제 #16
0
        private void SetupStockChart(NCartesianChart chart)
        {
            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.LightModel.EnableLighting         = false;
            chart.Axis(StandardAxis.Depth).Visible  = false;
            chart.Wall(ChartWallType.Floor).Visible = false;
            chart.Wall(ChartWallType.Left).Visible  = false;
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(10, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(50, NRelativeUnit.ParentPercentage));

            // setup X axis
            NAxis axis = chart.Axis(StandardAxis.PrimaryX);
            NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)axis.ScaleConfigurator;

            ordinalScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, false);
            ordinalScale.InnerMajorTickStyle.Length = new NLength(0);

            // setup Y axis
            axis = chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScale = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            linearScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, false);
            linearScale.InnerMajorTickStyle.Length = new NLength(0);

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

            stripStyle.Interlaced = true;
            stripStyle.SetShowAtWall(ChartWallType.Back, true);
            linearScale.StripStyles.Add(stripStyle);

            // setup the stock series
            m_Stock                        = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.Name                   = "Price";
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Stick;
            m_Stock.UpStrokeStyle.Color    = Color.RoyalBlue;
            m_Stock.OpenValues.Name        = "open";
            m_Stock.HighValues.Name        = "high";
            m_Stock.LowValues.Name         = "low";
            m_Stock.CloseValues.Name       = "close";
            m_Stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
        }
예제 #17
0
        private void CalculateFunctions(NStockSeries stock, NLineSeries lineUpper, NLineSeries lineLower, NLineSeries lineSMA, NFunctionCalculator upperCalculator,
                                        NFunctionCalculator lowerCalculator, NFunctionCalculator SMACalculator)
        {
            lineUpper.Values = upperCalculator.Calculate();
            lineLower.Values = lowerCalculator.Calculate();
            lineSMA.Values   = SMACalculator.Calculate();

            lineUpper.XValues    = (NDataSeriesDouble)stock.XValues.Clone();
            lineUpper.UseXValues = true;
            lineLower.XValues    = (NDataSeriesDouble)stock.XValues.Clone();
            lineLower.UseXValues = true;
            lineSMA.XValues      = (NDataSeriesDouble)stock.XValues.Clone();
            lineSMA.UseXValues   = true;
        }
        private NCartesianChart CreateStockChart()
        {
            NCartesianChart chart = new NCartesianChart();

            chart.DockMode            = PanelDockMode.Top;
            chart.Size                = new NSizeL(new NLength(0), new NLength(55, NRelativeUnit.ParentPercentage));
            chart.Margins             = new NMarginsL(5, 5, 5, 0);
            chart.BackgroundFillStyle = new NColorFillStyle(Color.FromArgb(125, Color.White));
            chart.BoundsMode          = BoundsMode.Stretch;
            chart.Padding             = new NMarginsL(5, 5, 5, 0);

            // setup X axis
            NAxis axis = chart.Axis(StandardAxis.PrimaryX);
            NOrdinalScaleConfigurator ordinalScale = (NOrdinalScaleConfigurator)axis.ScaleConfigurator;

            ordinalScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
            ordinalScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, false);
            ordinalScale.InnerMajorTickStyle.Length = new NLength(0);

            // setup Y axis
            axis = chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScale = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            linearScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, false);
            linearScale.InnerMajorTickStyle.Length = new NLength(0);

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

            stripStyle.Interlaced = true;
            stripStyle.SetShowAtWall(ChartWallType.Back, true);
            linearScale.StripStyles.Add(stripStyle);

            // setup the stock series
            m_Stock                        = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.Name                   = "Price";
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Stick;
            m_Stock.UpStrokeStyle.Color    = Color.RoyalBlue;
            m_Stock.OpenValues.Name        = "open";
            m_Stock.HighValues.Name        = "high";
            m_Stock.LowValues.Name         = "low";
            m_Stock.CloseValues.Name       = "close";
            m_Stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);

            return(chart);
        }
예제 #19
0
        private void ExportToDataTable_Click(object sender, System.EventArgs e)
        {
            NChart chart = nChartControl1.Charts[0];
            NDataSeriesCollection arrSeries = new NDataSeriesCollection();
            string sTableName = "";

            switch (ChartCombo.SelectedIndex)
            {
            case 0:                     // Bar Chart
                NBarSeries bar = (NBarSeries)chart.Series[0];
                sTableName = "Bar Chart";

                arrSeries.Add(bar.Values, DataSeriesMask.Values);
                arrSeries.Add(bar.Labels, DataSeriesMask.Labels);
                break;

            case 1:                     // Line Chart With X Values
                NLineSeries line = (NLineSeries)chart.Series[0];
                sTableName = "Line Chart";

                arrSeries.Add(line.Values, DataSeriesMask.Values);
                arrSeries.Add(line.XValues, DataSeriesMask.XValues);
                arrSeries.Add(line.Labels, DataSeriesMask.Labels);
                break;

            case 2:                     // Pie Chart with detachments
                NPieSeries pie = (NPieSeries)chart.Series[0];
                sTableName = "Pie Chart";

                arrSeries.Add(pie.Values, DataSeriesMask.Values);
                arrSeries.Add(pie.Detachments, DataSeriesMask.PieDetachments);
                arrSeries.Add(pie.Labels, DataSeriesMask.Labels);
                break;

            case 3:                     // Open - High - Low - Close
                NStockSeries stock = (NStockSeries)chart.Series[0];
                sTableName = "Stock Chart";

                arrSeries.Add(stock.OpenValues, DataSeriesMask.StockOpenValues);
                arrSeries.Add(stock.HighValues, DataSeriesMask.StockHighValues);
                arrSeries.Add(stock.LowValues, DataSeriesMask.StockLowValues);
                arrSeries.Add(stock.CloseValues, DataSeriesMask.StockCloseValues);
                break;
            }

            dataView1.Table = arrSeries.ExportToDataTable(sTableName);

            nChartControl1.Refresh();
        }
예제 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override NWidget CreateExampleContent()
        {
            NChartView chartView = CreateCartesianChartView();

            // configure title
            chartView.Surface.Titles[0].Text = "Value Timeline Scale";

            // configure chart
            m_Chart = (NCartesianChart)chartView.Surface.Charts[0];

            // configure axes
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);

            // setup X axis
            NCartesianAxis axis = m_Chart.Axes[ENCartesianAxis.PrimaryX];

            m_TimeLineScale = new NValueTimelineScale();
            axis.Scale      = m_TimeLineScale;

            // setup primary Y axis
            axis = m_Chart.Axes[ENCartesianAxis.PrimaryY];
            NLinearScale linearScale = (NLinearScale)axis.Scale;

            // configure ticks and grid lines
            linearScale.MajorGridLines.Stroke   = new NStroke(NColor.LightGray);
            linearScale.InnerMajorTicks.Visible = false;

            // add interlaced stripe
            NScaleStrip strip = new NScaleStrip();

            strip.Fill       = new NColorFill(NColor.Beige);
            strip.Interlaced = true;
            linearScale.Strips.Add(strip);

            // Setup the stock series
            m_Stock = new NStockSeries();
            m_Chart.Series.Add(m_Stock);

            m_Stock.DataLabelStyle = new NDataLabelStyle(false);
            m_Stock.CandleShape    = ENCandleShape.Stick;
            m_Stock.CandleWidth    = 4;
            m_Stock.UseXValues     = true;

            chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, false));

            OnWeeklyDataButtonClick(null);

            return(chartView);
        }
        private void BuildExpression(NFunctionCalculator nFunction, NStockSeries stock, NSeries line)
        {
            NDataSeriesDouble arg;
            StringBuilder     sb = new StringBuilder();
            int nPeriod          = 10;

            arg = stock.OpenValues;
            arg = stock.OpenValues;

            sb.AppendFormat("SMA({0}; {1})", arg.Name, nPeriod);
            line.Name = "Simple Moving Average";

            nFunction.Arguments.Clear();
            nFunction.Arguments.Add(arg);
            nFunction.Expression = sb.ToString();
        }
예제 #22
0
        private void SetDataToChart(IEnumerable <WeatherData> data)
        {
            IntitChart();
            NChart       chart = nChartControl1.Charts[0];
            NStockSeries stock = (NStockSeries)chart.Series[chart.Series.Count - 1];

            foreach (var d in data)
            {
                stock.OpenValues.Add(d.LowTemp);
                stock.HighValues.Add(d.MaxTemp);
                stock.LowValues.Add(d.LowTemp);
                stock.CloseValues.Add(d.Temp);
                stock.XValues.Add(d.DateTime.ToOADate());
            }
            nChartControl1.Refresh();
        }
예제 #23
0
        protected void FillStockDates(NStockSeries stock, int count, DateTime startDate)
        {
            stock.XValues.Clear();

            DateTime dt = startDate;

            for (int i = 0; i < count;)
            {
                if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday)
                {
                    stock.XValues.Add(dt.ToOADate());
                    i++;
                }

                dt = dt.AddDays(1);
            }
        }
예제 #24
0
        private void GenerateData(NStockSeries s, NWorkCalendar calendar, double dPrevClose, int nCount)
        {
            DateTime  now = DateTime.Now;
            NTimeline timeline = calendar.CreateTimeline(new NDateTimeRange(now, now + new TimeSpan(730, 0, 0, 0, 0)));
            double    open, high, low, close;

            s.ClearDataPoints();

            Random random = new Random();

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                open = dPrevClose;

                if (dPrevClose < 25 || random.NextDouble() > 0.5)
                {
                    // upward price change
                    close = open + (2 + (random.NextDouble() * 20));
                    high  = close + (random.NextDouble() * 10);
                    low   = open - (random.NextDouble() * 10);
                }
                else
                {
                    // downward price change
                    close = open - (2 + (random.NextDouble() * 20));
                    high  = open + (random.NextDouble() * 10);
                    low   = close - (random.NextDouble() * 10);
                }

                if (low < 1)
                {
                    low = 1;
                }

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
                s.XValues.Add(now.ToOADate());

                // advance to next working day
                now = timeline.AddTimeSpan(now, new NDateTimeSpan(1, NDateTimeUnit.Day));
            }
        }
예제 #25
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override NWidget CreateExampleContent()
        {
            NChartView chartView = CreateCartesianChartView();

            // configure title
            chartView.Surface.Titles[0].Text = "Candle Stock";

            // configure chart
            m_Chart = (NCartesianChart)chartView.Surface.Charts[0];

            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

            // setup X axis
            NCartesianAxis axis = m_Chart.Axes[ENCartesianAxis.PrimaryX];

            axis.Scale = new NValueTimelineScale();

            // setup primary Y axis
            axis = m_Chart.Axes[ENCartesianAxis.PrimaryY];
            NLinearScale linearScale = (NLinearScale)axis.Scale;

            // configure ticks and grid lines
            linearScale.MajorGridLines.Stroke   = new NStroke(NColor.LightGray);
            linearScale.InnerMajorTicks.Visible = false;

            // add interlaced stripe
            NScaleStrip strip = new NScaleStrip();

            strip.Fill       = new NColorFill(NColor.Beige);
            strip.Interlaced = true;
            linearScale.Strips.Add(strip);

            // Setup the stock series
            m_Stock = new NStockSeries();
            m_Chart.Series.Add(m_Stock);

            m_Stock.DataLabelStyle = new NDataLabelStyle(false);
            m_Stock.CandleShape    = ENCandleShape.Rectangle;
            m_Stock.CandleWidth    = 4;
            m_Stock.UseXValues     = true;

            GenerateData();

            return(chartView);
        }
예제 #26
0
        private void LoadFromFileButton_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Binary(*.bin)|*.bin|XML(*.xml)|*.xml|All files (*.*)|*.*";

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                NSerializationFilter filter = GetSeriazliationFilter();
                nChartControl1.Serializer.LoadControlStateFromFile(dlg.FileName, (PersistencyFormat)SerializationFormatComboBox.SelectedIndex, filter);

                // update form members
                if (nChartControl1.Charts.Count > 0)
                {
                    m_Chart = nChartControl1.Charts[0];

                    foreach (NSeriesBase series in m_Chart.Series)
                    {
                        if (series is NHighLowSeries)
                        {
                            m_HighLow = (NHighLowSeries)series;
                        }
                        else if (series is NLineSeries)
                        {
                            m_LineSMA = (NLineSeries)series;
                        }
                        else if (series is NStockSeries)
                        {
                            m_Stock = (NStockSeries)series;
                        }
                    }
                }

                nChartControl1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public static void GenerateOHLCData(NStockSeries s, double dPrevClose, int nCount, NRange1DD range)
        {
            double open, high, low, close;

            s.ClearDataPoints();

            for (int nIndex = 0; nIndex < nCount; nIndex++)
            {
                GenerateOHLCDataPoint(dPrevClose, range, out open, out high, out low, out close);

                dPrevClose = close;

                s.OpenValues.Add(open);
                s.HighValues.Add(high);
                s.LowValues.Add(low);
                s.CloseValues.Add(close);
            }
        }
예제 #28
0
        private void UpdateLineStudyAnchor(NStockSeries stock, NLineStudy lineStudy)
        {
            switch (FinancialMarkerCombo.SelectedIndex)
            {
            case 0:                     // Fibonacci Arcs
            case 1:                     // Fibonacci Fans
            case 2:                     // Fibonacci Retracements
            case 3:                     // Speed Resistance Lines
            case 4:                     // Quadrant Lines
                lineStudy.BeginPoint = GetLowPointFromStock(stock, m_nMinIndex1);
                lineStudy.EndPoint   = GetHighPointFromStock(stock, m_nMaxIndex2);
                break;

            case 5:                     // Trend Line
                lineStudy.BeginPoint = GetLowPointFromStock(stock, m_nMinIndex1);
                lineStudy.EndPoint   = GetLowPointFromStock(stock, m_nMaxIndex2);
                break;
            }
        }
        private void CalculateFunction(NStockSeries stock, NLineSeries line)
        {
            StringBuilder sb = new StringBuilder();

            NFunctionCalculator function = new NFunctionCalculator();

            function.Arguments.Clear();

            switch (FunctionDropDownList.SelectedIndex)
            {
            case 0:
                sb.AppendFormat("MEDIANPRICE({0}; {1})", stock.HighValues.Name, stock.LowValues.Name);
                line.Name = "Median Price";
                break;

            case 1:
                sb.AppendFormat("TYPICALPRICE({0}; {1}; {2})", stock.CloseValues.Name, stock.HighValues.Name, stock.LowValues.Name);
                line.Name = "Typical Price";
                break;

            case 2:
                sb.AppendFormat("WEIGHTEDCLOSE({0}; {1}; {2})", stock.CloseValues.Name, stock.HighValues.Name, stock.LowValues.Name);
                line.Name = "Weighted Close";
                break;

            default:
                return;
            }

            function.Expression = sb.ToString();
            function.Arguments.Clear();
            function.Arguments.Add(stock.CloseValues);
            function.Arguments.Add(stock.HighValues);
            function.Arguments.Add(stock.LowValues);

            line.XValues    = (NDataSeriesDouble)stock.XValues.Clone();
            line.UseXValues = true;
            line.Values     = function.Calculate();

            // form controls
            ExpressionLabel.Text = function.Expression;
        }
예제 #30
0
        private int FindLocalMax(NStockSeries stock, int index)
        {
            double maxValue = (double)stock.HighValues[index];
            int    maxIndex = index;

            int from = Math.Max(0, index - 10);
            int to   = Math.Min(index + 10, stock.LowValues.Count - 1);

            for (int i = from; i <= to; i++)
            {
                double value = (double)stock.HighValues[i];
                if (value > maxValue)
                {
                    maxValue = value;
                    maxIndex = i;
                }
            }

            return(maxIndex);
        }