IsTimeBased

View as Markdown

Definition

Used to indicate the BarsType is built from time-based bars (day, minute, second). Setting this property on a custom bar type is useful for correct calculations from many core data and session logic, and can also be used by 3rd party NinjaScript objects to determine how to interact with the bars.

Property Value

A bool which when true tells other objects the bars are built from time; default set to false.

Syntax

Bars.IsTimeBased

Examples

Setting the IsTimeBased defaults in a custom BarsType

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 Name = "Custom BarsType";
6 IsTimeBased = true; // indicates to the core the these bars are built using time.
7 }
8}

Reading IsTimeBased from a custom NinjaScript object

1protected override void OnBarUpdate()
2{
3 // include milliseconds time stamps for tick based bars
4 string timeFormat = "HH:mm:ss:fff";
5
6 if (Bars.BarsType.IsTimeBased)
7 {
8 // on time based bars, only format up to "seconds"
9 timeFormat = "HH:mm:ss";
10 }
11 // format string based on the appropriate time format
12 Print(Time[0].ToString(timeFormat));
13}