- ago
Hello,
after some backtesting of intraday strategies in European (German) stocks, I am actually testing the strategy monitor in paper trading.

Some questions:

b) A very special question on European stocks:
The min tick differs for European stocks due to some "sophisticated" regulation.
Some thing like: more liquidity -> lower min tick && higer price -> higher min tick
e.g. the very liquid Siemens stock (SIE@IBIS) has a minimum tick of 2ct.

Hence placing a calculated limit order (e.g. 0.99*last_close) without any rounding to multiples of 2ct results in an error from the IB-API for this stock.
What can I do ? Implement a symbol specific rounding algorithm in my strategy ?
In my own IB-API applications, I use the min-tick property of the IB-symbols data for rounding.

Thanks!
0
569
13 Replies

Reply

Bookmark

Sort
Cone8
 ( 6.07% )
- ago
#1
b) You can round to the nearest 0.02 like below, but if I'm reading you right, this can change without notice to be value other than 0.02?

CODE:
double limit = Math.Round(bars.Close[idx] * 0.99 / 0.02) * 0.02;
0
- ago
#2
Yes, unfortunately the minimum tick can change with the price:

e.g. 1ct as long as the price is 99.99 or below and 2ct when the price is above 100.
BidAsk could be 99.99 - 100.02

furthermore it depends on the liquidity of the stock:
e.g. one stock around 18€ is traded with even 2ct min tick, another (highly liquid) with 0,2ct = 3 digits

It is a EU-regulation, hence I think it is applicable at all Eu-based exchanges.
0
Cone8
 ( 6.07% )
- ago
#3
I don't know about the liquidity end of it, but when required (like for futures), we can request Contract Details, which has the "Market Rules" that define the tick increments used at different pricing levels. The only problem is that this takes time, so if you're testing on 100 symbols, this would add dozens of seconds for data collection - but only the first time.

I'll see what I can do, but when a "Tick" increment is associated with a BarsHistory, WealthLab only has one of those values to work with. Changing it when price is "on the edge" will be a challenge. At least for now and until there's another solution, you'll have to set up your own rounding for the contracts you're trading when it's different than 0.01.
0
Cone8
 ( 6.07% )
- ago
#4
I worked on this and the good news is that we already are requesting those details. We're actually using the Market Rule, but WealthLab only uses the number of decimals. 0.05 is the same as 0.02 which is the same as 0.01 - 2 decimals.

For the next IB Provider update, I've added a new public method that you can use to get the proper rounding for a contract's Price based on the contract's Market Rule.

Here's how:
CODE:
double limit = bars.Close[idx] * 0.99; limit = WealthLab.InteractiveBrokers.IBConnection.Instance.RoundToMarketRule(bars.Symbol, limit);
bars.Symbol needs to be the IB Local Symbol, so if you're using something like this for the contract record:
SIE.IBIS=SIE|EUR|STK|IBIS|IBIS|SIE|||0|
... you'll need to pass just the SIE local symbol part instead of bars.Symbol.

However, you shouldn't even need to do that because I've added the method to automatically adjust IB's limit and stop orders for the Market Rule. For now, we'll just apply this to Stocks since it's not required for Futures. Let's hope this does the trick!
1
- ago
#5
Trading EU stocks intraday - I tested with build 80, IB extension 43:
a) Open a position works fine:
CODE:
if(!HasOpenPosition(bars, PositionType.Long) { limit = lastClose * 0.99995; PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, limit, "TestOpenBuy"). }

The stock limit price is rounded to the next valid tick for the stock (e.g. SIE.SMART). Great!

