> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# GetClosestAnchor()

## Definition

Returns the closest chart anchor within a specified maximum distance from the mouse cursor.

## Method Return Value

This method returns an existing **ChartAnchor**.

## Syntax

`GetClosestAnchor(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, double maxDist, Point point)`

## Method Parameters

| Parameter        | Description                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------ |
| **chartControl** | A **ChartControl** representing the x-axis                                                 |
| **chartPanel**   | A **ChartPanel** representing the panel for the chart                                      |
| **chartScale**   | A **ChartScale** representing the y-axis                                                   |
| **maxDist**      | A **double** value representing the cursor's sensitivity used to detect the nearest anchor |
| **point**        | A **Point** in device pixels representing the current mouse cursor position                |

## Examples

```csharp

public override Cursor GetCursor(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, Point point)
{
   // get the closest anchor to where the user has clicked
   ChartAnchor closest = GetClosestAnchor(chartControl, chartPanel, chartScale, 10, point);

   if (closest != null)
   {
     // set cursor to indicate that it can be moved
     return Cursors.SizeNWSE;
   }
   // otherwise set cursor back to arrow
   else return Cursors.Arrow;
```