예제 #1
0
        private void UpdateExpressions(NSeries lineUpper, NSeries lineLower, NFunctionCalculator upperCalculator,
                                       NFunctionCalculator lowerCalculator, NFunctionCalculator SMACalculator)
        {
            int nPeriod    = PeriodDropDownList.SelectedIndex * 10;
            int nDeviation = DeviationDropDownList.SelectedIndex;

            SMACalculator.Expression = String.Format("SMA(close; {0})", nPeriod);

            if (FunctionDropDownList.SelectedIndex == 0)
            {
                lineUpper.Name = "Bollinger Band - Upper";
                lineLower.Name = "Bollinger Band - Lower";

                upperCalculator.Expression = String.Format("BOLLINGER(close; {0}; {1})", nPeriod, nDeviation);
                lowerCalculator.Expression = String.Format("BOLLINGER(close; {0}; {1})", nPeriod, -nDeviation);
            }
            else
            {
                lineUpper.Name = "Envelopes - Upper Line";
                lineLower.Name = "Envelopes - Lower Line";

                upperCalculator.Expression = String.Format("ENV(close; {0}; {1})", nPeriod, nDeviation);
                lowerCalculator.Expression = String.Format("ENV(close; {0}; {1})", nPeriod, -nDeviation);
            }
        }
예제 #2
0
        public NRangeIndicatorsUC()
        {
            m_UpperCalculator = new NFunctionCalculator();
            m_LowerCalculator = new NFunctionCalculator();
            m_SMACalculator   = new NFunctionCalculator();

            m_Updating = true;
            InitializeComponent();
        }
예제 #3
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();
        }
예제 #4
0
        public NMovingAveragesUC()
        {
            InitializeComponent();

            m_Function = new NFunctionCalculator();

            m_ApplyToCombo.Items.Add("Open Values");
            m_ApplyToCombo.Items.Add("High Values");
            m_ApplyToCombo.Items.Add("Low Values");
            m_ApplyToCombo.Items.Add("Close Values");
        }
예제 #5
0
        private void ConfigureChart()
        {
            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Annotations");

            title.TextStyle.FontStyle  = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
            title.TextStyle.FillStyle  = new NColorFillStyle(GreyBlue);
            title.TextStyle.TextFormat = TextFormat.XML;
            title.ContentAlignment     = ContentAlignment.BottomCenter;
            title.Location             = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            m_Legend = nChartControl1.Legends[0];

            m_Chart          = nChartControl1.Charts[0];
            m_Chart.Enable3D = true;
            m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted);
            m_Chart.Axis(StandardAxis.Depth).Visible = false;

            // add the line series
            m_Line      = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_Line.Name = "Cumulative";
            m_Line.DataLabelStyle.Visible = false;
            m_Line.MarkerStyle.Visible    = true;
            m_Line.MarkerStyle.PointShape = PointShape.Cylinder;
            m_Line.MarkerStyle.FillStyle  = new NColorFillStyle(Color.LimeGreen);
            m_Line.MarkerStyle.Width      = new NLength(1.5f, NRelativeUnit.ParentPercentage);
            m_Line.MarkerStyle.Height     = new NLength(1.5f, NRelativeUnit.ParentPercentage);
            m_Line.ShadowStyle.Type       = ShadowType.GaussianBlur;
            m_Line.ShadowStyle.Color      = Color.FromArgb(80, 0, 0, 0);
            m_Line.ShadowStyle.Offset     = new NPointL(2, 2);
            m_Line.ShadowStyle.FadeLength = new NLength(4);

            // add the bar series
            m_Bar      = (NBarSeries)m_Chart.Series.Add(SeriesType.Bar);
            m_Bar.Name = "Bar Series";
            m_Bar.DataLabelStyle.Visible = false;
            m_Bar.BorderStyle.Width      = new NLength(0, NGraphicsUnit.Pixel);
            m_Bar.FillStyle              = new NGradientFillStyle(GradientStyle.Vertical, GradientVariant.Variant2, Color.DarkBlue, Color.CornflowerBlue);
            m_Bar.ShadowStyle.Type       = ShadowType.GaussianBlur;
            m_Bar.ShadowStyle.Color      = Color.FromArgb(80, 0, 0, 0);
            m_Bar.ShadowStyle.Offset     = new NPointL(3, 3);
            m_Bar.ShadowStyle.FadeLength = new NLength(4);

            // fill with random data and sort in descending order
            m_Bar.Values.FillRandom(Random, 10);
            m_Bar.Values.Sort(DataSeriesSortOrder.Descending);

            // generate a data series cumulative sum of the bar values
            NFunctionCalculator fc = new NFunctionCalculator();

            fc.Expression = "CUMSUM(Value)";
            fc.Arguments.Add(m_Bar.Values);
            m_Line.Values = fc.Calculate();
        }
예제 #6
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 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();
        }
예제 #8
0
        private void GenerateData(int nCount)
        {
            DateTime now = DateTime.Now;

            GenerateOHLCData(m_Stock, 300, nCount);
            TimeSpan day = new TimeSpan(1, 0, 0, 0, 0);

            for (int i = 0; i < nCount; i++)
            {
                m_Stock.XValues.Add(now);
                m_HighLow.XValues.Add(now);
                m_LineSMA.XValues.Add(now);

                now += day;
            }

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

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

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

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

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

            // remove data that won't be charted
            m_Stock.HighValues.RemoveRange(0, 20);
            m_Stock.LowValues.RemoveRange(0, 20);
            m_Stock.OpenValues.RemoveRange(0, 20);
            m_Stock.CloseValues.RemoveRange(0, 20);
            m_HighLow.HighValues.RemoveRange(0, 20);
            m_HighLow.LowValues.RemoveRange(0, 20);
            m_LineSMA.Values.RemoveRange(0, 20);
        }
        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;
        }
예제 #10
0
 public NSideGuidelineUC()
 {
     m_Function = new NFunctionCalculator();
     InitializeComponent();
 }
        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;
        }
예제 #12
0
        public NSumElementsUC()
        {
            InitializeComponent();

            m_FuncCalculator = new NFunctionCalculator();
        }
        public NAverageMedianMinMaxUC()
        {
            InitializeComponent();

            m_FuncCalculator = new NFunctionCalculator();
        }
