Update()

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Common > OnBarUpdate() >

Update()

Previous page Return to chapter overview Next page

Definition

Forces the OnBarUpdate() method to be called so that indicator values are updated to the current bar.  If the values are already up to date, the Update() method will not be run.

 

Note:  This method is only relevant in specific use cases and should only used by advanced programmers

 

When indicators are embedded (called) within a NinjaScript strategy, they are optimized to calculate only when they are called upon in a historical backtest. Since the NinjaTrader indicator model is very flexible, it is possible to create public properties on a custom indicator that return values of internal user defined variables. If these properties require that the OnBarUpdate() method is called before returning a value, include a call to this Update() method in the property getter.

 

Syntax

Update()

 

Parameters

idx

The current bar index value to update to

bip

The BarsInProgress to update

 

 

Examples

ns

private double tripleValue = 0;
 
protected override void OnBarUpdate()
{
  if (CurrentBar < 20)
      return;
 
  tripleValue = SMA(20)[0] * 3;
  Value[0] = SMA(20)[0];
}
 
public double TripleValue
{
    get
    {
      //call OnBarUpdate before returning tripleValue
      Update();
      return tripleValue;
    }
}