Interactive Brokers -1 values for CFDs at the end of session

Hello,

Has anyone encountered the problem with negative values in Interactive Brokers real-time feed for CFDs at the end of the session? I am sure IBKR want to signal the session is closed but it resets the y-axis and I can't see the plot (see picture) until the -1 values get flushed out the following morning.

IBKR_axis

I have tried referencing the previous bar (see code below) but the problem persists.

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", IIf(O > 0, O, Ref(O,-1)), IIf(H > 0, H, Ref(H,-1)), IIf(L > 0, L, Ref(L,-1)),IIf(C > 0, C, Ref(C,-1)), SelectedValue( ROC( IIf(C > 0, C, Ref(C,-1)), 1 ) ) ));
P = ParamField("Price field",-1);
Plot(IIf(C > 0, C, Ref(C,-1)), "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
PlotVAPOverlay( Param("lines",300,10,1000,1), Param("width",10,1,99,1), ParamColor("color", colorDarkBlue), Param("style",0,0,7,1) );
_SECTION_END();

It happens at all time intervals but if I scroll the x-axis to exclude the last bar the chart is ok. Also, plots in IBKR's TWS are ok. I am using Amibroker version 6.40.0 Build: Aug 24

I appreciate help on this matter.
Thank you.-

What plugin version do you have in Tools->Plugins?

I have Interactive Brokers data Plug-in 2.0.10

This is old version. Newest is 2.0.11 Chart not updating in real time for NIFTY index (India only) from IB - #17 by Tomasz

I replaced the plug-in with the latest 2.11.0 and checked it is in Tools/Plug-ins list... as per instructions. Still same problem.
I upgraded Amibroker to 6.40.4 and the problem persists.

It only happens to CFDs; stocks and futures are ok. It can happen mid-session as well but it always happens at the end of the session. When it happens I can see the -1s in the Quote Editor (see screenshot). I try to backfill it but the -1s stay, and the CFDs charts only display properly the following morning.
amibroker_quote_editor

If backfill does not fix that, it means that those -1 are just present on all Interactive Broker servers. Plugin just passes that transparently.

Thanks Tomasz for looking into it. I will raise it with IBKR.

I have back up plots in TWS but my concern is that it can mess up my alerts from the scans when it happens mid-session. Is there any workaround so whenever I get a -1 my charts and analyses can ignore it or set it to previous value? I have made several attempts but failed.

@carlrom, to learn more about outlier issues I suggest reviewing this past thread and looking at the interesting solutions suggested by @fxshrat, to see if you could apply something similar to your formulas.

1 Like

@beppe , many thanks for the pointer, the extra piece of code sorted out the plotting issue. I have also added it to the analysis files.

IBKR haven't replied yet.

1 Like

Here is the link to the code by @fxshrat I used as a start: past thread.

And below is my adapted code:

band1 = 0 ;

altOC = Ref(O, -1) ;
altHC = Ref(H, -1) ;
altLC = Ref(L, -1) ;
altCC = Ref(C, -1) ;

O = IIf( O < band1, altOC, O );
H = IIf( H < band1, altHC, H );
L = IIf( L < band1, altLC, L );
C = IIf( C < band1, altCC, C );

I tried to simplify it but it didn't work (I don't do HFT so can live with a bit of suboptimal code). Suggestions welcome!

This problem also occurs for forex tickers e.g for EUR.USD-IDEALPRO-CASH.

I use the following code:

DataError = (L <= 0) OR (H < L); // Latter for datafeed errors...

if (ParamToggle("Fix Data Errors", "No|Yes", 1)) {
	n = -BarsSince(NOT DataError);
	O = Ref(O, n); H = Ref(H, n); L = Ref(L, n); C = Ref(C, n); 
	V = Ref(V, n); Avg = Ref(Avg, n);
}

There are pros & cons for this solution. It's simpler but doesn't work for spreads (quotations can be negative). Using Compress/Expand is better if you can modify your formula (I use a separate include file). I never found a perfect universal solution to this problem.

Note that modifying O H L C is problematic when used with TimeFrameGetPrice(). The latter seems to use database quotes directy (unmodified) instead of modified O/H/L/C arrays. Maybe implementation could be changed @Tomasz Or better,filter/remove -1 in IB plugin for -CFD- and -CASH tickers.

3 Likes

Hi @carlrom , for real trading I use a my own software in java. I use Amibroker for back-testing on historical data. My experience is that for CFD IB doesn't stream real-time data via API, but I have to require live data for the underlying instrument of the CFD. In fact CFD shown data on IB chart are really the traded price of the underlying instrument. Have you tried if your issues holds on real-time price data of the underlying instrument? May be you can visualize the underlying with no issues, but for trading instead you send orders to trade the relative CFD. I do so.
I was attracted by your question because I am only recently interested in trading CFD, before only stock or future. I have problems with lack of documentation for CFD orders type from IB. Particularly I want to know if trading CFD I have to respect the time limit for submitting Market On Open / Market On Close orders as I have if I was trading the relative stock. Can you give me the answer?

Hi @Luca, you are right, IB CFD quotes are actually those for the underlying stocks. But they have several index CFDs (such IBUST100 for the Nasdaq-100) which are a convenient way to trade during my wake hours. Those are the ones that throw a -1 from time to time.
Regarding your question about time limit, I can't help, I don't use Market On Open / Close orders.

Apparently it is INTERACTIVE BROKERS problem/limitation. IB actively refuses getting data for CFD, displays error 2127 and advises to use underlying symbol instead of CFD symbol:

See this:

image

You need to complain to DATA VENDOR. Our plugin does nothing to the data. It is 100% transparent and passes the data as they come from data vendor without any modification.