예제 #14
0
        private void AddData()
        {
            int          nCount = 200;
            NStockSeries s = m_Stock;
            double       open, high, low, close;

            if (m_OpenValues == null || m_OpenValues.Length < nCount)
            {
                m_OpenValues  = new double[nCount];
                m_HighValues  = new double[nCount];
                m_LowValues   = new double[nCount];
                m_CloseValues = new double[nCount];
                m_XValues     = new double[nCount];
            }

            for (int index = 0; index < nCount; index++)
            {
                open = m_PrevClose;

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

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

                m_PrevClose = close;

                m_OpenValues[index]  = open;
                m_HighValues[index]  = high;
                m_LowValues[index]   = low;
                m_CloseValues[index] = close;
                m_XValues[index]     = m_Start.ToOADate();

                // advance to next working day
                m_Start = m_Start.AddDays(1);
            }

            s.OpenValues.AddRange(m_OpenValues, 0, nCount);
            s.HighValues.AddRange(m_HighValues, 0, nCount);
            s.LowValues.AddRange(m_LowValues, 0, nCount);
            s.CloseValues.AddRange(m_CloseValues, 0, nCount);
            s.XValues.AddRange(m_XValues, 0, nCount);

            int period = 20;

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

            fc.Arguments.Add(m_Stock.CloseValues);

            // calculate the simple moving average
            fc.Expression    = "SMA(close; " + period.ToString() + ")";
            m_LineSMA.Values = fc.Calculate();
            m_LineSMA.XValues.AddRange(m_XValues, 0, nCount);

            int numberOfDataPoints = 1000;

            switch (NumberOfDataPointsComboBox.SelectedIndex)
            {
            case 0:
                numberOfDataPoints = 1000;
                break;

            case 1:
                numberOfDataPoints = 5000;
                break;

            case 2:
                numberOfDataPoints = 10000;
                break;
            }

            if (s.Values.Count > numberOfDataPoints)
            {
                s.OpenValues.RemoveRange(0, nCount);
                s.HighValues.RemoveRange(0, nCount);
                s.LowValues.RemoveRange(0, nCount);
                s.CloseValues.RemoveRange(0, nCount);
                s.XValues.RemoveRange(0, nCount);

                m_LineSMA.Values.RemoveRange(0, nCount);
                m_LineSMA.XValues.RemoveRange(0, nCount);
            }
        }
예제 #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel header = nChartControl1.Labels.AddHeader("Train Sales");

            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));

            nChartControl1.Legends[0].Mode = LegendMode.Disabled;

            NChart chart = nChartControl1.Charts[0];

            // perform manual stretch
            float fAspect = ((float)nChartControl1.Width.Value / (float)nChartControl1.Height.Value);

            // perform manual stretch
            if (fAspect > 1)
            {
                chart.Width  = 86 * fAspect;
                chart.Height = 70;
            }
            else
            {
                chart.Width  = 86;
                chart.Height = 70 * fAspect;
            }

            chart.Location = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage),
                                         new NLength(18, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(new NLength(86, NRelativeUnit.ParentPercentage),
                                    new NLength(70, NRelativeUnit.ParentPercentage));

            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.Wall(ChartWallType.Floor).Visible = false;
            chart.Wall(ChartWallType.Left).Visible  = false;
            chart.Axis(StandardAxis.Depth).Visible  = false;

            chart.Axis(StandardAxis.Depth).Visible = false;
            NOrdinalScaleConfigurator ordinalScaleConfigurator = (NOrdinalScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;

            ordinalScaleConfigurator.InnerMajorTickStyle.LineStyle.Width = new NLength(0, NGraphicsUnit.Pixel);
            ordinalScaleConfigurator.MajorGridStyle.LineStyle.Pattern    = LinePattern.Dot;
            ordinalScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, false);
            ordinalScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
            NDockAxisAnchor anchor = new NDockAxisAnchor(AxisDockZone.FrontBottom, false, 5, 95);

            chart.Axis(StandardAxis.PrimaryX).Anchor = anchor;
            NLinearScaleConfigurator linearSclaeConfigurator = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;

            linearSclaeConfigurator.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;

            NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);
            NBarSeries  bar  = (NBarSeries)chart.Series.Add(SeriesType.Bar);

            bar.Name = "Bar Series";
            bar.BorderStyle.Width      = new NLength(0, NGraphicsUnit.Pixel);
            bar.FillStyle              = new NColorFillStyle(Color.MediumPurple);
            bar.DataLabelStyle.Visible = false;
            bar.InflateMargins         = true;

            // fill with random data
            Random random = new Random();

            bar.Values.FillRandom(random, 10);

            // generate a data series cumulative sum of the bar values
            NFunctionCalculator fc = new NFunctionCalculator();

            fc.Expression = "CUMSUM(Value)";
            fc.Arguments.Add(bar.Values);

            // display this data series as line
            line.Name   = "Cumulative";
            line.Values = fc.Calculate();
            line.MarkerStyle.Visible    = true;
            line.MarkerStyle.PointShape = PointShape.Cylinder;
            line.DataLabelStyle.Visible = false;
            line.DataLabelStyle.ArrowStrokeStyle.Width = new NLength(0, NGraphicsUnit.Pixel);

            bar.BarShape = BarShape.Cylinder;

            for (int i = 0; i < bar.Values.Count; i++)
            {
                bar.FillStyles[i] = new NColorFillStyle(WebExamplesUtilities.RandomColor());
            }
            bar.Legend.Mode  = SeriesLegendMode.DataPoints;
            line.Legend.Mode = SeriesLegendMode.None;

            NImageResponse imageResponse = new NImageResponse();

            imageResponse.StreamImageToBrowser = true;
            nChartControl1.ServerSettings.BrowserResponseSettings.DefaultResponse = imageResponse;
            nChartControl1.RenderControl(null);
        }
예제 #16
0
        public NVolumeIndicatorsUC()
        {
            InitializeComponent();

            m_Function = new NFunctionCalculator();
        }
