<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Common >


Previous page Return to chapter overview Next page


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.



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.

Hosted indicators will need to be accessed by the hosting script to ensure OnBarUpdate functionality. This can be done by: 1) Calling 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 (strategies only)



Related Methods and Properties


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


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


The total number of bars or data points.


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


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


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


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


Indicates the specified bar series is using Tick Replay.


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.



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.




This method does not take any parameters






protected override void OnBarUpdate()
    if (CurrentBar < 1)
    // 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");