Tyche Trading

Track Mouse Clicks

Bar Info

Debugging

Derivatives

Matrix Handling

Price Rounding

Regression Lines

Statistics

User Tracking

Example Strategies

Track Mouse Clicks

Description:

For getting the exact X and Y coordinates that some mouse clicked on their chart.

				
					protected override void OnStateChange()
{
    if (State == State.Historical)
    {
    	if (ChartControl != null)
    	{
    		foreach (ChartScale scale in ChartPanel.Scales)
    			if (scale.ScaleJustification == ScaleJustification)
    				chartScale = scale;
    
    		ChartControl.MouseLeftButtonDown += MouseClicked;
    	}
    }
    else if (State == State.Terminated)
    {
    	if (ChartControl != null)
    		ChartControl.MouseLeftButtonDown -= MouseClicked;
    }
}

private ChartScale chartScale;
private Point clickPoint = new Point();
private double convertedPrice;
private DateTime convertedTime;

protected void MouseClicked(object sender, MouseButtonEventArgs e)
{
	// convert e.GetPosition for different dpi settings
	clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.GetPosition(ChartControl as IInputElement).X, ChartControl.PresentationSource);
	clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPosition(ChartControl as IInputElement).Y, ChartControl.PresentationSource);

	convertedPrice = Instrument.MasterInstrument.RoundToTickSize(chartScale.GetValueByY((float)clickPoint.Y));

	convertedTime = ChartControl.GetTimeBySlotIndex((int)ChartControl.GetSlotIndexByX((int)clickPoint.X));

	Draw.TextFixed(this, "priceTime", string.Format("Price: {0}, Time: {1}", convertedPrice, convertedTime), TextPosition.BottomLeft);

	ForceRefresh();
}