OnDataPoint()

View as Markdown

Definition

Called for each record in the corresponding base dataset used to build the BarType (i.e., for every tick, minute, or day). The OnDataPoint() method is where you should adjust data points (bar values) of your series through AddBar() and UpdateBar(). See also the BuiltFrom property.

  1. Historical data processing receives a single update for every base bar determined by the BuiltFrom property.
  2. When using TickReplay, historical updates will call for every tick handled by the core regardless of the BuiltFrom property defined.
  3. Once transitioned to real-time, updates will call on every tick processed by the core.
  4. The bid/ask parameters will ONLY be available historically when using Tick Replay, unless you are using a 1-tick series.
  5. isBar could be true in case the BarsSeries was internally copied to another BarsSeries and is only needed for IsTimeBased = true BarsTypes (e.g. Second/Minute/Day…).

Method Return Value

This method does not return a value.

Method Parameters

ParameterDescription
barsThe Bars object of your bars type
openA double value representing the open price
highA double value representing the high price
lowA double value representing the low price
closeA double value representing the close price
timeA DateTime value representing the time
volumeA long value representing the volume
isBarA bool value representing if OnDataPoint should treat the timestamp as an already built bar instead of an intrabar timestamp.
bidA double value representing the bid price
askA double value representing the ask price

Syntax

You must override the method in your Bars Type with the following syntax.

protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask) \{ \}

Examples

1protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
2{
3 int minIndex;
4
5 // Create the first data point of our series
6 if (bars.Count == 0)
7 {
8 minIndex = 0;
9 AddBar(bars, open, high, low, close, TimeToBarTime(time, (int) bars.BarsPeriod.Value), volume);
10 }
11 // Update our data point with the latest information
12 else if ((time.Month <= bars.LastBarTime.Month && time.Year == bars.LastBarTime.Year) || time.Year < bars.LastBarTime.Year)
13 {
14 if (high != bars.GetHigh(bars.Count - 1) || low != bars.GetLow(bars.Count - 1) ||
15 close != bars.GetClose(bars.Count - 1) || volume > 0)
16 {
17 minIndex = bars.Count - 1;
18 UpdateBar(bars, high, low, close, bars.LastBarTime, volume);
19 }
20 else
21 minIndex = -1;
22 }
23 // Add new data points
24 else
25 {
26 minIndex = bars.Count;
27 AddBar(bars, open, high, low, close, time, (long)Math.Min(volumeTmp, bars.BarsPeriod.Value));
28 }
29 FirstBarAmended = minIndex;
30}