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

# GetBarIdxByTime()

## Definition

Returns the **ChartBars** index value calculated from the time parameter provided.

## Method Return Value

An **int** representing the bar index value at a specific time.

## Syntax

`ChartBars.GetBarIdxByTime(ChartControl chartControl, DateTime time)`

## Method Parameters

| Parameter        | Description                                                         |
| ---------------- | ------------------------------------------------------------------- |
| **chartControl** | The **ChartControl** object used to determine the chart's time axis |
| **time**         | The **DateTime** value used to convert to a ChartBar index value    |

## Examples

```csharp

protected override void OnBarUpdate()
{
   if (ChartBars != null)
   {
     Print(ChartBars.GetBarIdxByTime(ChartControl, Time[0]));  
   }
}
```