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

# Getting indicator values from a specified time

## Getting indicator values from a specified time

Sometimes, you may want to access a value from a historical point in time, but have not kept track of the value to make this readily available. With **NinjaScript**, it is possible to pick a bar based on time to access that value. **GetBar()** returns the number of bars ago that holds the same timestamp of the time you request. This sample demonstrates how to get an indicator value from 9:30AM of the previous trading day.

## Key concepts in this example

* Obtaining a Simple Moving Average value from a specific time by referencing the bar number for that time.

## Important related documentation

* [GetBar()](/developer/desktop-sdk/references/common/bars/getbar)
* [Draw.Line()](/developer/desktop-sdk/references/common/drawing/draw-line)
* [Time](/developer/desktop-sdk/references/common/iseriest/timeseries/time)
* [Sessions](/developer/desktop-sdk/references/common/tradinghours/tradinghours-sessions)
* [DateTime](https://learn.microsoft.com/en-us/dotnet/api/system.datetime?view=netframework-4.8)

## Import instructions

1. Download the file contained in this Help Guide topic to your PC desktop.
2. From the Control Center window, select the menu Tools > Import > NinjaScript.
3. Select the downloaded file.

[SampleGetBar\_NT8.zip](https://ninjatrader.com/support/helpGuides/nt8/samples/SampleGetBar_NT8.zip)