ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  CCI Indicator error
Posted by Mahbub on Jan-26-2011 12:45
Attachments:
Dear Sir, I have an excell sheet (collected from stockcharts.com) for calculating CCI (Commodity Channel Index). But the value is different from your chart. I've attached the necessary files. Please provide me your's calculation technique in excell. It'll be very much helpful for me.

Thanks
CCI.zip
CCI.zip

59.36 Kb

  Re: CCI Indicator error
Posted by Peter Kwan on Jan-27-2011 01:53
Hi Mahbub,

I confirm that this is in fact due to a bug in the ChartDirector FinanceChart class library.

To solve the problem, please put the following in your code. It creates a local class also called FinanceChart that inherits from ChartDirector.FinanceChart, and it overrides the addCCI method of the ChartDirector.FinanceChart. The overrided addCCI method is modified from the original FinanceChart source code (which is included in the ChartDirector download) and should fix the issue you encountered.

When your code uses "New FinanceChart", it should automatically choose the local FinanceChart (instead of ChartDirector.FinanceChart) as per VB.NET scope rules.


Class FinanceChart
    Inherits ChartDirector.FinanceChart

Private Dim m_highData As Double()
Private Dim m_lowData As Double()
Private Dim m_closeData As Double()

Public Sub New(ByVal width As Integer)
MyBase.New(width)
End Sub

    Public Sub setData(timeStamps As Double(), highData As Double(), lowData As Double(), _
       openData As Double(), closeData As Double(), volData() As Double, extraPoints As Integer)
        MyBase.setData(timeStamps, highData, lowData, openData, closeData, volData, extraPoints)
     m_highData = highData
     m_lowData = lowData
     m_closeData = closeData
    End Sub

Public Function addCCI(height As Integer, period As Integer, color As Integer, range As Double, _
upColor As Integer, downColor As Integer) As XYChart
        Dim tp As Double() = New ArrayMath(m_highData).add(m_lowData).add(m_closeData).div(3).result()

        Dim smvtp As Double() = New ArrayMath(tp).movAvg(period).result()

        Dim movMeanDev(UBound(smvtp)) As Double
        Dim i As Integer
        For i = 0 To Ubound(smvtp)
            Dim avg As Double = smvtp(i)
            if avg = Chart.NoValue Then
                movMeanDev(i) = Chart.NoValue
            Else
                Dim currentIndex As Integer = i
                Dim count As Integer = period - 1
                Dim acc As Double = 0

                Do while (count >= 0) And (currentIndex >= count)
                    Dim currentValue As Double = tp(currentIndex)
                    currentIndex = currentIndex - 1
                    If currentValue <> Chart.NoValue Then
                        count = count - 1
                        acc = acc + Math.Abs(avg - currentValue)
                    End If
                Loop

                if count > 0 Then
                    movMeanDev(i) = Chart.NoValue
                Else
                    movMeanDev(i) = acc / period
                End If
            End If
        Next

        Dim c As XYChart = addIndicator(height)
        Dim label As String = "CCI (" & period & ")"
        Dim layer As LineLayer = addLineIndicator2(c, New ArrayMath(tp).sub(smvtp).financeDiv( _
            movMeanDev, 0).div(0.015).result(), color, label)
        addThreshold(c, layer, range, upColor, -range, downColor)
        Return c
    End Function

End Class


Hope this can help.

Regards
Peter Kwan

  Re: CCI Indicator error
Posted by Mahbub on Jan-27-2011 10:29
Hello Peter, Thanks for reply.

If I use other indicators in the same form, same chart object, what will happen? will they remain undisturbed?

  Re: CCI Indicator error
Posted by Peter Kwan on Jan-27-2011 11:25
Hi Mahbub,

The code I suggested will not affect other indicators, as it only overrides the addCCI method.

Regards
Peter Kwan

  Re: CCI Indicator error
Posted by Mahbub on Jan-27-2011 17:53
Thanks a lot for providing such a nice software.