Page 1 of 3

Multiple strategies

Posted: Wed Apr 26, 2017 1:38 pm
by sectorbets
I am running live a TradeStation strategy that has two separate sub scripts, each of which launch both SPY and ES orders to an IB master account, and it works great.

I want to add two more strategies right now -- one for VX and one for GC -- and have them send orders to the same IB master account. The easiest way to implement on the TradeStation end would be to just run them as standalone scripts, but am I correct that I would need a separate TWSLink license for each script. An alternative would be for the three scripts to send signals via the Global Dictionary to a "master script", and I run TWSLink just in that script that picks up the signals from the three other scripts, and use the "master script" to send orders to IB.

Over time I hope to have maybe ten different contracts active which means ten different scripts, so am trying to make the best decision right now so I have a cost effective approach for the future.

Thank you
Rick

Re: Multiple strategies

Posted: Wed Apr 26, 2017 3:29 pm
by board_admin
Hello,
TS 9.x splits into multiple processes. Each process is loading a TWSLink instance.
In prior versions we had the license linked per IB account (or per instance).
But this is no longer the case.

With 1 license you can run as many TWSLink instances per machine you like.

If you should see a license fault, please write us an email. Old license still have instance lock.
We will switch it to machine lock.

Re: Multiple strategies

Posted: Wed Apr 26, 2017 3:38 pm
by sectorbets
You guys are the best !! I will test multiple instances over the next couple of days and get back to you.

Thank you
Rick

Re: Multiple strategies

Posted: Wed Apr 26, 2017 3:46 pm
by sectorbets
Do I use

CONNECT(ip,port,clientid)

in each TradeStation script, or just one time in the first script I start ??

Thank you
Rick

Re: Multiple strategies

Posted: Wed Apr 26, 2017 7:35 pm
by board_admin
Each time, TS will start a new process, you need to provide a new client id.
Also, let's say your script A trades Symbol s1,s2,s3 and you connect with clientid=85,
then next time you start this script to trade those 3 symbols, you should connect again with clientid=85.

Re: Multiple strategies

Posted: Wed Apr 26, 2017 11:20 pm
by sectorbets
Just to be sure I understand, I am using the following currently:

Connection = CONNECT("",7499,1,500);

As I add TS strategies, I should still use 7499, but should change 1 to 2, and then 3, and so forth for each new strategy ??

Thank you
Rick

Re: Multiple strategies

Posted: Thu Apr 27, 2017 12:09 pm
by board_admin
As TWSLink is loaded per process, you need a clientid per process

Re: Multiple strategies

Posted: Fri Apr 28, 2017 10:49 am
by ke45
Well, I have the same question about many automated charts (in my case there are about 20 charts trading different (about 8) forex symbols).

The problem is, you (Twslink) think in (windows-) processes, a TradeStation user thinks in charts. In fact TradeStation will launch many (depending on the CPU) processes to ro run the charts, the TradeStation user has no control about the distribution of charts to processes. Each chart runs independent from each other.

So If I start up TradeStation with 20 charts (running in 4 (windows-) processes) what is the right calls to Twslink in each chart to start automation properly?

Thank you
-Klaus

Re: Multiple strategies

Posted: Fri Apr 28, 2017 2:33 pm
by board_admin
"The problem is, you (Twslink) think in (windows-) processes, a TradeStation user thinks in charts"

Exactly. This is the point. Let me think about.

The challenge is provide the same clientid for the same group of symbols you trade AND that those groups
are always below the same processid. I think this could be a problem as you might have no
chance to influence this.

The problem is clearly that TS splits into multiple processes. I am pretty sure they did this to keep most
of their 32 code. (You could check, if TS is a 32 bit process). Modern applications on x64 architectur can
run in one process and split work into threads. They can access to all available memory.
Just for instance google chrome, also splits in multiple processes on new url, so when request hangs
other still can proceed.End of short excurse.

Summary: How to ensure that a group of symbols are charted below same process ?
I have no TS unfortunately.

Re: Multiple strategies

Posted: Tue May 02, 2017 9:07 am
by ke45
Hi,

of course, TS is a 32 Bit application and I don't know if and when this will change in the future? But if you want to sell your product to TS users, the product should be able to handle an every day scenario, I think?

Well, I am in the TradeStation business for more then 15 years now. I have worked with products like Dyaorder und Hyperorder in the past (both discontinued for years and not connecting to TWS any more due to changes in the API) and I was very happy to see, that there is an new product with similar functionality in the market. Why do you start multiple instances of Twslink instead of one application (like Dynaorder and Hyperorder did)?

Since TradeStation sold the forex business to Oanda last year, I am looking for alternative solutions to automate forex trading. Twslink looks good for that task, but ...

Thank you!
-Klaus

Re: Multiple strategies

Posted: Tue May 02, 2017 12:53 pm
by board_admin
This version of TS, which is splitting into multiple processes, is younger than TWSLink.

"..of course 32 bit..". After my opinion 32 bit processes are deprecated.

As i mentioned, the TS dev Team most likely decided to split the application in multiple process
to avoid checking old 32 bit code for 64 bit usage. Perhaps they did it fo safty reasons
(if one chart crashes, others can still proceed).

So i see the Problem not with TWSLink. TWSLink can be used with any application
that can load DLL/COM, not just TradeStation.


As i mentioned some posts ago, the TWSLink license is no longer per instance, it is per machine.
So the # of running TWSLink instance on your machine using your license is not limited.

