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

# GetSlotIndexByTime()

## Definition

Returns the slot index relative to the chart control corresponding to a specified time value.

Notes:

* A "Slot" is used in Equidistant [bar spacing](/developer/desktop-sdk/references/common/charts/chartcontrol/barspacingtype) 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.GetBarIdxByTime()](/developer/desktop-sdk/references/common/charts/chartbars/getbaridxbytime).

## Method Return Value

A double representing a slot index.

## Syntax

`\<chartcontrol\>.GetSlotIndexByTime(DateTime time)`

This method CANNOT be called on BarSpacingType.TimeBased charts. You will need to ensure an Equidistant [bar spacing type](/developer/desktop-sdk/references/common/charts/chartcontrol/barspacingtype) is used, otherwise errors will be thrown.

## Method Parameters

| Parameter | Description                                                                                                                      |
| --------- | -------------------------------------------------------------------------------------------------------------------------------- |
| **time**  | A [DateTime](https://msdn.microsoft.com/en-us/library/system.datetime\(v=vs.110\).aspx) Structure used to determine a slot index |

## Examples

```csharp
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
    // ensure that GetSlotIndexByTime is called on TimeBased charts
    if(chartControl.BarSpacingType != BarSpacingType.TimeBased)
    {
        // get the slot index of the first time painted on the chart
        double slotIndex = chartControl.GetSlotIndexByTime(chartControl.FirstTimePainted);
        
        Print(slotIndex);
    }
}
```