Page 1 of 1

Point & Figure Chart with Reversal Dates

Posted: Fri Aug 20, 2004 12:00 am
by 8124495
Hi, we've been trying for a while to use the point and figure charts, and to also display the reversal date in the bottom axis, instead of just having the points labelled 0, 1, 2, 3, ...

Setting a Date Field to the Labels member of the series doesn't help - it doesnt seem to be used in the transformation to P&F format.

Tomato

Posted: Fri Aug 20, 2004 12:30 pm
by Chris
Hi --
Hi, we've been trying for a while to use the point and figure charts, and to also display the reversal date in the bottom axis, instead of just having the points labelled 0, 1, 2, 3, ...
You could try the GetAxisLabel event, e.g.

Code: Select all

private void Form1_Load(object sender, System.EventArgs e) {
	Random r = new Random();
	double tmpOpen = r.Next(1000);
	double tmpClose;
	DateTime dt = DateTime.Today;
	TimeSpan ts = TimeSpan.FromDays(1);
	for (int t=0;t<13;t++) {
		tmpOpen += r.Next(100) - 50.0;
		tmpClose = tmpOpen - r.Next(100) + 50.0;
		pointFigure1.Add(dt,tmpOpen,tmpOpen + r.Next(10),tmpClose -r.Next(10),tmpClose);
		dt += ts;
	}

	tChart1.Axes.Bottom.Labels.Angle = 90;
}



private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e) {
	switch(e.LabelText) {
		case "0":
			e.LabelText = DateTime.Today.ToString("dd/MM/yy");
			break;
	}
}

Posted: Wed Sep 01, 2004 11:51 pm
by 8124495
Interesting.

I see this will enable me to manually set the label on the horizontal axis, but my problem is retrieving the date of the reversal for the point and figure series. Currently it still looks like I will have to manually calculate the point and figure chart to be able to record the reversal date (hoping that I have the same algorithm as the TChart uses).

Posted: Fri Sep 10, 2004 1:48 pm
by Chris
Hi,
I see this will enable me to manually set the label on the horizontal axis, but my problem is retrieving the date of the reversal for the point and figure series. Currently it still looks like I will have to manually calculate the point and figure chart to be able to record the reversal date (hoping that I have the same algorithm as the TChart uses).
I'm assuming here that a reversal date is the date at which a new PointFigure column is drawn.

TeeChart uses the following algorithm to calculate the number of columns drawn:

Code: Select all

 
private int CalcMaxColumns(bool draw) 
    {
      if (Count>0) 
      {
        double tmpDistance=ReversalAmount*BoxSize;

        double tmpLow=LowValues.Value[0];
        double tmpHigh=HighValues.Value[0];
        int tmpCol=0;
        double tmp;

        int tmpX=0;

        if (draw) 
        {
          tmpX=CalcXPosValue(tmpCol);
          DrawColumn(down,tmpLow,tmpHigh,tmpX);
        }

        bool tmpIsDown=true;

        for (int t=1; t<Count; t++) 
        {
                            
          if (tmpIsDown) 
          {
            tmp=LowValues.Value[t];
            if (tmp<=(tmpLow-BoxSize)) 
            {
              if (draw)
                DrawColumn(down,tmp,tmpLow-BoxSize,tmpX);
              tmpLow=tmp;
            }
            else 
            {
              tmp=HighValues.Value[t];
              if (tmp>=(tmpLow+tmpDistance)) 
              {
                tmpCol++;
                tmpHigh=tmp;
                if (draw) 
                {
              
                  tmpX=CalcXPosValue(tmpCol);
                  DrawColumn(up,tmpLow+BoxSize,tmpHigh,tmpX);
                }
                tmpIsDown=false;
              }
            }
          }
          else 
          {
            tmp=HighValues.Value[t];
            if (tmp>=(tmpHigh+BoxSize))
            {
              if (draw)
                DrawColumn(up,tmpHigh+BoxSize,tmp,tmpX);
              tmpHigh=tmp;
            }
            else
            {
              tmp=LowValues.Value[t];
              if (tmp<=(tmpHigh-tmpDistance)) 
              {
                tmpCol++;
                tmpLow=tmp;
                if (draw) 
                {
                  tmpX=CalcXPosValue(tmpCol);
                  DrawColumn(down,tmpLow,tmpHigh-BoxSize,tmpX);
                }
                tmpIsDown=true;
              }
            }
          }
        }

        return tmpCol+1;
      }
      else return 0;
    }
