Placing Adaptive Algorithmic orders

Discuss, post your questions about TWSLink here.

Users who just registered, please write an email to
forum@trade-commander.de
with your username mentioned.
So we can distinguish you from bots.
Thank you
Casey
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Placing Adaptive Algorithmic orders

Post by Casey »

Newbie, wondering how to place adaptive algo order type:
https://www.youtube.com/watch?v=IsrW76DJBF8
https://interactivebrokers.github.io/tw ... #gsc.tab=0

I am working with the batch testing tool. Thanks.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

Hello,
please try this:

// create an order
uid=PLACE_ORDER(....,transmit_flag=-1)
// now set the algo params for adaptive orders as orderval (you must know arguments)
// https://interactivebrokers.github.io/tw ... #gsc.tab=0
// name of strategy
SET_ORDER_VAL(uid,67,name_of_strategy,-1)
// params of strategy as name_val_pair := name_of_param=valu_of_param
SET_ORDER_VAL(uid,68, name_val_pair,1)

Mind the 1 as last parameter which means, send this order to IB.
The point here: Name of strategy and what name and value pair.
Please read the link above in order to figure this out.

Casey
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Re: Placing Adaptive Algorithmic orders

Post by Casey »

Thank you,

I can confirm this is working with SET_ORDER_VAL valued id 67 set to "Adaptive"
and valued id 68 set to "Normal" (or whatever desired priority)

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

Thank you

Casey
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Re: Placing Adaptive Algorithmic orders

Post by Casey »

I may have spoken too soon on this topic. It does not appear to be working today. The batch tester returns valid values, but the order does not appear in TWS.

Image

Placing a simple limit order worked fine, but the Algo type didn't go through.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

If it prev. worked and now not, what changed ?
Could it be related to the contract ? Not all features apply for all contracts.
What are the logs saying ?

Please save your script in batchtester.
Click on save again and now save at a location you will find easily.
Pick it from there and attach the script to your forum answer here.

Then close batchtester. Goto c:\trade-commander\twslink2.
Delete folder log.
Restart batchtester.
Rerun script.
Open twslink.log in the logfolder (perhaps it is below a subfolder pxxxx).Search for PLACE_ORDER or SET_ORDER_VAL
and subsequent error messages. They may point you to possible reasons.

You could also attach the log to your forum answer, so i can have a look on it.
Best attach script and logfolder. Thank you.

Casey
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Re: Placing Adaptive Algorithmic orders

Post by Casey »

Sorry, when I said it was working over the weekend, the trades were appearing in TWS with a delay and an error message saying that only RTH is allowed for Algo orders (note that tif is set to "DAY").

However, I am still receiving the same delays and message during RTH.

Image

Please test the attached batch files. The simple limit order works, the Algo does not. If I send the Algo first, it does not appear in TWS until I subsequently send the simple limit, at which point TWS shows the Algo order as cancelled by the system.

Thank you.
Attachments
batchtest.zip
(1.18 KiB) Downloaded 326 times

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

Hello,
will check it. Probably it is related to the RTH flag which can be set by SET_ORDER_VAL.

Another method to sheld light into such problems is to connect with clientid 0. That means
you get control about TWS orders.

Then run the batchtester and simply do a connect. Next, place an algo order in TWS.
Of course this should be possible without errors.

Then check twslink.log for order status message about this order and its attribute values.
This way, you may can figure out what attributes to change with SET_ORDER_VAL before
placing order finally without getting errors (because you could successfully place it in TWS).

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

You need an updated TWSLink version for an adaptive order.

New version download: https://trade-commander.com/?ddownload=281

Just install. No uninstallation required. A small fix just affecting adaptive orders.
Also the log has been extended to record adaptive order attributes.

Find attached a batch command for an NVDA adaptive order. It worked with my TWS 964 and 963.
In the batchtester click on "Import" and select the file attached.

Please let me know if it works.

Casey
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Re: Placing Adaptive Algorithmic orders

Post by Casey »

Thank you, I don't see the batch file attachment?

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

Sorry. Find attached.
Attachments
nvda_adaptive_order.zip
adaptive orders script
(622 Bytes) Downloaded 300 times

Casey
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Re: Placing Adaptive Algorithmic orders

Post by Casey »

Thank you, the batch file is working for me, but I'm getting some errors when I try to place the order from the imported DLL in C#.

Code: Select all

