Page 1 of 1

Moving Average .XScreenToValue

Posted: Mon May 23, 2005 8:05 am
by 9083304
Sorry to seem lazy but I am pressed for time.
I plot a price line which has 751 points. Of which 250 are visible at any one time to user.
I add a 21 day moving average.
As user moves mouse pointer (the requirement is to be able to do this WITHOUT a cursor) I need to update a 'data window' to show the Y values at the current mouse point.
I use .Series(SeriesIndex).XScreenToValue(X) to determine the index value to pass to .YValues
This works fine for the main line, but when I use the same logic for the moving average it is out by the period (ie, 21).
As there may be many series plotted is there a way to write a generic piece of code that will return the value for the series relative to the pointer? Thanks again.

Posted: Mon May 23, 2005 9:44 am
by narcis
Hi Rossmc,

You could use something like:

Code: Select all

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
    Dim ValuesStr As String

    If TChart1.Series(0).Clicked(X, Y) <> -1 Then
        ValuesStr = "X: " + CStr(TChart1.Series(0).XValues.Value(TChart1.Series(0).Clicked(X, Y))) _
                + ", Y: " + CStr(TChart1.Series(0).YValues.Value(TChart1.Series(0).Clicked(X, Y)))
    
        TChart1.Header.Text.Clear
        TChart1.Header.Text.Add (ValuesStr)
    Else
        TChart1.Header.Text.Clear
        TChart1.Header.Text.Add ("")
    End If
End Sub