Calculation of intraday candlesticks by time intervals
This question could be asked, but my mind is not working at this point. I know what a candlestick is and how to draw it daily. But how to draw it within a day at given time periods. I have this server written in Java which gives me trade depth (every trade is done from the very beginning of the day). Its just a stream of raw data: price, stock, timestamp.
How do I calculate the highlighted data? Let's say they want a 5 minute candle or a 1 minute candle. Or is there a library that will do this for me if I feed it with data?
Any help is appreciated!
a source to share
The exact implementation depends on how you store the data, but in general:
- Sorting data by timestamp
- Decide when the day starts (for example, 9 AM EST, whatever) and find the time stamp of that time on the first day. You then know when each 5 minute (or any other) bar starts and ends by adding the appropriate offset to that number.
- Find the index of the first data point that is not in the first bar - every data point that has an index lower than the first bar. It is now easy to take the first, last, high and low prices for a candlestick.
- Repeat 3, replacing the last index of the previous candle with 0.
You now have the data divided into candles.
a source to share
Have you seen JFreeChart ? It will paint candlesticks , and since it is incredibly customizable, it can do what you want.
a source to share