int contractID = REGISTER_CONTRACT("FOLD","STK","USD","SMART","","","",0.0,"",0,0.0);
int placeOrder = PLACE_ORDER(contractID, 0, "BUY", "LMT", 100, 15.00, 0.0, "DAY", -1, 0);
int setOrderVal14 = SET_ORDER_VAL(placeOrder, 14, "0", -1);
int setOrderVal67 = SET_ORDER_VAL(placeOrder, 67, "Adaptive", -1);
int setOrderVal68 = SET_ORDER_VAL(placeOrder, 68, "adaptivePriority=Normal", 1);	
This code returns valid values, but no order appears in TWS.

TWSLink log file attached.
Attachments
p16228.zip
(4.47 KiB) Downloaded 304 times

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

It is a license fault. Since about a year, twslink has a machine lock license not instance lock.
But when a new license is created, it is still instance lock (by default). I switched your license
to machine and it should work now.

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: Placing Adaptive Algorithmic orders

Post by sectorbets »

I want to test this over the next couple of weeks, but before I do, is everything working OK if I follow each step exactly ??

Also, once I get this to work, can I try some of the other IB algos, or is this only for the Adaptive Algo ??

Thank you
Rick

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

Hello,
in my tests with the new version it works. If you need other algos, please read the IB API documentation.

https://interactivebrokers.github.io/tw ... #gsc.tab=0

This provides information about parameter to be used.

Please mind: TWSLink provides much but not all features of IBs API.

For algo orders, all what is possible with IBs API should be possible with TWLlink. How it generally works,
has been discussed in this thread. Using other algos is it just a point of research in IBs API documentation and trial
with the batchtester.

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: Placing Adaptive Algorithmic orders

Post by sectorbets »

It almost worked, but not quite:

Here is my code -- I think my question is about the set_FA_members section: The order was placed correctly and the Adaptive algo was recognized correctly. The order was filled correctly, but was allocated incorrectly -- it went to "VXX Alloc" instead of VXX Algo Alloc" -- "VXX Alloc" was used in a different model so that I could compare with and without the algo. Should the set_FA_members statement come before the set_order_val statements, or should I use set_order_val to designate the FA members?

Thank you
Rick


uidOfOrderVXX=PLACE_ORDER(uidVXX,0,"BUY","MKT",PosSizeVXXX,0,0.0,"DAY",-1,0);
SetOrderVal14 = SET_ORDER_VAL(uidOfOrderVXX,14,"0",-1);
SetOrderVal67 = SET_ORDER_VAL(uidOfOrderVXX,67,"Adaptive",-1);
SetOrderVal68 = SET_ORDER_VAL(uidOfOrderVXX,68,"adaptivePriority=Normal",-1);
setFAVXX = SET_FA_MEMBERS(uidOfOrderVXX,"","","VXX Algo Alloc","","",1);

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

Twslink just forwards the alloc parmeters. A bug here is unlikely if not impossible.
Please check again on your side.

The order of the function call is whatever.
When you pass a 1 for transmit, the order is sent to IB.

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: Placing Adaptive Algorithmic orders

Post by sectorbets »

The code is exactly what you see above in the algo version -- the "VXX Algo Alloc" has been validated and there is no problem that I can see. The code without the algo is as follows:

uidOfOrderVXX=PLACE_ORDER(uidVXX,0,"BUY","MKT",PosSizeVXXX,0,0.0,"DAY",-1,0);
setFAVXX = SET_FA_MEMBERS(uidOfOrderVXX,"","","VXX Alloc","","",1);

This code is running in a different window, and its allocation is absolutely correct -- I have been running this version for about a year with never an allocation problem.

Is there a log where we can see what is sent to IB ??

sectorbets
Posts: 92
Joined: Wed Apr 26, 2017 12:41 pm

Re: Placing Adaptive Algorithmic orders

Post by sectorbets »

I found the log -- you can see that it sent in VXX Alloc instead of VXX Algo Alloc. I have verified that VXX Alloc is not anywhere in the code, but it is running in a separate window -- it's almost as if the algo order is picking up setfa instructions from teh other window



20171019 09:45:02:546 [IN] uid=97058 BUY VXX MKT 5610 DAY SMART lmt=0 aux=0 Submitted acc_? clientid=2 transmit=IB ref= nref=#~tc#;0=97058;1=20171019 09:45:00:023d;2=5610;> oca= filled=0 lastfill=0 fa group= fa profile=VXX Alloc fa method= fa percentage= gat= gtd= outside rth=0 hidden=0 algo=Adaptive algo-param=adaptivePriority=Normal oid=5253 permid=709398922 uidp=0 oidp=0 cid=50007 comment=open order
20171019 09:45:02:547;

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Placing Adaptive Algorithmic orders

Post by board_admin »

I can see. Two possible causes:
1. TWSLink itself changes the value, so deletes "Algo"
or
2. You programm passes this to TWSLink.

Please check the exp. function call as well, so watch for SET_FA_MEMBERS

Post Reply