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

# OnBarUpdate()

## Definition

An event driven method which is called whenever a bar is updated. The frequency in which **OnBarUpdate** is called will be determined by the "[Calculate](/developer/desktop-sdk/references/common/onbarupdate/calculate)" property. **OnBarUpdate()** is the method where all of your script's core bar based calculation logic should be contained.

Notes:

* For [multi-timeframe and instrument scripts](/developer/desktop-sdk/guides/educational-resources/multi-time-frame-instruments), the **OnBarUpdate** method is called for each Bars object of a strategy. You MUST filter for the exact bar update events using the "[BarsInProgress](/developer/desktop-sdk/references/common/adddataseries/barsinprogress)" property you want your system logic to execute against.
* Hosted indicators will need to be accessed by the hosting script to ensure **OnBarUpdate** functionality. This can be done by:
  1. Calling [Update](/developer/desktop-sdk/references/common/onbarupdate/update) on the hosted indicator within the host script,
  2. Including a plot in the hosted indicator and accessing the plot in the host script,
  3. Including a plot in the hosted indicator and adding the indicator to the chart with [AddChartIndicator](/developer/desktop-sdk/references/strategy/addchartindicator) (strategies only)

## Related Methods and Properties

| Method                                                                                                  | Description                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| [BarsPeriod](/developer/desktop-sdk/references/common/onbarupdate/barsperiod)                           | The primary Bars object time frame (period type and interval).                                                                                |
| [Calculate](/developer/desktop-sdk/references/common/onbarupdate/calculate)                             | Determines how often **OnBarUpdate()** is called for each bar.                                                                                |
| [Count](/developer/desktop-sdk/references/common/onbarupdate/count)                                     | The total number of bars or data points.                                                                                                      |
| [CurrentBar](/developer/desktop-sdk/references/common/onbarupdate/currentbar)                           | A number representing the current bar in a Bars object that the **OnBarUpdate()** method in an indicator or strategy is currently processing. |
| [IsDataSeriesRequired](/developer/desktop-sdk/references/common/onbarupdate/isdataseriesrequired)       | Determines if a Data Series is required for calculating this NinjaScript object.                                                              |
| [IsFirstTickOfBar](/developer/desktop-sdk/references/common/onbarupdate/isfirsttickofbar)               | Indicates if the incoming tick is the first tick of a new bar.                                                                                |
| [IsResetOnNewTradingDays](/developer/desktop-sdk/references/common/onbarupdate/isresetonnewtradingdays) | Determines if the specified bar series is using Break at EOD.                                                                                 |
| [IsTickReplays](/developer/desktop-sdk/references/common/onbarupdate/istickreplays)                     | Indicates the specified bar series is using Tick Replay.                                                                                      |
| [Update()](/developer/desktop-sdk/references/common/onbarupdate/update)                                 | Forces the **OnBarUpdate()** method to be called so that indicator values are updated to the current bar.                                     |

## Method Return Value

This method does not return a value.

## Syntax

You must override this method with the following syntax:

**protected override void OnBarUpdate()**

Tip: The NinjaScript code wizards automatically generates the method syntax for you.

## Parameters

This method does not take any parameters.

## Examples

```csharp
protected override void OnBarUpdate()
{
     if (CurrentBar < 1)
         return;

     // Compares the primary bar's low price to the 5-minute bar's low price
     if (Low[0] > Lows[1])
         Print("The current bar's low price is greater");
}
```