예제 #17
0
        private void UpdateFunction(NStockSeries stock, NAreaSeries volume, NLineSeries line, NFunctionCalculator function)
        {
            int           nParam = ParameterDropDownList.SelectedIndex * 10;
            StringBuilder sb     = new StringBuilder();

            switch (FunctionDropDownList.SelectedIndex)
            {
            case 0:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.Append("ACCDIST(close; high; low; volume)");
                line.Name = "Accumulation Distribution";
                ParameterDropDownList.Enabled = false;
                break;

            case 1:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.Append("CHOSC(close; high; low; volume; 3; 10)");
                line.Name = "Chaikin Oscillator";
                ParameterDropDownList.Enabled = false;
                break;

            case 2:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.Append("EMV(high; low; volume)");
                line.Name = "Ease of Movement";
                ParameterDropDownList.Enabled = false;
                break;

            case 3:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("MFI(close; high; low; volume; {0})", nParam);
                line.Name = "Money Flow Index";
                ParameterDropDownList.Enabled = true;
                break;

            case 4:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("NVI(close; volume; {0})", nParam);
                line.Name = "Negative Volume Index";
                ParameterDropDownList.Enabled = true;
                break;

            case 5:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("OBV(close; volume; {0})", prevVolumeValue);
                line.Name = "On Balance Volume";
                ParameterDropDownList.Enabled = false;
                break;

            case 6:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("PVI(close; volume; {0})", nParam);
                line.Name = "Positive Volume Index";
                ParameterDropDownList.Enabled = true;
                break;

            case 7:
                function.Arguments.Add(volume.Values);
                function.Arguments.Add(stock.CloseValues);
                sb.Append("PVT(close; volume; 0)");
                line.Name = "Price and Volume Trend";
                ParameterDropDownList.Enabled = false;
                break;

            default:
                return;
            }

            function.Expression = sb.ToString();

            ExpressionLabel.Text = function.Expression;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // form controls
                FunctionDropDownList.Items.Add("Count");
                FunctionDropDownList.Items.Add("Standard Deviation");
                FunctionDropDownList.Items.Add("Root Mean Square");
                FunctionDropDownList.SelectedIndex = 0;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Functions");

            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));

            // align the legend
            NLegend legend = nChartControl1.Legends[0];

            legend.Location      = new NPointL(legend.Location.X, new NLength(15, NRelativeUnit.ParentPercentage));
            legend.Data.MarkSize = new NSizeL(5, 5);

            nFuncCalculator = new NFunctionCalculator();

            nChart          = nChartControl1.Charts[0];
            nChart.Enable3D = true;
            nChart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            nChart.LightModel.SetPredefinedLightModel(PredefinedLightModel.MetallicLustre);
            nChart.BoundsMode = BoundsMode.Stretch;
            nChart.Location   = new NPointL(
                new NLength(10, NRelativeUnit.ParentPercentage),
                new NLength(15, NRelativeUnit.ParentPercentage));
            nChart.Size = new NSizeL(
                new NLength(70, NRelativeUnit.ParentPercentage),
                new NLength(75, NRelativeUnit.ParentPercentage));

            nChart.Axis(StandardAxis.Depth).Visible  = false;
            nChart.Wall(ChartWallType.Left).Visible  = false;
            nChart.Wall(ChartWallType.Floor).Visible = false;



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

            ordinalScale.DisplayDataPointsBetweenTicks = false;

            // add a constline to diplay the function result
            NAxisConstLine cl = nChart.Axis(StandardAxis.PrimaryY).ConstLines.Add();

            cl.StrokeStyle.Width = new NLength(2, NGraphicsUnit.Pixel);
            cl.StrokeStyle.Color = Color.Red;
            cl.Value             = 0;

            // add the bar series
            nBar                        = (NBarSeries)nChart.Series.Add(SeriesType.Bar);
            nBar.Name                   = "Bar1";
            nBar.Values.Name            = "values";
            nBar.Values.ValueFormatter  = new NNumericValueFormatter("0.00");
            nBar.MultiBarMode           = MultiBarMode.Series;
            nBar.DataLabelStyle.Visible = false;
            nBar.Legend.Mode            = SeriesLegendMode.DataPoints;
            nBar.BarShape               = BarShape.Cylinder;
            nBar.BorderStyle.Width      = new NLength(0, NGraphicsUnit.Pixel);
            nBar.FillStyle              = new NColorFillStyle(Color.DarkSeaGreen);
            nBar.Values.FillRandomRange(Random, 10, 0, 20);
            nBar.Legend.TextStyle = new NTextStyle(new NFontStyle("Arial", 7));

            // add argument
            nFuncCalculator.Arguments.Add(nBar.Values);
            nBar.Values.FillRandomRange(Random, 10, 0, 20);


            BuildExpression();
            CalculateFunction();
        }
예제 #19
0
        private void AddData(NCartesianChart chart, NWorkCalendar calendar)
        {
            const int nNumberOfWeeks  = 20;
            const int nWorkDaysInWeek = 5;
            const int nTotalWorkDays  = nNumberOfWeeks * nWorkDaysInWeek;
            const int nHistoricalDays = 20;

            NLineSeries lineSMA = new NLineSeries();

            lineSMA.Name = "SMA(20)";
            lineSMA.DataLabelStyle.Visible = false;
            lineSMA.BorderStyle.Color      = Color.DarkOrange;
            lineSMA.UseXValues             = true;

            // create the stock series
            NStockSeries stock = new NStockSeries();

            chart.Series.Add(stock);
            stock.DisplayOnAxis(StandardAxis.PrimaryX, true);

            stock.Name                   = "Stock Data";
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Bar;
            stock.CandleWidth            = new NLength(0.8f, NRelativeUnit.ParentPercentage);
            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;
            stock.OpenValues.Name        = "open";
            stock.CloseValues.Name       = "close";
            stock.HighValues.Name        = "high";
            stock.LowValues.Name         = "low";

            int period = 20;

            // add the bollinger bands as high low area
            NHighLowSeries highLow = new NHighLowSeries();

            chart.Series.Add(highLow);
            highLow.DisplayOnAxis(StandardAxis.SecondaryX, true);

            highLow.Name = "BB(" + period.ToString() + ", 2)";
            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
            GenerateData(stock, calendar, 300, nTotalWorkDays + nHistoricalDays);

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

            fc.Arguments.Add(stock.CloseValues);

            // calculate the bollinger bands
            fc.Expression           = "BOLLINGER(close;" + period.ToString() + "; 2)";
            highLow.HighValues      = fc.Calculate();
            highLow.HighValues.Name = "BollingerUpper";

            fc.Expression          = "BOLLINGER(close; " + period.ToString() + "; -2)";
            highLow.LowValues      = fc.Calculate();
            highLow.LowValues.Name = "BollingerLower";
            highLow.XValues.InsertRange(0, stock.XValues);

            // calculate the simple moving average
            fc.Expression  = "SMA(close; " + period.ToString() + ")";
            lineSMA.Values = fc.Calculate();
            lineSMA.XValues.InsertRange(0, stock.XValues);

            // remove first period from line SMA
            lineSMA.Values.RemoveRange(0, period);
            lineSMA.XValues.RemoveRange(0, period);

            // remove first period from high low
            highLow.XValues.RemoveRange(0, period);
            highLow.HighValues.RemoveRange(0, period);
            highLow.LowValues.RemoveRange(0, period);

            // remove first period from stock
            stock.OpenValues.RemoveRange(0, period);
            stock.HighValues.RemoveRange(0, period);
            stock.LowValues.RemoveRange(0, period);
            stock.CloseValues.RemoveRange(0, period);
            stock.XValues.RemoveRange(0, period);
        }