b) Then I tried closing the position:
CODE:
if(HasOpenPosition(bars, PositionType.Long) { p = LastPosition; profitTarget = p.EntryPrice*1.00005; ClosePosition(p, OrderType.Limit, profitTarget, "TestCloseBuy"); text = "CloseOrder @ " + idx.ToString() + " - " + profitTarget.ToString() + " open: " + p.EntryPrice; WLHost.Instance.AddLogItem(StrategyName, text, WLColor.Green); }


Unfortunately the sell-to-close-position-oder isn't transfered to IB-TWS, evenso the strategy monitor thinks the order has been transmitted sucessfully!
The order manager shows an error for the close-order.

Then it gets strange: The strategy monitor continues with my algorithm to open new positions - strategy thinks, that there are no open positions, evenso in my IB-TWS the position is still open.

Is this problem related to rounding to the next tick or is there something complete different, I am doing wrong ?
Maybe it isn't possible to use a Limit Order in Closeposition ?

Thanks


0
Glitch8
 ( 11.64% )
- ago
#6
The SM runs the Strategy on a theoretical basis. It's not linked to your live account at all unless you enable to "Use Live Positions" in Trading Preferences.
0
- ago
#7
I followed your advice and activated "use live positions". Still the close orders are not transmitted: Message in Order Manager "Could not find Position to exit"

Then I looked into the TWS API log and found some strange things:
I used two symbols ENR.SMART and SIE.SMART - both are functioning in data manager and chart.

Order-Opening - Buy - 1min bars - should start at 19:38:00:
Several strange requests from wealthlab for a CASH contract (shortend here):
19:38:01:067 <- 9-8-1268-0-SIE-CASH--0---IDEALPRO-IDEALPRO-SMART-SIE.SMART
19:38:01:204 -> ---D4-2-1268-200-No security definition has been found
19:38:01:267 <- 9-8-1269-0-ENR-CASH--0---IDEALPRO-IDEALPRO-SMART-ENR.SMART
19:38:01:391 -> ---D4-2-1269-200-No security definition has been found

then the opening buy order is sucessfully transmitted:
19:38:02:580 -> -- 5-1274-447545380-ENR-STK--0-?--SMART-EUR-ENR-XETRA-BUY-72-LMT-13.82-0.0-DAY
and filled (I changed the limit in TWS manually to force execution)
19:38:19:183 -> ---Q61-3-DU8361652-447545380-ENR-STK--0.0---IBIS-EUR-ENR-XETRA-72-13.911666666666665-

The order status on the order manager changes correctly to filled.
The strange request for a cash symbol continue.

Closing position:
I could identify any message in the TWS-API-log, that the close-position order has been send to TWS. It seems that the strategy monitor sends, but the order manager rejects the order.

Is wealthlab looking/requesting the open positions from TWS before placing an closing order?
If so: Is there maybe a mismatch in symbols?

Is there any function in wealthlab, which I can use to show the actual TWS positions to compare symbols and other data?

0
Cone8
 ( 6.07% )
- ago
#8
I can't explain the variability unless the contracts aren't defined precisely.
Did you create records for those contracts in IBContracts.txt?
0
Cone8
 ( 6.07% )
- ago
#9
Your symbol is SIE.SMART?
Open the Accounts Tool (Ctrl + T). What symbol is showing for that position there?

If it's not the same, please show me the records for it and all "SIE" symbols in IBContracts.txt.

I think the problem is going to be that we're matching the contract to the symbol you traded... and you're switching contracts that uses a different symbol => no match.
0
- ago
#10
Yes, there is a difference:

Ordermanager and Strategy monitor uses SIE.SMART and ENR.SMART. Account window shows ENR and SIE.
Futhermore in the screenshot: Several requests from WealthLab with wrong CASH symbol:
09:29:05:736 <- 9-8-1461-0-ENR-CASH--0---IDEALPRO-IDEALPRO-SMART-ENR.SMART--0-
09:29:05:870 -> ---D4-2-1461-200-No security definition has been found for the request--

And here the excerpt from IBContracts.txt:
ENR.IBIS=ENR|EUR|STK|IBIS|IBIS|ENR|||0|
ENR.SMART=ENR|EUR|STK|SMART|IBIS|ENR|||0|
SIE.IBIS=SIE|EUR|STK|IBIS|IBIS|SIE|||0|
SIE.SMART=SIE|EUR|STK|SMART|IBIS|SIE|||0|
(market.txt and symbol.txt are unchanged compared to installalation)

0
Cone8
 ( 6.07% )
- ago
#11
Re: IDEALPRO - those are internal IB data messages. We're not doing that.

Because you're entering multiple records for the same contract, there's not going to be a way to match different contracts with the same symbol in the Broker Account. We can only sync 1 contract to 1 unique symbol.

You'll have to turn off all the Portfolio Sync options if you want to trade this way.
0
Cone8
 ( 6.07% )
- ago
#12
That said, I still would have expected the symbol to appear with the "WealthLab Symbol" for the first record of the contract - ENR.IBIS and SIE.IBIS.

I'll look into that.
0
Cone8
 ( 6.07% )
- ago
#13
Found it. The problem was that these were matching other contracts with different currencies - so the CASH thing was actually a clue.

Fixed for IB Build 44 -
We'll make sure to match by Local Symbol, Currency, and Security Type. Still there won't be a way to match different records.
You can have multiple records, but we can only return 1 contract symbol - and it will be the first one in the file.

Example:
ENR.IBIS=ENR|EUR|STK|IBIS|IBIS|ENR|||0|
ENR.SMART=ENR|EUR|STK|SMART|IBIS|ENR|||0|

Even if you're trading with ENR.SMART, this will be the result since ENR.IBIS comes first in IBContracts.txt:

0

Reply

Bookmark

Sort