OnBarUpdate()

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Common >

OnBarUpdate()

Previous page Return to chapter overview Next page

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" property. OnBarUpdate() is the method where all of your script's core bar based calculation logic should be contained.

 

Note:  For multi-timeframe and instrument scripts, the OnBarUpdate method is called for each Bars object of a strategy.  You MUST filter for the exact bar update events using the "BarsInProgress" property you want your system logic to execute against.

 

 

Related Methods and Properties

BarsPeriod

The primary Bars object time frame (period type and interval).

Calculate

Determines how often OnBarUpdate() is called for each bar.

Count

The total number of bars or data points.

CurrentBar

A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing.

IsDataSeriesRequired

Determines if a Data Series is required for calculating this NinjaScript object.

IsFirstTickOfBar

Indicates if the incoming tick is the first tick of a new bar.

IsResetOnNewTradingDays

Determines if the specified bar series is using Break at EOD.

IsTickReplays

Indicates the specified bar series is using Tick Replay.

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

ns


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");
}