TWS line charts - what is plotted and why does refreshing result in different data?

Discussion in 'Retail Brokers' started by brynno, Jun 10, 2013.

  1. brynno


    I would be very grateful if someone who knows about this could clear a couple of things up regarding IB's line charts.

    I have always used their line charts for all of my day trading.
    I am now in the process of automating my strategy using IB's API.
    As far as I can tell, what I see on a historical "line chart" corresponds exactly with the "WAP" (which I gather stands for "weighted average price") for each 1-second bar when I request historical data using the API.

    maybe somebody could confirm this?

    more importantly though, I have found that when I am watching a real time line-chart, whenever I refresh, the refreshed version will show a slight change somewhere. in fact, sometimes the difference can be very significant when prices are volatile.

    since all of my backtesting has been done using historical line charts, i.e. the "refreshed version", I therefore always make sure to refresh regularly when I am trading manually, particularly just before entry.

    now that I am half way through coding my strategy, I am starting to wonder whether i'll have to somehow get it to refresh (or whatever the API equivalent of refreshing is) in order to emulate what I would be doing if I were trading manually.

    or could it be that this mysterious discrepancy as a result of refreshing only occurs in the charts themselves, and the API data manages to churn out first time round the exact "WAPS" that I see in my historical line charts?

    if the answer is that I DO need to refresh, any idea how I can get my program to do that?
  2. Pete - IB

    Pete - IB Interactive Brokers

    The data points used for line charts depends on the total length of the chart (e.g. 1 day, 6 months, etc.). What is the time period of your charts?

    As for the price discrepancy, real-time charts have three sources of data: historical prices, real-time five-second bars, and real-time market data. When you refresh the chart, all real-time data is replaced with historical prices. I don't know why they should differ, but I believe that that is why you see the change.

    All three source of data are available for your API program. If you are mixing real-time and historical data, you will probably see the same thing in your API program as you do on the charts. If you are only using historical prices, you should be okay.
  3. brynno


    thank you for your reply Pete

    I am talking about the smallest resolution (1 second). If you zoom into a line chart until you hit 1 second resolution, let it update automatically for a minute or so, and then refresh it manually, you will almost always notice quite a difference.

    my entry and exit rules require every second's worth of data to be recorded and analysed. I have lost count of the number of times ive lost money on a trade only to find out later that if only i'd been shown in real time the exact prices later displayed on the historical chart, and applied my rules to those prices, i'd have done fine! no idea why this should be the case. you'd think it would average out, wouldn't you, so that you win some and lose some. but no.. for some reason I always do better when I use the "refreshed" (ie historical) data.

    therefore I would prefer to be able to use historical data for my API program, wherever possible. however the problem seems to be that I can only make a limited number of historical data requests in any 10 minute period. I suppose then i'll need to somehow mix the two?

    oh also could you confirm that "real time market data" (for the API) includes the so-called "last" price that is available on the TWS? when trading manually I have, in addition to the "bid" and the "ask", a third price called the "last". this "last" is what appears to be plotted on the line charts, BEFORE I refresh them, when I choose "trades" in the "what to show?" setting in chart parameters. do I get the same "last" price with the API when I "request market data"?