Fully automated trading using TradeStation 9.1 and TWS-Link

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
Post Reply
Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Fully automated trading using TradeStation 9.1 and TWS-Link

Post by Rocket130713 »

Hello, I want to use the following trading setup to do 100% automated trading: TradeStation 9.1 platform + TWS-Link DLL + IB broker (TWS API), can this be done using Financial Advisor or Money Manager account at IB?

For example, I want to send a large "block order" (for example, BUY 700 Gold contracts) to my IB Master Account and then instruct TWS (via the "Allocation Profiles", or, "Account Groups" settings in TWS) to allocate these 700 contracts to 100 client sub-accounts all done automatically without human intervention, is this possible using TradeStation 9.1 +TWS-Link DLL + IB Financial Advisor account method? Or will there be some problems doing this, like problems doing proper "order handling" within the TradeStation EasyLanguage code? Is managing 100 client sub-accounts possible using TWS-Link DLL and TradeStation 9.1 platform, do you know of any other traders or money managers that have already successfully done this using TWS-Link?

Many thanks in advance. Kind regards, Rod.
Last edited by Rocket130713 on Mon Mar 12, 2018 4:36 am, edited 1 time in total.

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

Re: Fully automated trading and TWS-Link

Post by board_admin »

Hello,
generally this should be possible. But in particular TradeStation may has some stumbling blocks, as it spreads into multiple processes
and so TWSLink is loaded multiple times. Each instance makes its own connection to API (TWS/Gateway) and so you need to
do some work in order to use different clientids for each connection. You also need a technique, that always the same client
ids are used for same scripts, because the API grants control about orders through the clientid.

For instance, if you connect with clientid=1234, then you place a limit, then, when you start TS next time and TWSLink connects
again and you connect with clientid=534535, you can get control about this limit order: Only the client with id=1234 is getting control.

But i think here are some TS 9 users who already solved this. Perhaps you should also set TS to start only 1 process for scripts.
I believe this removes many problems.

Orders with an allocation are ususally completed by calling function SET_FA_MEMBERS with transmit flag=1.
Before you call PLACE_ORDER with transmit flag=-1 (and some SET_ORDER_VAL, if required, also with transmit flag=-1).

If you need to serve 100 subaccounts, i recommend to set the account information to summary or off, if you do no need account data.
You do this settings in the TWSLink.xml, which is usually located in

Code: Select all

C:\Program Files (x86)\trade-commander\twslink2\xml
Then make sure that <acc_update_mode> is set to

Code: Select all

<acc_update_mode ttl="off,summary,full">summary</acc_update_mode>
or

Code: Select all

<acc_update_mode ttl="off,summary,full">off</acc_update_mode>
If you do not need account data information.

Because, when you connect, TWSLink is fetching all the detailed account information for all 100 subaccounts and
this can take a while because IBs API takes time to send all those data.

The declarations and a small sample for using TWSLink in TS 9 can be downloaded here:

https://trade-commander.com/?ddownload=416

more example here:

https://trade-commander.com/public-downloads/

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Fully automated trading and TWS-Link

Post by Rocket130713 »

Thanks for your help. Really appreciate it. This is great software. Especially for the many TradeStation platform users out there.

Regards, Rod.

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Fully automated trading using TradeStation 9.1 and TWS-Link

Post by Rocket130713 »

Hello, using TWS-Link and TradeStation 9.1, I was able to send an order to BUY 50 e-mini Nasdaq futures contracts to my IB master account (FA paper account), and then, based on "Account Groups" method TWS was able to allocate these 50 contracts to my 5 sub-accounts with all had equal Net Liquidation Values / balances (i.e. 10 contracts in each sub-account) using this line of code which works 100% fine:

my_status = SET_FA_MEMBERS(uidOrderNQ,"DF995847","","GroupNL","NetLiq","",1);


//****//


However, using TWS-Link DLL, I could not allocate using the "Allocation Profiles" "Ratio" method (named "Profile1") in TWS, this is the code I was using, is this the correct code and way to do it?

CONNECT("",7496,1,500);

uidNQ = REGISTER_CONTRACT("NQ","FUT","USD","GLOBEX","","20180316","",0.0,"20",0,0.0);

uidOrderNQ = PLACE_ORDER(uidNQ,0,"SELL","MKT",50,0.0,0.0,"GTC", -1, 0);

my_status = SET_FA_MEMBERS(uidOrderNQ,"DF995847","","Profile1","AvailableEquity","",1);

Have never seen such a powerful DLL for automated trading at IB broker, with so many functions and capabilities as TWS-Link. This is really great software.

Thanks in advance. Much appreciated.

Regards, Rod.

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

Re: Fully automated trading using TradeStation 9.1 and TWS-Link

Post by board_admin »

Hello Rod,

Code: Select all

SET_FA_MEMBERS(uidOrderNQ,"DF995847","","Profile1","AvailableEquity","",1); 
If you pass an account name, the allocation is set to account and Profiel1 etc. is ignored.
What about

Code: Select all

SET_FA_MEMBERS(uidOrderNQ,"","","Profile1","AvailableEquity","",1); 
Can you check this out ?

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Fully automated trading using TradeStation 9.1 and TWS-Link

Post by Rocket130713 »

Your solution worked very well. I can now use IB FA accounts and allocate trades based on "account groups" and also via "allocation profile" (both percentage and ratio methods). I must say your software is brilliant and works very well. Thanks again for your help. Kind regards, Rod.

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

Re: Fully automated trading using TradeStation 9.1 and TWS-Link

Post by board_admin »

Thank you Rod. Whish you good trading!

Post Reply