IsFirstTickOfBar

View as Markdown

Definition

Indicates if the incoming tick is the first tick of a new bar. This property is only of value in scripts that run tick by tick which is when the Calculate property is set to Calculate.OnEachTick or Calculate.OnPriceChange.

This property should NOT be accessed outside of the OnBarUpdate() method.

If a bar type is set up to remove the last bar on a chart, IsFirstTickOfBar will automatically be set to True.

Property Value

This property returns true if the incoming tick is the first tick of a new bar; otherwise, false.

Syntax

IsFirstTickOfBar

In NinjaTrader’s event driven framework, bar closures are signaled by the tick that opens the next bar. The price of the last tick of a bar can be referenced by checking Close[1] on IsFirstTickOfBar. For volume and tick based bars, Bars.TickCount and Volume[0] can be referenced to see if the number of ticks / volume meet the criteria to build a new bar.

Examples

1// On a tick by tick strategy the only way you know when a bar is closed is when
2// the IsFirstTickOfBar is true.
3protected override void OnBarUpdate()
4{
5 // Only process entry signals on a bar by bar basis (not tick by tick)
6 if (IsFirstTickOfBar)
7 {
8 if (CCI(20)[1] < -250)
9 EnterLong();
10 return;
11 }
12
13 // Process exit signals tick by tick
14 if (CCI(20)[0] > 250)
15 ExitLong();
16}