예제 #20
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel header = nChartControl1.Labels.AddHeader("Bollinger Bands /\n Envelopes");

            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 chart
            NChart chart = nChartControl1.Charts[0];

            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.Height     = 40;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(25, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(73, NRelativeUnit.ParentPercentage));

            // 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;

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

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

            // Add line series for the upper band
            NLineSeries lineUpper = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineUpper.DataLabelStyle.Visible = false;
            lineUpper.BorderStyle.Color      = Color.Green;

            // Add line series for lower band
            NLineSeries lineLower = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineLower.DataLabelStyle.Visible = false;
            lineLower.BorderStyle.Color      = Color.Green;

            // Add line series for Simple Moving Average
            NLineSeries lineSMA = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineSMA.DataLabelStyle.Visible = false;
            lineSMA.BorderStyle.Color      = Color.Orange;
            lineSMA.Name = "Simple Moving Average";

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

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

            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Stick;
            stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            stock.UpStrokeStyle.Color    = color1;
            stock.DownStrokeStyle.Color  = color2;
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.CloseValues.Name       = "close";
            stock.UseXValues             = true;
            stock.InflateMargins         = true;

            // Add arguments
            NFunctionCalculator upperCalculator = new NFunctionCalculator();
            NFunctionCalculator lowerCalculator = new NFunctionCalculator();
            NFunctionCalculator SMACalculator   = new NFunctionCalculator();

            upperCalculator.Arguments.Add(stock.CloseValues);
            lowerCalculator.Arguments.Add(stock.CloseValues);
            SMACalculator.Arguments.Add(stock.CloseValues);

            GenerateData(stock);

            // form controls
            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Bollinger Bands");
                FunctionDropDownList.Items.Add("Envelopes");
                FunctionDropDownList.SelectedIndex = 0;

                WebExamplesUtilities.FillComboWithValues(PeriodDropDownList, 0, 100, 10);
                PeriodDropDownList.SelectedIndex = 2;

                WebExamplesUtilities.FillComboWithValues(DeviationDropDownList, 0, 20, 1);
                DeviationDropDownList.SelectedIndex = 2;

                ShowPricesCheckBox.Checked = true;
                ShowSMACheckBox.Checked    = true;
            }

            UpdateExpressions(lineUpper, lineLower, upperCalculator, lowerCalculator, SMACalculator);
            CalculateFunctions(stock, lineUpper, lineLower, lineSMA, upperCalculator, lowerCalculator, SMACalculator);
            stock.Visible   = ShowPricesCheckBox.Checked;
            lineSMA.Visible = ShowSMACheckBox.Checked;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!NThinChartControl1.Initialized)
            {
                // enable jittering (full scene antialiasing)
                NThinChartControl1.Settings.JitterMode = JitterMode.Enabled;

                NThinChartControl1.BackgroundStyle.FrameStyle.Visible = false;
                NThinChartControl1.Panels.Clear();

                // add header
                NLabel header = NThinChartControl1.Labels.AddHeader("General Thin Web Functionality");
                header.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
                header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
                header.Margins  = new NMarginsL(10, 10, 10, 10);
                header.DockMode = PanelDockMode.Top;

                NChart chart = new NCartesianChart();
                NThinChartControl1.Panels.Add(chart);
                chart.BoundsMode = BoundsMode.Stretch;
                chart.DockMode   = PanelDockMode.Fill;
                chart.Margins    = new NMarginsL(10, 0, 10, 10);

                // setup X axis
                NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();
                // set configurator
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

                // enable the scrollbar
                chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;

                // setup primary Y axis
                NAxis axis = chart.Axis(StandardAxis.PrimaryY);
                NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)axis.ScaleConfigurator;

                // add interlace stripe
                NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1);
                stripStyle.Interlaced = true;
                stripStyle.SetShowAtWall(ChartWallType.Back, true);
                stripStyle.SetShowAtWall(ChartWallType.Left, true);
                scaleY.StripStyles.Add(stripStyle);

                // line series for the function
                NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);
                line.DataLabelStyle.Visible = false;
                line.BorderStyle.Color      = Color.Red;
                line.BorderStyle.Width      = new NLength(2, NGraphicsUnit.Pixel);
                line.UseXValues             = true;

                Color customColor = Color.FromArgb(100, 100, 150);

                // setup the stock series
                NStockSeries stock = (NStockSeries)chart.Series.Add(SeriesType.Stock);
                stock.DataLabelStyle.Visible   = false;
                stock.CandleStyle              = CandleStyle.Bar;
                stock.CandleWidth              = new NLength(1, NRelativeUnit.ParentPercentage);
                stock.HighLowStrokeStyle.Color = customColor;
                stock.UpStrokeStyle.Color      = customColor;
                stock.DownStrokeStyle.Color    = customColor;
                stock.UpFillStyle              = new NColorFillStyle(Color.White);
                stock.DownFillStyle            = new NColorFillStyle(customColor);
                stock.OpenValues.Name          = "open";
                stock.HighValues.Name          = "high";
                stock.LowValues.Name           = "low";
                stock.CloseValues.Name         = "close";
                stock.UseXValues = true;

                GenerateData(stock);
                NFunctionCalculator functionCalculator = new NFunctionCalculator();
                BuildExpression(functionCalculator, stock, line);

                line.XValues = (NDataSeriesDouble)stock.XValues.Clone();
                line.Values  = functionCalculator.Calculate();

                NThinChartControl1.ServerSettings.EnableTiledZoom = true;

                // configure toolbar
                NThinChartControl1.Toolbar.Visible = true;
                NThinChartControl1.Controller.SetActivePanel(chart);

                // add a data zoom tool
                NDataZoomTool dataZoomTool = new NDataZoomTool();
                dataZoomTool.Exclusive      = true;
                dataZoomTool.Enabled        = true;
                dataZoomTool.AllowYAxisZoom = false;
                NThinChartControl1.Controller.Tools.Add(dataZoomTool);

                // add a data pan tool
                NDataPanTool dataPanTool = new NDataPanTool();
                dataPanTool.Exclusive = true;
                dataPanTool.Enabled   = false;
                NThinChartControl1.Controller.Tools.Add(dataPanTool);

                // add a tooltip tool
                NThinChartControl1.Controller.Tools.Add(new NTooltipTool());
                // add a cursor change tool
                NThinChartControl1.Controller.Tools.Add(new NCursorTool());

                NThinChartControl1.Toolbar.Visible = true;
                NThinChartControl1.Toolbar.Items.Add(new NToolbarButton(new NSaveImageAction("Save as PNG", new NPngImageFormat(), true, new NSize(0, 0), 96)));
                NThinChartControl1.Toolbar.Items.Add(new NToolbarSeparator());

                NThinChartControl1.Toolbar.Items.Add(new NToolbarButton(new NToggleDataZoomToolAction()));
                NThinChartControl1.Toolbar.Items.Add(new NToolbarButton(new NToggleDataPanToolAction()));
            }
        }
        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;
        }