DrawColumn just uses Graphics stuff to do the actual painting. CalcMaxColumns is also called by the public PointFigure property, MaxXValue():

Code: Select all

public override double MaxXValue()
    {
      return CalcMaxColumns(false)-1;
    }
At the moment I don't think there's any way to use TeeChart PointFigure methods/properties to calculate the reversal dates.

Success!

Posted: Fri Sep 17, 2004 12:34 am
by 8124495
Ok, I ran a modified version of CalcMaxColumns in order to record the reversal dates.
Ignoring the Draw commands (since I wasn't doing the drawing), I created an array to store the desired labels. Whenever the column for the P&F changed, I would write a (formatted) date to this array, fetching the Date from the date series corresponding to the data.
I ran this function when I was adding the series to the chart, and stored the array as a module level variable.
Then I used the AxisGetLabel event to format the label text.

Code: Select all

    Private Function CalcHorizontalLabels(ByVal pSeries As Steema.TeeChart.Styles.PointFigure) As ArrayList
        'Return Array of Labels to use for Horizontal Axis 
        Try
            If pSeries.Count > 0 Then
                Dim lLabels As New ArrayList
                Dim lReversalDistance As Double = mReversal * mBoxSize
                Dim lColumn As Integer = 0, lIndex As Integer
                Dim lIsDown As Boolean = True, lTemp As Double

                'Initial Start of First Column
                Dim lLow As Single = pSeries.LowValues.Item(0)
                Dim lHigh As Single = pSeries.HighValues.Item(0)
                Dim lLabel As String
                lLabel = Date.FromOADate(pSeries.DateValues.Item(0)).ToString(gDateFormatLong)
                lLabels.Add(lLabel) 'Put Formatted Date Label into Output Array

                'Loop through rest of Data
                For lIndex = 1 To pSeries.Count - 1
                    If lIsDown Then
                        lTemp = pSeries.LowValues.Item(lIndex)
                        If (lTemp <= (lLow - mBoxSize)) Then
                            lLow = lTemp
                        Else
                            lTemp = pSeries.HighValues.Item(lIndex)
                            If (lTemp >= (lLow + lReversalDistance)) Then
                                lColumn += 1 'When Column is incremented, then we want to record a new label for new column
                                lLabel = Date.FromOADate(pSeries.DateValues.Item(lIndex)).ToString(gDateFormatLong)
                                lLabels.Add(lLabel) 'Put Formatted Date Label into Output Array
                                lHigh = lTemp
                                lIsDown = False
                            End If
                        End If
                    Else
                        lTemp = pSeries.HighValues.Item(lIndex)
                        If (lTemp >= (lHigh + mBoxSize)) Then
                            lHigh = lTemp
                        Else
                            lTemp = pSeries.LowValues.Item(lIndex)
                            If (lTemp <= (lHigh - lReversalDistance)) Then
                                lColumn += 1 'When Column is incremented, then we want to record a new label for new column
                                lLabel = Date.FromOADate(pSeries.DateValues.Item(lIndex)).ToString(gDateFormatLong)
                                lLabels.Add(lLabel) 'Put Formatted Date Label into Output Array
                                lLow = lTemp
                                lIsDown = True
                            End If
                        End If
                    End If
                Next lIndex

                CalcHorizontalLabels = lLabels
            Else
                CalcHorizontalLabels = Nothing
            End If
        Catch ex As Exception
            Globals.WriteError(ex.ToString)
        End Try
    End Function

Code: Select all

    Private Sub TChart1_GetAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.GetAxisLabelEventArgs) Handles TChart1.GetAxisLabel
        'Write Reversal Dates from Labels Array into Horizontal Axis
        Try
            Dim lAxis As Steema.TeeChart.Axis = sender

            If Not (lAxis Is Nothing) AndAlso (lAxis Is TChart1.Axes.Bottom) Then
                Dim lLabel As String = e.LabelText
                If IsNumeric(lLabel) Then
                    Dim lIndex As Integer = CInt(lLabel)
                    If Not mLabels Is Nothing AndAlso (CDbl(lLabel) = lIndex) AndAlso mLabels.Count > lIndex Then
                        e.LabelText = mLabels(lIndex)
                    End If
                End If
            End If
        Catch ex As Exception
            Globals.WriteError(ex.ToString)
        End Try
    End Sub