softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

Bar prices keep changing #94

Open dakr001 opened 4 years ago

dakr001 commented 4 years ago

Hi,

This is not really an issue I wanted to log here, but I wanted to share what I've found. I'll check with IB support. I've shared this in a separate forum in more detail:

https://www.elitetrader.com/et/threads/bar-prices-keep-changing.343216/

softwarespartan commented 4 years ago

It is hard for me to understand what the issue is exactly from your plot. In general the mktdata in TWS is not perfect and IB says as much. Is it possible that you use realtimebar instead to compute minute bars?

dakr001 commented 4 years ago

Thanks. I think it was my misunderstanding of how the bar chart is generated in the first place. I've assumed that to produce the 8:47 bar it uses prices from 8:46:00 to 8:47:00. In other words 8:47:00 is the last price used. However I think what happens is that the 8:47 bar uses prices from 8:47:00 to 8:47:59.

bondtrade commented 4 years ago

I have found a similar issue. I use realtimebar to build up minutes bars and when the last one is received at say 10:00:55 being the 10:00:00 bar, I request 10 minutes of 10-minute bars with historicaldata to make sure my construction of bars with realtimebar is ok. Quite often and mainly in the Sydney/Asia session there are variances with the open price of the last minute bar. I was initially just using historicaldata every minute for minute bars but found I had to add up to 2 seconds of latency for the last minute bar to complete properly and avoid variances on the data returned in the next historicaldata call. I use both now so I can go to a lower resolution than 1-minute in future if I need to. If you don't, you could monitor realtimebar for completion of the minute bar and then get data with historicaldata. That should remove any variances over time. It can be problematic because I was missing signals initially dues to what I perceived as changing bars.