예제 #23
0
파일: Graph.cs 프로젝트: lewis810/HueApp
        private void callPersonalGraph(string projectName, string ScenarioName, int idx)
        {
            nChartControl1.Clear();

            //rData.getRData()[0].taskName 이런식으로 인덱스 줘서 사용하면 될 듯
            m_FuncCalculator = new NFunctionCalculator();

            nChartControl1.Legends.Clear();



            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Task x 소요 시간");
            //title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Regular);
            title.TextStyle.FontStyle = new NFontStyle(pfc.Families[0].ToString(), 18, FontStyle.Regular);
            title.ContentAlignment = ContentAlignment.BottomCenter;
            title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            // setup chart
            m_Chart = nChartControl1.Charts[0];
            m_Chart.BoundsMode = BoundsMode.Stretch;
            m_Chart.Location = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage));
            m_Chart.Size = new NSizeL(new NLength(80, NRelativeUnit.ParentPercentage), new NLength(75, NRelativeUnit.ParentPercentage));
            


            //m_Chart.Axis(StandardAxis.Depth).Visible = false;


            // add a line series for the function
            m_Line = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_Line.MarkerStyle.Visible = true;
            m_Line.MarkerStyle.BorderStyle.Color = Color.DarkGreen;
            m_Line.MarkerStyle.BorderStyle.Width = new NLength(2, NGraphicsUnit.Pixel);
            m_Line.MarkerStyle.Width = new NLength(1.2f, NRelativeUnit.ParentPercentage);
            m_Line.MarkerStyle.Height = new NLength(1.2f, NRelativeUnit.ParentPercentage);
            m_Line.MarkerStyle.PointShape = PointShape.Cylinder;
            m_Line.MarkerStyle.FillStyle = new NColorFillStyle(Color.Gold);
            m_Line.BorderStyle.Color = Color.DarkGreen;
            m_Line.BorderStyle.Width = new NLength(2, NGraphicsUnit.Pixel);
            m_Line.Legend.Mode = SeriesLegendMode.None;
            m_Line.DataLabelStyle.Format = "<value>";
            m_Line.Values.ValueFormatter = new NNumericValueFormatter("0.0");
            m_Line.ShadowStyle.Type = ShadowType.GaussianBlur;
            m_Line.ShadowStyle.Offset = new NPointL(2, 2);
            m_Line.ShadowStyle.Color = Color.FromArgb(120, 0, 0, 0);
            m_Line.ShadowStyle.FadeLength = new NLength(5);


            // add the bar series
            m_Bar = (NBarSeries)m_Chart.Series.Add(SeriesType.Bar);
            m_Bar.Name = "Bar1";
            m_Bar.Values.Name = "values";
            m_Bar.Values.ValueFormatter = new NNumericValueFormatter("0.0");
            m_Bar.MultiBarMode = MultiBarMode.Stacked;
            m_Bar.DataLabelStyle.Visible = true; // 바에 보이는 값
            //m_Bar.Legend.Mode = SeriesLegendMode.None; // 범례 안보이게 하는 거
            m_Bar.BarShape = BarShape.Cylinder;
            m_Bar.BorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel);
            m_Bar.FillStyle = new NColorFillStyle(Color.DarkKhaki);
            m_Bar.ShadowStyle.Type = ShadowType.Solid;
            m_Bar.ShadowStyle.Offset = new NPointL(2, 2);
            m_Bar.ShadowStyle.Color = Color.FromArgb(80, 0, 0, 0);
            //m_Bar.Values.FillRandomRange(new Random(), 14, 0, 100);

            NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator();
            //m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale;
            m_Chart.Axis(StandardAxis.PrimaryX).ScrollBar.ResetButton.Visible = false;

            NNumericAxisPagingView numericPagingView = new NNumericAxisPagingView(new NRange1DD(0, 10));
            m_Chart.Axis(StandardAxis.PrimaryX).PagingView = numericPagingView;
            m_Chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;
            nChartControl1.Controller.Tools.Add(new NAxisScrollTool());

            NStandardScaleConfigurator scaleConfiguratorX = (NStandardScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
            scaleConfiguratorX.MajorTickMode = MajorTickMode.AutoMaxCount;

            scaleConfiguratorX.AutoLabels = false;

            foreach (ResultData.ResultInfo temp in rData.getRData())
            {
                // 현재 찾고자 하는 프로젝트와 시나리오랑 같으면
                if (temp.projectName == projectName && temp.taskName == ScenarioName)
                {
                    if (idx == -1 /*&& temp.isMin == true*/) // ***************************************************************************************************************** check
                    {
                        ImgAverageInfo.Clear();

                        // 해당 시나리오 값에서 이동한 path 이미지들 값 가져오기
                        foreach (ResultData.ImgTime imgTemp in temp.pathInfo)
                        {
                            bool inList = false;

                            float timeValue = System.Convert.ToSingle(imgTemp.timeImg);

                            // 리스트 내에 같은 값 찾기

                            if (ImgAverageInfo.Count != 0)
                            {
                                foreach (ImgAverageTime inListImg in ImgAverageInfo)
                                {
                                    // 같은게 있다면
                                    if (inListImg.imgName == imgTemp.imgName)
                                    {
                                        inListImg.count += 1;
                                        inListImg.imgTime += timeValue;
                                        inList = true;
                                        break;
                                    }
                                }
                            }

                            // 리스트 내에 없다면
                            if (inList == false)
                                ImgAverageInfo.Add(new ImgAverageTime() { imgName = imgTemp.imgName, imgTime = timeValue, count = 1 });
                        }
                    }
                    // Idx랑 같으면
                    else if (temp.idx == idx)
                    {
                        // 해당 시나리오 값에서 이동한 path 이미지들 값 가져오기
                        foreach (ResultData.ImgTime imgTemp in temp.pathInfo)
                        {
                            scaleConfiguratorX.Labels.Add(imgTemp.imgName);
                            m_Bar.Values.Add(imgTemp.timeImg);
                        }
                    }
                }
            }


            if (idx == -1)
            {
                foreach (ImgAverageTime listImg in ImgAverageInfo)
                {
                    scaleConfiguratorX.Labels.Add(listImg.imgName);
                    m_Bar.Values.Add(listImg.imgTime / listImg.count);
                }
            }





            //m_FuncCalculator.Arguments.Add(m_Line.Values);
            m_FuncCalculator.Arguments.Add(m_Bar.Values);
            m_FuncCalculator.Expression = "CUMSUM(values)";
            m_Line.Values = m_FuncCalculator.Calculate();

            m_Line.Values.ValueFormatter = new NNumericValueFormatter("0.0");


            // form controls
            /*m_FunctionCombo.Items.Add("Power");
            m_FunctionCombo.Items.Add("Cumulative");
            m_FunctionCombo.Items.Add("Exponential Average");
            m_FunctionCombo.SelectedIndex = 0;*/


            nChartControl1.Refresh();
        }
