Page 1 of 1

OnClickSeries not detecting up candles correctly

Posted: Fri Dec 12, 2003 1:03 pm
by 9079470
In a chart displaying a candle series, I think there is something wrong with the hit testing for "up" candles. It seems that these are only detected if the mouse is directly over the candle centre line but not anywhere else in the candle body. The hit testing seems to work correctly for "down" candles though.

The problem affects, OnClickSeries, OnMouseEnterSeries events and also the ISeries>>GetMousePointer() method.

I'm using TeeChart v6 and I've also set a custom candle width via ICandleSeries>>CandleWidth() if that makes any difference. Is there, perhaps, a workaround for this problem or will I need to wait for a future bug fix to become available.

Thanks in advance

Posted: Mon Dec 15, 2003 6:53 am
by Marc
Hello,

Thanks for letting us know. This seems to be a problem and has been logged to be fixed.

With regards to workarounds, if the Candle is set as 1 pixel width Bar not Stick the hit rate is 100% (and hence a clue to where the internal problem lies).

A 'long' workaround (this works) would be to check clicks against a calculation made of each Candle Rectangle. Steps would include sending the X,Y click to a routine that steps through visible Series points

Eg.

Code: Select all

Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal x As Long, ByVal y As Long)
  vIdx = CheckCandlePoint(x, y)
  TChart1.Repaint
End Sub

Private Function CheckCandlePoint(ByVal x As Integer, ByVal y As Integer) As Integer

  Dim openValY, closeValY

  With TChart1
    i = -1
    For i = .Series(0).FirstValueIndex To .Series(0).LastValueIndex
    
      openValY = .Series(0).CalcYPosValue(.Series(0).asCandle.OpenValues.Value(i))
      closeValY = .Series(0).CalcYPosValue(.Series(0).asCandle.CloseValues.Value(i))
      
      If openValY < closeValY Then
        topY = openValY
        bottomY = closeValY
      Else
        topY = closeValY
        bottomY = openValY
      End If
    
      If x > .Series(0).CalcXPos(i) - (.Series(0).asCandle.CandleWidth / 2) And _
         x < .Series(0).CalcXPos(i) + (.Series(0).asCandle.CandleWidth / 2) And _
         y > topY And y < bottomY Then
        CheckCandlePoint = i
      End If
    Next i
  
  End With
End Function
If you prefer to make the click sensitive to the entire area between high and low values instead of the open and close rectangle then simply replace in highValues and lowValues for the Open and CloseValues in the calculation above.

Regards,
Marc Meumann
Steema Support