NinjaScript > Language Reference > Data >

OnBarUpdate()

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
The OnBarUpdate() method is called whenever a bar is updated. If the "CalculateOnBarClose" property is set to true, it is only called on the close of each bar, otherwise it is called on each incoming tick. This is the method where all of your strategy or indicator core calculation logic should be contained.

 

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

 
 

Method Return Value

This method does not return a value.

 

Syntax
See example below. The NinjaScript indicator and strategy wizards automatically generate the method syntax for you.
 

 
Examples

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