예제 #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Average");
                FunctionDropDownList.Items.Add("Min");
                FunctionDropDownList.Items.Add("Max");
                FunctionDropDownList.SelectedIndex = 0;

                GroupingDropDownList.Items.Add("Do not group");
                GroupingDropDownList.Items.Add("Group by every 2 values");
                GroupingDropDownList.Items.Add("Group by every 3 values");
                GroupingDropDownList.Items.Add("Group by every 4 values");
                GroupingDropDownList.SelectedIndex = 0;

                DataDropDownList.Items.Add("Positive");
                DataDropDownList.Items.Add("Positive and Negative");
                DataDropDownList.SelectedIndex = 0;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Average, Min, Max");

            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));

            nFuncCalculator = new NFunctionCalculator();

            // setup legend
            NLegend legend = nChartControl1.Legends[0];

            legend.Location      = new NPointL(legend.Location.X, new NLength(15, NRelativeUnit.ParentPercentage));
            legend.Data.MarkSize = new NSizeL(5, 5);

            // setup chart
            nChart          = nChartControl1.Charts[0];
            nChart.Enable3D = true;
            nChart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            nChart.LightModel.SetPredefinedLightModel(PredefinedLightModel.MetallicLustre);
            nChart.BoundsMode = BoundsMode.Stretch;
            nChart.Location   = new NPointL(
                new NLength(10, NRelativeUnit.ParentPercentage),
                new NLength(15, NRelativeUnit.ParentPercentage));
            nChart.Size = new NSizeL(
                new NLength(70, NRelativeUnit.ParentPercentage),
                new NLength(75, NRelativeUnit.ParentPercentage));

            nChart.Axis(StandardAxis.Depth).Visible  = false;
            nChart.Wall(ChartWallType.Left).Visible  = false;
            nChart.Wall(ChartWallType.Floor).Visible = false;

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

            ordinalScale.DisplayDataPointsBetweenTicks = false;

            // add a line series for the function
            nLine = (NLineSeries)nChart.Series.Add(SeriesType.Line);
            nLine.MarkerStyle.Visible           = true;
            nLine.MarkerStyle.BorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel);
            nLine.MarkerStyle.FillStyle         = new NColorFillStyle(Color.Crimson);
            nLine.BorderStyle.Color             = Color.Red;
            nLine.BorderStyle.Width             = new NLength(2, NGraphicsUnit.Pixel);
            nLine.Legend.Mode           = SeriesLegendMode.None;
            nLine.Values.ValueFormatter = new NNumericValueFormatter("0.00");
            nLine.DisplayOnAxis(StandardAxis.PrimaryX, false);
            nLine.DisplayOnAxis(StandardAxis.SecondaryX, true);
            nLine.Legend.TextStyle = new NTextStyle(new NFontStyle("Arial", 7));

            // add the bar series
            nBar                        = (NBarSeries)nChart.Series.Add(SeriesType.Bar);
            nBar.Name                   = "Bar1";
            nBar.Values.Name            = "values";
            nBar.Values.ValueFormatter  = new NNumericValueFormatter("0.00");
            nBar.MultiBarMode           = MultiBarMode.Series;
            nBar.DataLabelStyle.Visible = false;
            nBar.Legend.Mode            = SeriesLegendMode.DataPoints;
            nBar.BarShape               = BarShape.Cylinder;
            nBar.BorderStyle.Width      = new NLength(0, NGraphicsUnit.Pixel);
            nBar.FillStyle              = new NColorFillStyle(Color.DarkSalmon);
            nBar.Values.FillRandomRange(Random, 12, 0, 50);
            nBar.Legend.TextStyle = new NTextStyle(new NFontStyle("Arial", 7));

            if (DataDropDownList.SelectedIndex == 0)
            {
                nBar.Values.FillRandomRange(Random, 12, 0, 50);
            }
            else
            {
                nBar.Values.FillRandomRange(Random, 12, -25, 25);
            }

            BuildExpression();
            CalcFunction();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WebExamplesUtilities.FillComboWithValues(PeriodDropDownList, 0, 100, 10);
                PeriodDropDownList.SelectedIndex = 2;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            NFunctionCalculator calc = new NFunctionCalculator();

            nChartControl1.Settings.ShapeRenderingMode = ShapeRenderingMode.None;

            NChart chart = nChartControl1.Charts[0];

            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(20, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(75, NRelativeUnit.ParentPercentage));

            NLegend legend = nChartControl1.Legends[0];

            legend.Data.ExpandMode = LegendExpandMode.ColsOnly;
            legend.Location        = new NPointL(
                new NLength(98, NRelativeUnit.ParentPercentage),
                new NLength(12, NRelativeUnit.ParentPercentage));

            // align the chart and the legend
            NSideGuideline guideline = new NSideGuideline(PanelSide.Right);

            guideline.Targets.Add(legend);
            guideline.Targets.Add(chart);
            nChartControl1.Document.RootPanel.Guidelines.Add(guideline);

            // 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;
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // setup primary Y axis
            NAxis axisY1 = chart.Axis(StandardAxis.PrimaryY);

            axisY1.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 45, 100);

            NLinearScaleConfigurator scaleY1 = (NLinearScaleConfigurator)axisY1.ScaleConfigurator;

            scaleY1.RulerStyle.Height                   = new NLength(2, NGraphicsUnit.Pixel);
            scaleY1.MajorGridStyle.ShowAtWalls          = new ChartWallType[] { ChartWallType.Back };
            scaleY1.InnerMajorTickStyle.LineStyle.Width = new NLength(0);

            // setup secondary Y axis
            NAxis axisY2 = chart.Axis(StandardAxis.SecondaryY);

            axisY2.Visible = true;
            axisY2.Anchor  = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 0, 40);

            NLinearScaleConfigurator scaleY2 = (NLinearScaleConfigurator)axisY2.ScaleConfigurator;

            scaleY2.RulerStyle.Height                   = new NLength(2, NGraphicsUnit.Pixel);
            scaleY2.MajorGridStyle.ShowAtWalls          = new ChartWallType[] { ChartWallType.Back };
            scaleY2.InnerMajorTickStyle.LineStyle.Width = new NLength(0);

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

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

            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Stick;
            stock.UpStrokeStyle.Color    = color1;
            stock.DownStrokeStyle.Color  = color2;
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            stock.UseXValues             = true;
            stock.InflateMargins         = true;

            // Add line series for ADX
            NLineSeries lineADX = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineADX.DisplayOnAxis(StandardAxis.PrimaryY, false);
            lineADX.DisplayOnAxis(StandardAxis.SecondaryY, true);
            lineADX.BorderStyle.Color = Color.LimeGreen;
            lineADX.Name = "ADX";
            lineADX.DataLabelStyle.Visible = false;

            // Add line series for +DI
            NLineSeries lineDIPos = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineDIPos.MultiLineMode = MultiLineMode.Overlapped;
            lineDIPos.DisplayOnAxis(StandardAxis.PrimaryY, false);
            lineDIPos.DisplayOnAxis(StandardAxis.SecondaryY, true);
            lineDIPos.BorderStyle.Color = Color.Red;
            lineDIPos.Name = "+DI";
            lineDIPos.DataLabelStyle.Visible = false;

            // Add line series for -DI
            NLineSeries lineDINeg = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineDINeg.MultiLineMode = MultiLineMode.Overlapped;
            lineDINeg.DisplayOnAxis(StandardAxis.PrimaryY, false);
            lineDINeg.DisplayOnAxis(StandardAxis.SecondaryY, true);
            lineDINeg.BorderStyle.Color = Color.Blue;
            lineDINeg.Name = "-DI";
            lineDINeg.DataLabelStyle.Visible = false;

            // add arguments for function calculator
            stock.CloseValues.Name = "close";
            stock.HighValues.Name  = "high";
            stock.LowValues.Name   = "low";
            calc.Arguments.Add(stock.CloseValues);
            calc.Arguments.Add(stock.HighValues);
            calc.Arguments.Add(stock.LowValues);

            // form controls
            lineDIPos.Visible = ShowPosDICheckBox.Checked;
            lineDINeg.Visible = ShowNegDICheckBox.Checked;
            lineADX.Visible   = ShowADXCheckBox.Checked;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Directional Movement");

            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));

            GenerateData(stock);

            UpdateFunctions(stock, lineDIPos, lineDINeg, lineADX, calc);
        }
