Bars class

Discussion in 'Programming' started by abattia, Apr 10, 2013.

  1. I need a Bars class (C#), and am trying to determine what type to use.

    I need something that will construct as time bar, range bar, renko bar, etc ... as the case may be.

    To get the ball rolling (or perhaps "to get the bar going ..."), what do you think of ...

    Dictionary <DateTime, Ohlc>

    ... where the DateTime index would be the bar's start or end time, and
    ... where Ohlc would be another class with properties Open, High, Low, and Close [which - lol - will be either double, float or integer pending eventual resolution of the "Tick (Last Traded Price) ... float or double?" thread ...]

    Thanks for your help in "raising the bar" ... all contributions welcome.
  2. ... and sorry I realize that perhaps it is not clear that I am referring to the type of a property of Bars (perhaps Bar) that would give access to the bars ...

    I hope that makes better sense.
  3. hftvol


    I would encapsulate all the data in your Bar class, including start and end time, or one time reference and a TimeSpan to indicate the bar compression. Obviously you can also decode the time stamp or compression using other data types. It depends on how high frequency you go. If microseconds do not matter you should do just fine storing DateTime and TimeSpan.

    You can stick them into a var bars = List<Bar> and query with Linq like

    var result = from bar in bars where bar.StartTime >= x && bar.EndTime <= y orderBy bar.StartTime descending select bar;

    You can also include an orderBy

  4. dom993


    I suppose this is to store bars in RAM once historical data is read from file, for the purpose of chart display / data analysis / indicator or strategy processing.

    - Add Volume and Ticks to your Ohlc class (I would add a DateTime for the bar's close DateTime, too) (I would also keep track of the order sequence of H & L)

    - Dictionary<DateTime, Ohlc> has 2 issues:
    1) each DateTime used as Key must be unique, when processing volume/ticks based timeframe you can have several bars in the same second, and sub-second timestamp might not available for historical data
    2) the Item[] method of Dictionary takes as Key as parameter. I suspect most data processing is done either using an offset from the CurrentBar, or a BarNumber, either case you'll have to use Keys and/or Values to get a suitable Item[] with I am sure a performance hit each time you use it.

    I would create my own container class and use fixed size buffers to store N bars per buffer, and a second layer of containers to keep track of the buffers ...Don't forget in a single year you have about 25 million 1-second bars for 1 instrument.
  5. hftvol, dom993, many thanks! Great suggestions.

    ET rocks!
  6. even easier.... since is open and C# and supports time/tick/volume bars, just use classes in there that start with bar*.
  7. Thanks!

    I am browsing the Tradelink directories using the online svn tool provided on the Tradelink website... Where can I find the source for these classes?
  8. hftvol



  9. thanks
  10. tradelinkapi is the interfaces
    tradelinkcommon is the implementations
    #10     Apr 11, 2013