A time series of OHLCV bars


Namespace: OpenQuant.API
Assembly: OpenQuant.API (in OpenQuant.API.dll)

Syntax

Visual Basic (Declaration)
<DefaultMemberAttribute("Item")>
Public Class BarSeries
    Implements IEnumerable, ISeries
C#
[DefaultMemberAttribute("Item")]
public class BarSeries : IEnumerable, ISeries
C++
[DefaultMemberAttribute(L"Item")]
ref class BarSeries : IEnumerable, ISeries
J#
/** @attribute DefaultMemberAttribute("Item") */
public class BarSeries implements IEnumerable, ISeries
JScript
public 
   DefaultMemberAttribute("Item")
class BarSeries extends IEnumerable, ISeries

Remarks

BarSeries is a collection of Bar objects ordered in time.

The number of bars in the series is given by the Count property. It's always a good idea to check that you have enough bars in the series before you try to access a bar with specific index. An exception will be thrown if you try to access a bar with index that doesn't exist.

You can access a specific bar in the series by either using bar index in the series or bar time. The first bar in the series has zero index. The last bar in the series has Count-1 index. The last bar in the series is the most recent bar. The first and the last bars in the series can be directly accessed using First and Last properties of bar series. You can use Ago method to access n-bars-ago bar. The code below checks that we have enough bars in the series to access 10 bars ago bar. Then we print High of 10 bars ago bar using bar series indexers and Ago method

 Copy Code
            
            // using indexer 
            
            if (Bars.Count > 10)
                Console.WriteLine("10 bars ago high = " + Bars[Bars.Count - 1 - 10].High);
            
            // using the Ago method
            
            if (Bars.Count > 10)
                Console.WriteLine("10 bars ago high = " + Bars.Ago(10));
            
There are several methods in the BarSeries class helping to develop trading strategy logic. Use HighestHigh and LowestLow methods to find the highest High or the lowest Low value in the bar series. The code below shows an example of entry condition in a simple breakout strartegy.
 Copy Code
            public override OnBar(Bar bar)
            {
                if (Bars.Count > 10)
                    if (bar.High > Bars.HighestHigh(10))
                        Buy(100);
            }
            
You can use Crosses methods to check if BarSeriesCrossesAbove or CrossesBelow another series or an Indicator.
 Copy Code
            public override OnStrategyStart()
            {
                SMA sma = SMA(Bars, 14);
            }
            
            public override OnBar(Bar bar)
            {
                if (Bars.CrossesAbove(sma))
                    Buy(100);
            }
            

Inheritance Hierarchy

System.Object
   OpenQuant.API.BarSeries

Thread Safety

Public static (Shared in Visual Basic)staticShared members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

See Also