Exemple #1
0
        public void AddLineStudy(LineStudy.StudyTypeEnum studyTypeEnum, Color color, object[] extraArgs = null)
        {
            object[] args           = new object[0];
            double   strokeThicknes = 1;

            //set some extra parameters to line studies
            switch (studyTypeEnum)
            {
            case LineStudy.StudyTypeEnum.StaticText:
                args           = new object[] { "Some text for testing" };
                strokeThicknes = 12;     //for text objects is FontSize
                break;

            case LineStudy.StudyTypeEnum.VerticalLine:
                //when first parameter is false, vertical line will display DataTime instead on record number
                args = new object[]
                {
                    false,  //true - show record number, false - show datetime
                    true,   //true - show text with line, false - show only line
                    "d",    //custom datetime format, when args[0] == false. See MSDN:DateTime.ToString(string) for legal values
                };
                break;

            case LineStudy.StudyTypeEnum.ImageObject:
                args = new object[]
                {
                    "Res/open.png"
                };
                break;

            case LineStudy.StudyTypeEnum.FibonacciRetracements:
                if (extraArgs != null)
                {
                    args = extraArgs;
                }
                else
                {
                    args = new object[]
                    {
                        1.0,
                        0.763932,
                        0.618034,
                        0.5,
                        0.381966,
                        0.236068,
                        0.0,
                    }
                };
                break;

            default:
                break;
            }
            UserDrawingActivated = true;
            string studyName = studyTypeEnum.ToString();
            int    count     = _stockChartX.GetLineStudyCountByType(studyTypeEnum);

            if (count > 0)
            {
                studyName += count;
            }
            Brush     fbrush    = new SolidColorBrush(color);
            LineStudy lineStudy = _stockChartX.AddLineStudy(studyTypeEnum, studyName, fbrush, args);

            lineStudy.StrokeThickness = strokeThicknes;

            switch (studyTypeEnum)
            {
            case LineStudy.StudyTypeEnum.StaticText:
                //if linestudy is a text object we can change its text directly
                ((StaticText)lineStudy).Text = "Some other text for testing";
                break;

            case LineStudy.StudyTypeEnum.HorizontalLine:
                //change the appearance of horizontal Line
                lineStudy.StrokeType = LinePattern.DashDot;
                break;

            case LineStudy.StudyTypeEnum.ImageObject:
                //set an additional ImageAlign property, this is very usefull when setting
                //images for close and open price, when you want to put image below or above a candle
                //for Open price you'd use ImageObject.ImageAlign.BottomMiddle
                //for Close price you'd use ImageObject.ImageAlign.TopMiddle
                ((ImageObject)lineStudy).Align = ImageObject.ImageAlign.Center;
                break;
            }

            if (studyTypeEnum == LineStudy.StudyTypeEnum.HorizontalLine)
            {
                lineStudy.ValuePresenterAlignment = LineStudy.ValuePresenterAlignmentType.Left;
                lineStudy.LineStudyValue          = new CustomHorLineValueGetter(_stockChartX);
            }
        }
Exemple #2
0
        private void btnAddLineStudy_Click(object sender, RoutedEventArgs e)
        {
            LineStudy.StudyTypeEnum studyTypeEnum =
                ((StockChartX_LineStudiesParams.LineStudyParams)cmbLineStudies.SelectedItem).StudyTypeEnum;
            object[] args           = new object[0];
            double   strokeThicknes = 1;

            //set some extra parameters to line studies
            switch (studyTypeEnum)
            {
            case LineStudy.StudyTypeEnum.StaticText:
                args           = new object[] { "Some text for testing" };
                strokeThicknes = 12;     //for text objects is FontSize
                break;

            case LineStudy.StudyTypeEnum.VerticalLine:
                //when first parameter is false, vertical line will display DataTime instead on record number
                args = new object[]
                {
                    false,  //true - show record number, false - show datetime
                    true,   //true - show text with line, false - show only line
                    "d",    //custom datetime format, when args[0] == false. See MSDN:DateTime.ToString(string) for legal values
                };
                break;

            case LineStudy.StudyTypeEnum.ImageObject:
                args = new object[]
                {
                    "Res/open.png"
                };
                break;

            default:
                break;
            }

            string studyName = studyTypeEnum.ToString();
            int    count     = _stockChartX.GetLineStudyCountByType(studyTypeEnum);

            if (count > 0)
            {
                studyName += count;
            }
            LineStudy lineStudy = _stockChartX.AddLineStudy(studyTypeEnum, studyName, new SolidColorBrush(colorPicker.SelectedColor), args);

            lineStudy.StrokeThickness = strokeThicknes;

            switch (studyTypeEnum)
            {
            case LineStudy.StudyTypeEnum.StaticText:
                //if linestudy is a text object we can change its text directly
                ((StaticText)lineStudy).Text = "Some other text for testing";
                break;

            case LineStudy.StudyTypeEnum.HorizontalLine:
                //change the appearance of horizontal Line
                lineStudy.StrokeType = LinePattern.DashDot;
                break;

            case LineStudy.StudyTypeEnum.ImageObject:
                //set an additional ImageAlign property, this is very usefull when setting
                //images for close and open price, when you want to put image below or above a candle
                //for Open price you'd use ImageObject.ImageAlign.BottomMiddle
                //for Close price you'd use ImageObject.ImageAlign.TopMiddle
                ((ImageObject)lineStudy).Align = ImageObject.ImageAlign.Center;
                break;
            }

            btnAddLineStudy.IsEnabled = false;

            if (studyTypeEnum == LineStudy.StudyTypeEnum.HorizontalLine)
            {
                lineStudy.ValuePresenterAlignment = LineStudy.ValuePresenterAlignmentType.Left;
                lineStudy.LineStudyValue          = new CustomHorLineValueGetter(_stockChartX);
            }
        }