Back to Devexpress

FibonacciIndicator Class

corelibraries-devexpress-dot-xtracharts-c8a3d9e9.md

latest17.0 KB
Original Source

FibonacciIndicator Class

Represents an individual Fibonacci Indicator.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public class FibonacciIndicator :
    FinancialIndicator,
    IFibonacciIndicatorBehavior
vb
Public Class FibonacciIndicator
    Inherits FinancialIndicator
    Implements IFibonacciIndicatorBehavior

The following members return FibonacciIndicator objects:

Remarks

Objects of the FibonacciIndicator class are contained in the IndicatorCollection returned by the XYDiagram2DSeriesViewBase.Indicators property.

To create a Fibonacci Indicator, it is necessary to specify its FinancialIndicator.Point1 and FinancialIndicator.Point2 properties. And, each point is defined by its FinancialIndicatorPoint.Argument and FinancialIndicatorPoint.ValueLevel properties.

There following Fibonacci Indicator kinds (specified via the FibonacciIndicator.Kind property) are available: Fibonacci Arcs , Fibonacci Fans and Fibonacci Retracement.

The appearance of a Fibonacci Indicator is determined by its Indicator.Color and Indicator.LineStyle properties. And, for the indicator’s additional levels (which depend on the indicator’s kind), the following properties are available: FibonacciIndicator.BaseLevelColor and FibonacciIndicator.BaseLevelLineStyle.

For more information, see Fibonacci Indicators.

Example

This example demonstrates how to create a Fibonacci Indicator of a certain kind (Arcs, Fans or Retracements), and add it to a financial series.

To do this, create an instance of the FibonacciIndicator class, and specify its FibonacciIndicator.Kind property. Then, add this indicator to the series collection of indicators, returned by the XYDiagram2DSeriesViewBase.Indicators property.

