Thinkorswim Strategies Complex Stop Management
A brief article to contain my recent experience trying to program a transitional stop management into a Strategy on the Thinkorswim platform. The client wished to have the initial stop based on existing price structure. Then after unrealized profit equaled initial risk, the stop would be passed onto some other tool. After several hours of what I not so affectionately refer to as “coding wack-a-mole”, I took a couple of days off to refresh my perspective. When I came back to the project it suddenly dawned on my what I was fighting against, and realized I didn’t have the firepower to overcome. Not yet anyway.
For more information about developing Strategies on Thinkorswim and analyzing the output please review the following posts:
Here is a not so brief description explaining the hazards of coding a complex stop management into a Strategy in Thinkorswim. The placement of theoretical orders of a strategy are very difficult to predict. The key to understanding this, we’ll call “potential entry”. The code may sprinkle dozens of “potential entries” throughout the chart while the Strategy may only use half of them.
It can only hold a single position at a time. While a theoretical position is open, you may encounter a new “potential entry” in the code. Which would reset all the trailing stop parameters. Chaos ensues as the code is completely unaware that the Strategy already has an open position and that particular entry is being ignored.
Case in Point:
You have two entry signals within several bars. On which one does the Strategy place the Theoretical order? First? Second? Both? Or None? Well that depends on whether there is a current open position, and the conditions used to exit the position. Not to mention the potential for opposing entry signals. Change a few of the variables and you can see any one of those four outcomes.
What is Lacking:
Which makes it extremely complex to write code to manage stops. In other platform languages, the code has access to position status. The code can be aware of long, short and trade size. Not to mention portfolio equity. Thinkorswim is severely limited in this regard. But it does a great job considering how much it costs. The other factor is the way Thinkorswim implements a Strategy. Everything is modular. You are able to use one piece of code for your long entries, another piece of code for your short entries, and then use entirely different pieces of code to manage the exits. It’s designed to let you mix them around like Lego’s.
I do have some vague idea that one could build a sort of framework. A framework that could unify the entries and exits and keep track of current position type and status. But my mind is a long way off before that vague idea becomes a reality.