However, you can't connect more than 8 TWSLink to TWS or gateway
because this is a limitation by IB.

Re: Multiple strategies

Posted: Tue May 30, 2017 2:18 pm
by sectorbets
I am trying to run two instances of IB -- one live and one in paper trade mode. I am using the following to connect to the two versions:

Connection = CONNECT("",7499,1,500) for the live version of IB
and
Connection = CONNECT("",7498,2,500) for the paper trade version

I am using ES contracts for the test.

I am running one copy of TradeStation with two different windows open. The TS code is identical in the two windows except for the CONNECT statements above and the number of contracts traded -- 3 for the live version of IB and 10 for the paper trade version.

I got a signal in each of the TradeStation windows, but the paper trade version executed the trade twice at IB -- 10 contracts each time -- and the live version didn't execute at all.The live version of IB has been running perfectly for over 8 months, so I am thinking that the paper trade and live version are interacting somehow.

Should I be doing something different

Thank you
Rick

Re: Multiple strategies

Posted: Tue May 30, 2017 3:06 pm
by sectorbets
Additional information:

I turned off the live IB account, and everything is working perfectly in the paper trade account just as it did running only the live account for the last many months.

So, if I want to run a live IB account simultaneously with a paper trade account and a single instance of TS with two open windows with identical code and identical contracts, can it be done ?? And can I run the same way with different contracts on the live IB machine and paper trade machines ??

Thank you
Rick

Re: Multiple strategies

Posted: Tue May 30, 2017 7:39 pm
by board_admin
With the normal license, you now can run as many TWSLink instance you like.
Each TWSLink instance can connect to exactly one TWS.
Each Windows process can load only one TWSLink instance (This applies for all kind of DLL,COM).

So, if you run a single TS process, you just can connect to one TWS as you just can load only
1 TWSLink instance.

Windows Process 1 <----> 1 DLL/COM == TWSLink 1 <---->1 TWS

->>
"So, if I want to run a live IB account simultaneously with a paper trade account and a single instance of TS with two open windows with identical code and identical contracts, can it be done ?? "

No

What TS 9 users really need is: a TWSLink host application capable to connect to multiple TWS/gateway.
A lightweight 'satellite' plugin to be loaded in TS, connecting to the TWSLink host.

int connectionid=CONNECT(IP,port,....)
Changed functions like : PLACE_ORDER(connectionid, uidc, uido,.....)

Satellite, because the plugins would be in the orbit (connected) around the host application.

Re: Multiple strategies

Posted: Tue May 30, 2017 8:47 pm
by sectorbets
Sounds like I would have to have one TS and one TWSlink license for development and one for production -- is that correct

What you describe is what I was trying to avoid, but I do have a prototype almost ready to test -- it doesn't completely solve the paper trade / live account problem, but does let me run several scripts on different contracts at the same time with a single TS license

Thank you
Rick

Re: Multiple strategies

Posted: Tue May 30, 2017 8:57 pm
by board_admin
No. The license you have, basically allows running multiple TWSLink instances each connecting to different TWS.
But as one Windows process can only load one TWSLink and one TWSLink instance can only connect to one IB account,
you won't be able to connect to paper and real account at the same time from within one TS process.

For your use case, you would need a different kind of TWSLink, like i described in my prev. post.

Allow me to repeat: You can connect to different IB accounts from within 2 different processes with your license.

For instance, load TWSLink in Excel, connect to paper and load TWSLink in TS and connect to real. You will see it works.
You could use our short Excel sample for this:
https://trade-commander.com/twslink/excel-example/

Re: Multiple strategies

Posted: Tue May 30, 2017 9:11 pm
by sectorbets
I don't know much about Excel -- could I link TS to Excel real time to pick up the order information from TS and then use your example of Excel to send orders to the paper account while TS was working with the real account ??

Re: Multiple strategies

Posted: Tue May 30, 2017 9:19 pm
by board_admin
Possible yes, for instance using a custom DLL but eligible ? For me sounds very complicated.

What do you like to accomplish with paper and real trading same time. Can you describe this with few words ?

Re: Multiple strategies

Posted: Tue May 30, 2017 9:35 pm
by sectorbets
TS data feeds and licenses cost about $250 per month, so we try to use just one TS license for our each of our projects. Ideally we would use one license for both development work as well as production. That isn't usually a problem when running everything in TS, but with IB's paper trading structure, we actually have to login to IB twice which is what creates the problem -- we always run in simulation mode (paper trading) for at least 100 days before moving things to production, and we usually move only one thing at a time to production, so we would almost always have two TWS accounts active.

Thank you
Rick

Re: Multiple strategies

Posted: Tue May 30, 2017 9:56 pm
by board_admin
Ok. Have to think about.

Meanwhile, you could get in contact with trade station support and ask them something like that:

"I have a DLL plugin used in my TS scripts. Some scripts are for production, some scripts
are for development.
The DLL connects to a backend that can either be a production backend or a development
but not both.
Is there any method to keep production scripts in one TS process and development scripts in another TS process?"

Perhaps you should only ask this. Do not mention any backends. Just ask them, if it is somehow possible
to spawn specific scripts in dedicated TS processes.

If this is possible and you can figure out in your script: "i am in a production script (and so process)", just
do the real IB account connect with TWSLink.
If you are in development script, you just do the paper account connect.

Again, what's important for this:
a) TS splits in multiple processes (remember: each can load a TWSLInk)
b) You can somehow group all production scripts in process A and all development scripts in process B