TimeSeriesBase is the common base class used by TimeSeries and BarHistory. It provides shared functionality for working with data synchronized to a List of DateTimes. Two important concrete classes derive from TimeSeriesBase:
- TimeSeries - manages a series of
doublevalues - BarHistory - represents historical open, high, low, close, volume, and related market data
TimeSeriesBase also provides utility properties for accessing the first and last values, calculating overall and most recent changes, determining a likely HistoryScale, and storing user-defined data.
TimeSeriesBase inherits its fundamental DateTime synchronization functionality from
DateSynchedList<double>. Important inherited members commonly used with TimeSeriesBase instances include the following.
Returns the number of elements in the series. The DateTimes collection contains the same number of DateTimes. Derived classes maintain their associated data synchronized to these DateTimes.
Contains the DateTime corresponding to each element in the series. Derived classes maintain their own values synchronized with this collection, allowing the same index to be used to access both a DateTime and its corresponding data.
Returns the final DateTime in DateTimes.
Returns DateTime.MaxValue if the collection is empty.
Returns the index corresponding to dt. If exactMatchOnly is false and an exact match does not exist, the method returns the index immediately following the closest earlier DateTime, provided the requested DateTime falls within the range of the series. Returns -1 if the DateTime falls outside the series or if exactMatchOnly is true and no exact match exists.
Returns the first DateTime in DateTimes.
Returns DateTime.MinValue if the collection is empty.
Returns the amount of time covered by the DateTimes in the series. Returns a zero TimeSpan if fewer than two DateTimes are available.
A generic cache Dictionary that can be used to associate arbitrary objects with the TimeSeriesBase instance. Indicators can use this Cache to share related calculations and avoid recalculating the same data.
Attempts to determine the market close time from the DateTimes contained in the series. The method examines transitions between trading days and returns the latest observed time of day immediately preceding a new date. Returns a zero TimeSpan if the series contains no data.
Attempts to determine the market open time from the DateTimes contained in the series. For intraday data, the method examines the first bar of each trading day. When the detected scale is minute-based, it adjusts the first bar's timestamp backward by one interval to estimate the actual market open time. Returns a zero TimeSpan if the series contains no data.
Attempts to determine the HistoryScale represented by the DateTimes in the series. If useBarHistory is true and this instance is a BarHistory, the method returns the BarHistory's assigned Scale directly. Otherwise, it examines the spacing between DateTimes and attempts to identify the data as:
- Tick
- Second
- Minute
- Daily
- Weekly
- Monthly
- Quarterly
- Yearly If there is insufficient information to determine another scale, the method returns a Daily HistoryScale.
Returns EndDate formatted as a short date/time string for display purposes.
Returns an empty string if EndDate is DateTime.MaxValue.
Returns the first value in the series.
Returns Double.NaN if the series contains no values.
Returns true if the series appears to contain data through the requested endDate. The base implementation evaluates the data using the US Stock Market and a Daily scale. BarHistory overrides this method so that the test can account for the BarHistory's actual market and scale, including market holidays, trading hours, and intraday data.
Returns the change between the final two values in the series:
LastValue - PreviousValue
Returns Double.NaN if the series contains fewer than two values.
Returns the percentage change between the final two values in the series.
Returns Double.NaN if the series contains fewer than two values.
Returns the final value in the series.
Returns Double.NaN if the series contains no values.
Contains a temporary numeric value that can be used when sorting TimeSeriesBase instances. WealthLab uses this property internally in certain position sizing and participant-sorting operations. The default value is 0.
Returns StartDate formatted as a short date/time string for display purposes.
Returns an empty string if StartDate is DateTime.MinValue or DateTime.MaxValue.
Determines whether labels should be suppressed when the series is plotted on a chart. The default value is false.
Returns the total change in the series:
LastValue - FirstValue
Returns TotalProfit as a percentage of FirstValue.
Returns Double.NaN if FirstValue is zero.
Provides a general-purpose property for associating custom data with a TimeSeries or BarHistory instance.
You can store any object, including primitive values such as an int or double.
Returns UserData cast to a double.
Returns Double.NaN if UserData is null.
The value stored in UserData must be compatible with a direct cast to double.
Returns UserData cast to an int.
Returns 0 if UserData is null.
The value stored in UserData must be compatible with a direct cast to int.
Indicates whether the series has been plotted. WealthLab uses this property internally when managing charted TimeSeries and indicators. The default value is false.