Hi all, I'm in the process of coding up my trading platform using IB's API in java. My strategy looks at the previous 10 (5 minutes bar) to determine entry. I just can't figure out a way to aggregate the info from reqRealTimeBars (5 seconds interval) to a 5 minute info. I understand I need to collect 60 instances of RealTimeBars callback which I have absolutely no problem in doing, but the problem is... How the heck should I approach in storing until the 5 minute mark hits and make it into one 5 minute "bar"? Much thanks and I hope i did a good job explaining it.
If you just need OHLC, why not just do a running comparison? You only need to keep the most recent 5-second bar. For example: At i=0 (start of a new bar), the 5-minute O=H=L=C = close of the most recent 5-second bar. At i=1, i=2, i=3, check the high and low of the most recent 5 second bar and modify the 5-minutes values if they are exceeded. The 5-minute close is always the close of the most recent 5-second data. At i=59, you do all the same checks, but then you increment your 5-minute array so that you are looking at a new bar.
@TheGoonier Thank you very much for the tip. I'll look at it from that approach! Have a great day sir!
You're welcome. Also, if you're looking for more frequent updates of your bars, you might want to consider responding to the events from reqMktDataEx() instead of the real-time bars. These aren't true ticks (they are aggregate bars just like the 5-second bars, but they show up on the order of 100-200ms). In this case, you'd need a timer to tell you when to switch bars, but the method of generating the longer interval bar is pretty much the same as I mentioned before.
I have the code if you need it.I do the same thing in my Black box create a dataset collection that is all the 5min bars with a listener on the collection so that an event fires as each time a new 5min bar completes. I then plot the bars and calc the MA from this dataset. The chart updates every 5sec. Just PM me and I'll send you the code
I saw your YouTube channel. Do you have a blog also? YouTube is less convenient. I would like to read more about your efforts.
Would be mighty swell if you could share that portion of your codes with me. Much thanks. I used an Array, which type of dataset are you using for your collection?
I stayed with the reqRealTimeBars due to the precise 5 seconds interval. I had my codes add 300 to the returned epoch time and that yields exactly 5 minutes. I made sure that adding 300 only occurs when (Epoch Time % 300 == 0) to make sure that it's the first opening bar. That's the best I could come up with. Am opened to ideas if you guys have any!
Using 5 sec realtime bars has another advantage over reqMarketData. IB's market data is sampled and can miss prices at the extremes, so bars generated with this data might have a lower high or a higher low than they should due to trades that occurred between the samples. IB's market data is useful for other things but building bar data is not one of them.