MaximumBarsLookBack

View as Markdown

Definition

Determines memory performance of custom Series\<t\> objects (such as Series<double>, Series<long>, etc.). When using MaximumBarsLookBack.TwoHundredFiftySix, only the last 256 values of the series object will be stored in memory and be accessible for reference. This results in significant memory savings when using multiple series objects. In the rare case should you need older values you can use MaximumBarsLookBack.Infinite to allow full access of the series.

  • ISeries<t> objects that hold bar data (such as Close, High, Volume, Time, etc) always use MaximumBarsLookBack.Infinite which ensures all data points are always accessible during the lifetime of your NinjaScript indicator or strategy.
  • Series<double> objects that hold indicator plot values always use MaximumBarsLookBack.Infinite which ensures that charts always display the entire indicator’s calculated values.

Property Value

A MaximumBarsLookBack enum value. Default value is MaximumBarsLookBack.TwoHundredFiftySix.

Possible values are:

MaximumBarsLookBack.TwoHundredFiftySixOnly the last 256 values of the series object will be stored in memory and accessible for reference (improves memory performance)
MaximumBarsLookBack.InfiniteAllow full access of the series, but you will then not be able to utilize the benefits of memory optimization

A MaximumBarsLookBack.TwoHundredFiftySix series works as a circular ring buffer, which will “loop” when the series reaches full capacity. Specifically, once there are 256 entries in the series, new data added to the series overwrite the oldest data.

Syntax

MaximumBarsLookBack

Examples

Setting all custom series to use the default MaximumBarsLookBack

1Series<double> myDoubleSeries = null;
2Series<string> myStringSeries = null;
3
4protected override void OnStateChange()
5{
6 if (State == State.SetDefaults)
7 {
8 Name = "Example Indicator";
9 // Store all series values instead of only the last 256 values
10 MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
11 }
12 else if (State == State.DataLoaded)
13 {
14 // The custom Series`<t>` below are all constructed using only the NinjaScriptBase object (i.e., "this")
15 // therefore, the Series`<t>` **MaximumBarsLookBack is taken from the NinjaScript's configured MaximumBarsLookBack property
16 myDoubleSeries = new Series<double>(this);
17 myStringSeries = new Series<string>(this);
18 }

Optimizing custom series to use unique MaximumBarsLookBack behavior

1Series<double> myDoubleSeries = null;
2Series<string> myStringSeries = null;
3
4protected override void OnStateChange()
5{
6 if (State == State.SetDefaults)
7 {
8 Name = "Example Indicator";
9 }
10 else if (State == State.DataLoaded)
11 {
12 // The custom Series`<t>` below are constructed using MaximumBarsLookBack parameter
13 // therefore, each Series`<t>` will use their uniquely specified MaximumBarsLookBack properties
14 myDoubleSeries = new Series<double>(this, MaximumBarsLookBack.Infinite); // stores all values
15 myStringSeries = new Series<string>(this, MaximumBarsLookBack.TwoHundredFiftySix); // only the last 256 values (better performance)
16 }