views:

138

answers:

2

This maybe an over asked question, but my mind draws blank at this moment. I know what a candlestick chart is and how to draw it daily. But how to draw it intraday at asked time periods. I have this server, written in Java, that gives me trade depth (each trade done since the start of the day). Its just a stream of raw data: price, shares, timestamp.

How does one go about calculating candlestick data from that? Lets say, they want to have 5 min candlestick or 1min candlestick. Or is there a library that will do that for me if I feed it data?

Any help is appreciated!

A: 

Have you seen JFreeChart ? It will draw candlesticks, and since it's incredibly configurable, it may well do what you want.

Brian Agnew
A: 

The exact implementation varies depending on how you're storing the data, but in general:

  1. Sort the data by timestamp
  2. Decide when the day starts (e.g. 9 AM EST, whatever) and find the timestamp of that time on the first day. You then know when each 5 minute (or whatever) bar begins and ends, by adding an appropriate offset to that number.
  3. Find the index of the first data point that is not in the first bar - every data point whose index is lower than that is in the first bar. It's now straightforward to take the first, last, maximum, and minimum prices for a candlestick.
  4. Repeat 3, substituting the last index of the previous candle for 0.

You now have the data partitioned into candles.

Paul Legato