> 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.

# GetSlotIndexByX()

## Definition

Returns the slot index relative to the chart control corresponding to a specified x-coordinate.

* A "Slot" is used in Equidistant **bar spacing** and represents a position on the chart canvas background which may or may not contain a bar. The concept of "Slots" does NOT exist on a **TimeBased** bar spacing type.
* If you are looking for information on a bar series, please see [ChartBars.GetBarIdxByX()](/developer/desktop-sdk/references/common/charts/chartbars/getbaridxbyx).
* Since the slot index is based on the chart canvas, the value returned by **GetSlotIndexByX()** can be expected to change as new bars are painted, or as the chart is scrolled backward or forward on the x-axis.

## Method Return Value

A double representing a slot index; returns -1 on a time based bar spacing type.

## Syntax

`\<chartcontrol\>.GetSlotIndexByX(int x)`

## Method Parameters

| Parameter | Description                           |
| --------- | ------------------------------------- |
| x         | An int used to determine a slot index |

## Examples

```csharp
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
    // Find the index of the bar painted at x-coordinate 35
    double slotIndex = chartControl.GetSlotIndexByX(35);
    
    // Print the slot index of the specified time
    Print(slotIndex);
}
```