예제 #26
0
        public NTechnicalPriceIndicatorsUC()
        {
            InitializeComponent();

            m_Function = new NFunctionCalculator();
        }
예제 #27
0
        public NBasicFunctionsUC()
        {
            InitializeComponent();

            m_FuncCalculator = new NFunctionCalculator();
        }
        public NPowerCumulativeExpAverageUC()
        {
            InitializeComponent();

            m_FuncCalculator = new NFunctionCalculator();
        }
예제 #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            nFunction = new NFunctionCalculator();

            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Simple Moving Average");
                FunctionDropDownList.Items.Add("Weighted Moving Average");
                FunctionDropDownList.Items.Add("Exponential Moving Average");
                FunctionDropDownList.Items.Add("Modified Moving Average");
                FunctionDropDownList.SelectedIndex = 0;

                // form controls
                ApplyFunctionToDropDownList.Items.Add("Open");
                ApplyFunctionToDropDownList.Items.Add("High");
                ApplyFunctionToDropDownList.Items.Add("Low");
                ApplyFunctionToDropDownList.Items.Add("Close");
                ApplyFunctionToDropDownList.SelectedIndex = 3;

                WebExamplesUtilities.FillComboWithFloatValues(PeriodDropDownList, 0, 50, 1);
                PeriodDropDownList.SelectedIndex = 10;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Moving Averages");

            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));

            NLegend legend = nChartControl1.Legends[0];

            legend.Location = new NPointL(
                new NLength(98, NRelativeUnit.ParentPercentage),
                new NLength(12, NRelativeUnit.ParentPercentage));

            NChart chart = nChartControl1.Charts[0];

            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(20, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(75, NRelativeUnit.ParentPercentage));

            // align the chart and the legend
            NSideGuideline guideline = new NSideGuideline(PanelSide.Right);

            guideline.Targets.Add(legend);
            guideline.Targets.Add(chart);
            nChartControl1.Document.RootPanel.Guidelines.Add(guideline);

            // 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;

            // setup primary Y axis
            NAxis axis = chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScaleConfigurator = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            linearScaleConfigurator.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            linearScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Left, false);
            linearScaleConfigurator.InnerMajorTickStyle.LineStyle.Width = new NLength(0, NGraphicsUnit.Pixel);

            // line series for the function
            NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);

            line.DataLabelStyle.Visible = false;
            line.BorderStyle.Color      = Color.Red;
            line.BorderStyle.Width      = new NLength(2, NGraphicsUnit.Pixel);
            line.UseXValues             = true;

            Color customColor = Color.FromArgb(100, 100, 150);

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

            stock.DataLabelStyle.Visible   = false;
            stock.CandleStyle              = CandleStyle.Bar;
            stock.CandleWidth              = new NLength(1, NRelativeUnit.ParentPercentage);
            stock.HighLowStrokeStyle.Color = customColor;
            stock.UpStrokeStyle.Color      = customColor;
            stock.DownStrokeStyle.Color    = customColor;
            stock.UpFillStyle              = new NColorFillStyle(Color.White);
            stock.DownFillStyle            = new NColorFillStyle(customColor);
            stock.Legend.Mode              = SeriesLegendMode.None;
            stock.OpenValues.Name          = "open";
            stock.HighValues.Name          = "high";
            stock.LowValues.Name           = "low";
            stock.CloseValues.Name         = "close";
            stock.UseXValues     = true;
            stock.InflateMargins = true;

            GenerateData(stock);
            BuildExpression(stock, line);

            line.XValues = (NDataSeriesDouble)stock.XValues.Clone();
            line.Values  = nFunction.Calculate();
        }