csharp
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace FibonacciIndicators {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        #region Initialization
        private void Form1_Load(object sender, EventArgs e) {
            // Create a series.
            Series series = new Series("Stock", ViewType.Stock);
            series.ArgumentScaleType = ScaleType.DateTime;

            // Populate the series with data.
            AddPoints(series);

            // Add it to the chart.
            this.chartControl1.Series.Add(series);

            // Adjust the chart's appearance.
            XYDiagram diagram = (XYDiagram)this.chartControl1.Diagram;
            diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;
            diagram.AxisX.Label.Staggered = true;
        }
        #endregion

        #region Providing Data
        private void AddPoints(Series series) {
            series.Points.AddRange(new SeriesPoint[] {
                new SeriesPoint(new DateTime(2007, 12, 24), new object[] {110.55, 112, 111.3, 111.65}),
                new SeriesPoint(new DateTime(2007, 12, 26), new object[] {110.9, 112.09, 110.9, 111.56}),
                new SeriesPoint(new DateTime(2007, 12, 27), new object[] {109.49, 111.3, 110.53, 109.6}),
                new SeriesPoint(new DateTime(2007, 12, 28), new object[] {109.108, 110.76, 110.76, 110.09}),
                new SeriesPoint(new DateTime(2007, 12, 31), new object[] {107.26, 110, 109.51, 108.1}),
                new SeriesPoint(new DateTime(2008, 1, 2), new object[] {104.17, 108.99, 108.99, 104.69}),
                new SeriesPoint(new DateTime(2008, 1, 3), new object[] {103.98, 105.57, 104.83, 104.9}),
                new SeriesPoint(new DateTime(2008, 1, 4), new object[] {100.48, 103.95, 103.95, 101.13}),
                new SeriesPoint(new DateTime(2008, 1, 7), new object[] {99.03, 101, 100.25, 100.05}),
                new SeriesPoint(new DateTime(2008, 1, 8), new object[] {97.17, 100.38, 100.05, 97.59}),
                new SeriesPoint(new DateTime(2008, 1, 9), new object[] {97.16, 99.15, 97.76, 98.31}),
                new SeriesPoint(new DateTime(2008, 1, 10), new object[] {97.15, 100.86, 97.39, 99.92}),
                new SeriesPoint(new DateTime(2008, 1, 11), new object[] {97.09, 99.46, 99.2, 97.67}),
                new SeriesPoint(new DateTime(2008, 1, 14), new object[] {101.33, 105.59, 105.01, 102.93}),
                new SeriesPoint(new DateTime(2008, 1, 15), new object[] {101.23, 104.04, 102.03, 101.83}),
                new SeriesPoint(new DateTime(2008, 1, 16), new object[] {100.14, 102.86, 100.14, 101.63}),
                new SeriesPoint(new DateTime(2008, 1, 17), new object[] {100.05, 103.45, 102, 101.1}),
                new SeriesPoint(new DateTime(2008, 1, 18), new object[] {102.5, 106.72, 106.72, 103.4}),
                new SeriesPoint(new DateTime(2008, 1, 22), new object[] {98.55, 103.09, 98.55, 101.22}),
                new SeriesPoint(new DateTime(2008, 1, 23), new object[] {98.5, 106.335, 99.63, 106.1}),
                new SeriesPoint(new DateTime(2008, 1, 24), new object[] {104.68, 107.51, 106.38, 106.91}),
                new SeriesPoint(new DateTime(2008, 1, 25), new object[] {104.1, 107.79, 107.79, 104.52}),
                new SeriesPoint(new DateTime(2008, 1, 28), new object[] {103.83, 105.77, 104.44, 104.98}),
                new SeriesPoint(new DateTime(2008, 1, 29), new object[] {104.6, 106.8, 105.5, 106.1}),
                new SeriesPoint(new DateTime(2008, 1, 30), new object[] {104.855, 107.65, 105.85, 105.65}),
                new SeriesPoint(new DateTime(2008, 1, 31), new object[] {103.7, 107.97, 104.21, 107.11})
             });
        }
        #endregion

        #region Processing Button_Click
        private void btnArcs_Click(object sender, EventArgs e) {
            AddIndicator(chartControl1.Series[0], FibonacciIndicatorKind.FibonacciArcs);
        }

        private void btnFans_Click(object sender, EventArgs e) {
            AddIndicator(chartControl1.Series[0], FibonacciIndicatorKind.FibonacciFans);
        }

        private void btnRetracements_Click(object sender, EventArgs e) {
            AddIndicator(chartControl1.Series[0], FibonacciIndicatorKind.FibonacciRetracement);
        }
        #endregion

        private void AddIndicator(Series ser, FibonacciIndicatorKind kind) {
            // Get a collection of indicators.
            IndicatorCollection indicators =
                ((StockSeriesView)ser.View).Indicators;

            // Clear it.
            indicators.Clear();

            // Add a new indicator to it.
            indicators.Add(CreateIndicator(kind, new DateTime(2007, 12, 27), 
                new DateTime(2008, 1, 17), ValueLevel.High));
        }

        private FibonacciIndicator CreateIndicator(FibonacciIndicatorKind kind,
            DateTime arg1, DateTime arg2, ValueLevel level) {

            // Create the Fibonacci Indicator of the specified kind.
            FibonacciIndicator fi = new FibonacciIndicator(kind);

            // Specify its start and end points.
            fi.Point1.Argument = arg1;
            fi.Point1.ValueLevel = level;
            fi.Point2.Argument = arg2;
            fi.Point2.ValueLevel = level;

            // Select the name.
            switch (fi.Kind) {
                case FibonacciIndicatorKind.FibonacciArcs: {
                        fi.Name = "Arcs";
                        break;
                    }
                case FibonacciIndicatorKind.FibonacciFans: {
                        fi.Name = "Fans";
                        break;
                    }
                case FibonacciIndicatorKind.FibonacciRetracement: {
                        fi.Name = "Retracement";
                        break;
                    }
            }

            // Make all its levels visible.
            fi.ShowLevel23_6 = true;
            fi.ShowLevel76_4 = true;
            fi.ShowLevel0 = true;
            fi.ShowLevel100 = true;
            fi.ShowAdditionalLevels = true;

            // Customize its appearance.
            fi.BaseLevelColor = Color.Green;
            fi.BaseLevelLineStyle.DashStyle = DashStyle.Dash;

            return fi;
        }
    }
}
vb
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts

Namespace FibonacciIndicators
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        #Region "Initialization"
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create a series.
            Dim series As New Series("Stock", ViewType.Stock)
            series.ArgumentScaleType = ScaleType.DateTime

            ' Populate the series with data.
            AddPoints(series)

            ' Add it to the chart.
            Me.chartControl1.Series.Add(series)

            ' Adjust the chart's appearance.
            Dim diagram As XYDiagram = CType(Me.chartControl1.Diagram, XYDiagram)
            diagram.AxisY.WholeRange.AlwaysShowZeroLevel = False
            diagram.AxisX.Label.Staggered = True
        End Sub
        #End Region

        #Region "Providing Data"
        Private Sub AddPoints(ByVal series As Series)
            series.Points.AddRange(New SeriesPoint() { _
                New SeriesPoint(New Date(2007, 12, 24), New Object() {110.55, 112, 111.3, 111.65}), _
                New SeriesPoint(New Date(2007, 12, 26), New Object() {110.9, 112.09, 110.9, 111.56}), _
                New SeriesPoint(New Date(2007, 12, 27), New Object() {109.49, 111.3, 110.53, 109.6}), _
                New SeriesPoint(New Date(2007, 12, 28), New Object() {109.108, 110.76, 110.76, 110.09}), _
                New SeriesPoint(New Date(2007, 12, 31), New Object() {107.26, 110, 109.51, 108.1}), _
                New SeriesPoint(New Date(2008, 1, 2), New Object() {104.17, 108.99, 108.99, 104.69}), _
                New SeriesPoint(New Date(2008, 1, 3), New Object() {103.98, 105.57, 104.83, 104.9}), _
                New SeriesPoint(New Date(2008, 1, 4), New Object() {100.48, 103.95, 103.95, 101.13}), _
                New SeriesPoint(New Date(2008, 1, 7), New Object() {99.03, 101, 100.25, 100.05}), _
                New SeriesPoint(New Date(2008, 1, 8), New Object() {97.17, 100.38, 100.05, 97.59}), _
                New SeriesPoint(New Date(2008, 1, 9), New Object() {97.16, 99.15, 97.76, 98.31}), _
                New SeriesPoint(New Date(2008, 1, 10), New Object() {97.15, 100.86, 97.39, 99.92}), _
                New SeriesPoint(New Date(2008, 1, 11), New Object() {97.09, 99.46, 99.2, 97.67}), _
                New SeriesPoint(New Date(2008, 1, 14), New Object() {101.33, 105.59, 105.01, 102.93}), _
                New SeriesPoint(New Date(2008, 1, 15), New Object() {101.23, 104.04, 102.03, 101.83}), _
                New SeriesPoint(New Date(2008, 1, 16), New Object() {100.14, 102.86, 100.14, 101.63}), _
                New SeriesPoint(New Date(2008, 1, 17), New Object() {100.05, 103.45, 102, 101.1}), _
                New SeriesPoint(New Date(2008, 1, 18), New Object() {102.5, 106.72, 106.72, 103.4}), _
                New SeriesPoint(New Date(2008, 1, 22), New Object() {98.55, 103.09, 98.55, 101.22}), _
                New SeriesPoint(New Date(2008, 1, 23), New Object() {98.5, 106.335, 99.63, 106.1}), _
                New SeriesPoint(New Date(2008, 1, 24), New Object() {104.68, 107.51, 106.38, 106.91}), _
                New SeriesPoint(New Date(2008, 1, 25), New Object() {104.1, 107.79, 107.79, 104.52}), _
                New SeriesPoint(New Date(2008, 1, 28), New Object() {103.83, 105.77, 104.44, 104.98}), _
                New SeriesPoint(New Date(2008, 1, 29), New Object() {104.6, 106.8, 105.5, 106.1}), _
                New SeriesPoint(New Date(2008, 1, 30), New Object() {104.855, 107.65, 105.85, 105.65}), _
                New SeriesPoint(New Date(2008, 1, 31), New Object() {103.7, 107.97, 104.21, 107.11}) _
            })
        End Sub
        #End Region

        #Region "Processing Button_Click"
        Private Sub btnArcs_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnArcs.Click
            AddIndicator(chartControl1.Series(0), FibonacciIndicatorKind.FibonacciArcs)
        End Sub

        Private Sub btnFans_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnFans.Click
            AddIndicator(chartControl1.Series(0), FibonacciIndicatorKind.FibonacciFans)
        End Sub

        Private Sub btnRetracements_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRetracements.Click
            AddIndicator(chartControl1.Series(0), FibonacciIndicatorKind.FibonacciRetracement)
        End Sub
        #End Region

        Private Sub AddIndicator(ByVal ser As Series, ByVal kind As FibonacciIndicatorKind)
            ' Get a collection of indicators.
            Dim indicators As IndicatorCollection = CType(ser.View, StockSeriesView).Indicators

            ' Clear it.
            indicators.Clear()

            ' Add a new indicator to it.
            indicators.Add(CreateIndicator(kind, New Date(2007, 12, 27), New Date(2008, 1, 17), ValueLevel.High))
        End Sub

        Private Function CreateIndicator(ByVal kind As FibonacciIndicatorKind, ByVal arg1 As Date, ByVal arg2 As Date, ByVal level As ValueLevel) As FibonacciIndicator

            ' Create the Fibonacci Indicator of the specified kind.
            Dim fi As New FibonacciIndicator(kind)

            ' Specify its start and end points.
            fi.Point1.Argument = arg1
            fi.Point1.ValueLevel = level
            fi.Point2.Argument = arg2
            fi.Point2.ValueLevel = level

            ' Select the name.
            Select Case fi.Kind
                Case FibonacciIndicatorKind.FibonacciArcs
                        fi.Name = "Arcs"
                        Exit Select
                Case FibonacciIndicatorKind.FibonacciFans
                        fi.Name = "Fans"
                        Exit Select
                Case FibonacciIndicatorKind.FibonacciRetracement
                        fi.Name = "Retracement"
                        Exit Select
            End Select

            ' Make all its levels visible.
            fi.ShowLevel23_6 = True
            fi.ShowLevel76_4 = True
            fi.ShowLevel0 = True
            fi.ShowLevel100 = True
            fi.ShowAdditionalLevels = True

            ' Customize its appearance.
            fi.BaseLevelColor = Color.Green
            fi.BaseLevelLineStyle.DashStyle = DashStyle.Dash

            Return fi
        End Function
    End Class
End Namespace

Implements

IXtraSerializable

Inheritance

Object ChartElement ChartElementNamed Indicator FinancialIndicator FibonacciIndicator

See Also

FibonacciIndicator Members

Fibonacci Indicators

DevExpress.XtraCharts Namespace