ComponentOne FinancialChart for UWP Edition
Commodity Channel Index
Analytics > Indicators > Commodity Channel Index

Commodity Channel Index (CCI) indicator is an oscillator that measures an asset's current price level relative to an average price level over a specified period of time. It is used to determine a new trend or to warn about extreme conditions.

In FinancialChart, you need to use a CCI object to work with Commodity Channel Index. FinancialChart also enables you to fetch the calculated CCI values at run-time using GetValues() method. This can help in creating alerts in application or maintaining logs while working with dynamic data.

See the following code snippet that demonstrates how you can use CCI indicator. The code snippet uses a class DataService.cs whose code can be seen by referring to Average True Tange. 

Partial Public Class Indicators
    Inherits Page
    Private dataService As DataService = dataService.GetService()

    Private rsi As New RSI() With {
        .SeriesName = "RSI"
    }
    Public Sub New()
        InitializeComponent()
    End Sub

    Public ReadOnly Property Data() As List(Of Quote)
        Get
            Return dataService.GetSymbolData("box")
        End Get
    End Property

    Public ReadOnly Property IndicatorType() As List(Of String)
        Get
            Return New List(Of String)() From {
                "Relative Strength Index",
            }
        End Get
    End Property

    Sub OnIndicatorTypeSelectionChanged(sender As Object, e As SelectionChangedEventArgs)
        Dim ser As FinancialSeries = Nothing

        If cbIndicatorType.SelectedIndex = 1 Then
            ser = rsi
        End If

        If ser IsNot Nothing AndAlso Not indicatorChart.Series.Contains(ser) Then
            indicatorChart.BeginUpdate()
            indicatorChart.Series.Clear()
            indicatorChart.Series.Add(ser)
            indicatorChart.EndUpdate()
        End If
    End Sub

    Sub OnCbPeriodValueChanged(sender As Object, e As PropertyChangedEventArgs(Of Double))
        rsi.Period = 14
    End Sub

    Sub OnFinancialChartRendered(sender As Object, e As RenderEventArgs)
        If indicatorChart IsNot Nothing Then
            indicatorChart.AxisX.Min = (CType(financialChart.AxisX, IAxis)).GetMin()
            indicatorChart.AxisX.Max = (CType(financialChart.AxisX, IAxis)).GetMax()
        End If
    End Sub
End Class
public partial class Indicators : Page
{
    DataService dataService = DataService.GetService();
    CCI cci = new CCI() { SeriesName = "CCI" };

    public Indicators()
    {
        InitializeComponent();
    }

    public List<Quote> Data
    {
        get
        {
            return dataService.GetSymbolData("box");
        }
    }

    public List<string> IndicatorType
    {
        get
        {
            return new List<string>()
            {
                "Commodity Channel Index",
            };
        }
    }

    void OnIndicatorTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        FinancialSeries ser = null;
        if (cbIndicatorType.SelectedIndex == 0)
            ser = cci;

        if (ser != null && !indicatorChart.Series.Contains(ser))
        {
            indicatorChart.BeginUpdate();
            indicatorChart.Series.Clear();
            indicatorChart.Series.Add(ser);
            indicatorChart.EndUpdate();
        }
    }

    void OnCbPeriodValueChanged(object sender, PropertyChangedEventArgs<double> e)
    {
        cci.Period = 14;
    }

    void OnFinancialChartRendered(object sender, RenderEventArgs e)
    {
        if (indicatorChart != null)
        {
            indicatorChart.AxisX.Min = ((IAxis)financialChart.AxisX).GetMin();
            indicatorChart.AxisX.Max = ((IAxis)financialChart.AxisX).GetMax();
        }
    }
}