예제 #30
0
        public override void Initialize()
        {
            base.Initialize();

            const int nNumberOfWeeks  = 20;
            const int nWorkDaysInWeek = 5;
            const int nDaysInWeek     = 7;
            const int nTotalWorkDays  = nNumberOfWeeks * nWorkDaysInWeek;
            const int nTotalDays      = nNumberOfWeeks * nDaysInWeek;
            const int nHistoricalDays = 20;

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

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);

            title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue);
            title.ContentAlignment    = ContentAlignment.BottomCenter;

            title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            // setup chart
            m_Chart            = nChartControl1.Charts[0];
            m_Chart.BoundsMode = BoundsMode.Fit;

            m_Chart.Location = new NPointL(new NLength(7, NRelativeUnit.ParentPercentage), new NLength(10, NRelativeUnit.ParentPercentage));
            m_Chart.Size     = new NSizeL(new NLength(86, NRelativeUnit.ParentPercentage), new NLength(70, NRelativeUnit.ParentPercentage));

            m_Chart.Height = 30;
            m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            m_Chart.Wall(ChartWallType.Floor).Visible  = false;
            m_Chart.Wall(ChartWallType.Left).Visible   = false;
            m_Chart.Wall(ChartWallType.Back).Width     = 0;
            m_Chart.Wall(ChartWallType.Back).FillStyle = new NColorFillStyle(Color.FromArgb(239, 245, 239));
            m_Chart.Axis(StandardAxis.Depth).Visible   = false;

            // setup y axis
            NLinearScaleConfigurator linearScale = (NLinearScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;

            linearScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            linearScale.MajorGridStyle.LineStyle.Color   = Color.Gray;
            linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, false);

            // setup x axis
            NAxis axisX1 = m_Chart.Axis(StandardAxis.PrimaryX);

            linearScale = new NLinearScaleConfigurator();
            axisX1.ScaleConfigurator = linearScale;

            linearScale.AutoLabels = false;

            linearScale.MinorTickCount                      = 4;
            linearScale.MajorTickMode                       = MajorTickMode.CustomStep;
            linearScale.CustomStep                          = 5;
            linearScale.RoundToTickMax                      = false;
            linearScale.RoundToTickMin                      = false;
            linearScale.OuterMajorTickStyle.Length          = new NLength(4, NGraphicsUnit.Point);
            linearScale.InnerMajorTickStyle.Length          = new NLength(0, NGraphicsUnit.Point);
            linearScale.InnerMinorTickStyle.Length          = new NLength(0, NGraphicsUnit.Point);
            linearScale.OuterMinorTickStyle.Length          = new NLength(2, NGraphicsUnit.Point);
            linearScale.OuterMinorTickStyle.LineStyle.Color = Color.Brown;
            linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
            linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, false);
            linearScale.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            linearScale.LabelStyle.ValueScale            = 0.2;

            // create a line series for the simple moving average
            m_LineSMA      = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineSMA.Name = "SMA(20)";
            m_LineSMA.DataLabelStyle.Visible = false;
            m_LineSMA.BorderStyle.Color      = Color.DarkOrange;

            // create the stock series
            m_Stock                        = (NStockSeries)m_Chart.Series.Add(SeriesType.Stock);
            m_Stock.Name                   = "Stock Data";
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Bar;
            m_Stock.CandleWidth            = new NLength(5, NGraphicsUnit.Point);
            m_Stock.InflateMargins         = false;
            m_Stock.UpFillStyle            = new NColorFillStyle(LightOrange);
            m_Stock.UpStrokeStyle.Color    = Color.Black;
            m_Stock.DownFillStyle          = new NColorFillStyle(DarkOrange);
            m_Stock.DownStrokeStyle.Color  = Color.Black;
            m_Stock.DisplayOnAxis(StandardAxis.PrimaryX, true);
            m_Stock.InflateMargins   = true;
            m_Stock.OpenValues.Name  = "open";
            m_Stock.CloseValues.Name = "close";
            m_Stock.HighValues.Name  = "high";
            m_Stock.LowValues.Name   = "low";

            // add the bollinger bands as high low area
            m_HighLow      = (NHighLowSeries)m_Chart.Series.Add(SeriesType.HighLow);
            m_HighLow.Name = "BB(20, 2)";
            m_HighLow.DataLabelStyle.Visible = false;
            m_HighLow.HighFillStyle          = new NColorFillStyle(Color.FromArgb(80, 130, 134, 168));
            m_HighLow.HighBorderStyle.Width  = new NLength(0, NGraphicsUnit.Pixel);
            m_HighLow.DisplayOnAxis(StandardAxis.SecondaryX, true);

            // generate some stock data
            GenerateOHLCData(m_Stock, 300, nTotalWorkDays + nHistoricalDays);

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

            fc.Arguments.Add(m_Stock.CloseValues);

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

            fc.Expression            = "BOLLINGER(close; 20; -2)";
            m_HighLow.LowValues      = fc.Calculate();
            m_HighLow.LowValues.Name = "BollingerLower";

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

            // remove data that won't be charted
            m_Stock.HighValues.RemoveRange(0, nHistoricalDays);
            m_Stock.LowValues.RemoveRange(0, nHistoricalDays);
            m_Stock.OpenValues.RemoveRange(0, nHistoricalDays);
            m_Stock.CloseValues.RemoveRange(0, nHistoricalDays);
            m_HighLow.HighValues.RemoveRange(0, nHistoricalDays);
            m_HighLow.LowValues.RemoveRange(0, nHistoricalDays);
            m_LineSMA.Values.RemoveRange(0, nHistoricalDays);

            GenerateDateLabels(nTotalDays);

            CandleStyleCombo.Items.Add("Candle");
            CandleStyleCombo.Items.Add("Stick");
            CandleStyleCombo.SelectedIndex = 0;

            NRangeSelection rangeSelection = new NRangeSelection();

            rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
            ((NCartesianChart)m_Chart).RangeSelections.Add(rangeSelection);

            nChartControl1.Controller.Tools.Add(new NPanelSelectorTool());
            nChartControl1.Controller.Tools.Add(new NAxisScrollTool());
            nChartControl1.Controller.Tools.Add(new NDataZoomTool());
            nChartControl1.Controller.Tools.Add(new NDataPanTool());
        }
예제 #31
0
        private void UpdateFunction(NStockSeries stock, NLineSeries line, NFunctionCalculator function)
        {
            int           nPeriod = PeriodDropDownList.SelectedIndex * 10;
            StringBuilder sb      = new StringBuilder();

            function.Arguments.Clear();

            switch (FunctionDropDownList.SelectedIndex)
            {
            case 0:                     // Average True Range
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("MMA(TR(close; high; low); {0})", nPeriod);
                line.Name = "Average True Range";
                PeriodDropDownList.Enabled = true;
                break;

            case 1:                     // Chaikin's Volatility
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("CHV(high; low; 10; {0})", nPeriod);
                line.Name = "Chaikin's Volatility";
                PeriodDropDownList.Enabled = true;
                break;

            case 2:                     // Commodity Channel Index
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("CCI(close; high; low; {0})", nPeriod);
                line.Name = "Commodity Channel Index";
                PeriodDropDownList.Enabled = true;
                break;

            case 3:                     // Detrended Price Oscillator
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("DPO(close; {0})", nPeriod);
                line.Name = "Detrended Price Oscillator";
                PeriodDropDownList.Enabled = true;
                break;

            case 4:                     // Moving Average Convergence Divergence
                function.Arguments.Add(stock.CloseValues);
                sb.Append("SUB( EMA(close;12) ; EMA(close;26) )");
                line.Name = "MACD";
                PeriodDropDownList.Enabled = false;
                break;

            case 5:                     // Mass Index
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("MI(high; low; 15; {0})", nPeriod);
                line.Name = "Mass Index";
                PeriodDropDownList.Enabled = true;
                break;

            case 6:                     // Momentum
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("MOMENTUM(close; {0})", nPeriod);
                line.Name = "Momentum";
                PeriodDropDownList.Enabled = true;
                break;

            case 7:                     // Momentum Div
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("MOMENTUMDIV(close; {0})", nPeriod);
                line.Name = "Momentum Div";
                PeriodDropDownList.Enabled = true;
                break;

            case 8:                     // Performance
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("PERFORMANCE(close)");
                line.Name = "Performance";
                PeriodDropDownList.Enabled = false;
                break;

            case 9:                     // Rate Of Change
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("ROC(close; {0})", nPeriod);
                line.Name = "Rate Of Change";
                PeriodDropDownList.Enabled = true;
                break;

            case 10:                     // Relative Strength Index
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("RSI(close; {0})", nPeriod);
                line.Name = "Relative Strength Index";
                PeriodDropDownList.Enabled = true;
                break;

            case 11:                     // Standard Deviation
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("STDDEV(close; {0})", nPeriod);
                line.Name = "Standard Deviation";
                PeriodDropDownList.Enabled = true;
                break;

            case 12:                     // Stochastic Oscillator
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("STOCHASTIC(close; high; low; {0})", nPeriod);
                line.Name = "Stochastic Oscillator";
                PeriodDropDownList.Enabled = true;
                break;

            case 13:                     // TRIX
                function.Arguments.Add(stock.CloseValues);
                sb.AppendFormat("TRIX(close; {0})", nPeriod);
                line.Name = "TRIX";
                PeriodDropDownList.Enabled = true;
                break;

            case 14:                     // William's %R
                function.Arguments.Add(stock.CloseValues);
                function.Arguments.Add(stock.HighValues);
                function.Arguments.Add(stock.LowValues);
                sb.AppendFormat("WILLIAMSR(close; high; low; {0})", nPeriod);
                line.Name = "William's %R";
                PeriodDropDownList.Enabled = true;
                break;

            default:
                return;
            }

            function.Expression  = sb.ToString();
            ExpressionLabel.Text = function.Expression;
        }