Possible to create a script parser/interpreter to automate Thinkscript conversion to Python? Future issues could warrant this, what would you do then?


Active member
Apologies if this has already been discussed before, I didn't see answers to each of my questions. I'm interested in thoughts from those of you who understand programming at a deeper level than Thinkscript tinkering, and understand the documentation on the Thinkscript language and the limits of how transparent its built-in functions are.

Suppose that someday, TD Ameritrade / Schwab became an awful broker platform either because they started offering scammier fills, charging exorbitant trade fees, etc. In that case, if we'd developed a profitable strategy reliant on Thinkscript indicators and therefore locked to the ThinkOrSwim platform, we'd want to port the indicators to a new platform. Would it be possible to do this with a 1:1 or nearly 1:1 replication of how they function on ThinkOrSwim?

Even without having to entertain hypothetical scenarios, we can consider now the fact that TD doesn't allow premarket trading before 7am. So with a sufficiently profitable strategy based on custom Thinkscript indicators, it would make sense for someone who wakes up early to port everything to a code language that could integrate with a broker that allows premarket trading from 4am onwards (assuming that the strategy worked as well at 4am as later, and suffered from the delay involved in chart-reading on ToS and then entering orders on another platform during early premarket -- that's money lost for every hour that we can't trade if our strategy works just as well during those locked-out early hours). Likewise with the poor availability of shares to short small caps, and I'm sure there are other reasons that some people might benefit from changing platforms.

The relevant questions, then, are:

1) Is the Thinkscript language well documented enough and its inner workings transparent enough that a workspace of studies could be reliably converted and reproduced accurately in another language / platform?

2) Is the complexity of that conversion something that would necessarily require manual human effort, or could it be automated by an interpreter that is programmed to parse and convert Thinkscript into another language?

3) Would it take hundreds of hours to either manually convert a complex workspace or develop an automation tool for converting Thinkscript, or should it be possible with only a few dozen hours or less given sufficient programming capability?

4) Would developing such an automation tool, if possible, and making it available publicly be in violation of the ToS user agreement or raise possible legal risks?

5) What is the main reason or reasons that such a tool hasn't already been developed?

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

this is my 0.02.
i'm no expert. i'm self taught with some programming languages. i'm just starting to learn python. murach's python programming book.

00a] ..port to...
i am happy with tos today. but i don't trust them to hold my studies forever, which is why i have text file copies of every study i have altered/made. if i change brokers, then i will manually convert a few.

00b] currently, tos works well for many people. if tos doesn't perform adequately for someone, they can search out a different broker.

01] are all functions documented, yes. could it be better, yes.
can tos studies be manually replicated to other platforms, i'll say mostly yes.
excluding exceptional programmers, i think someone must have a working knowledge of the thinkscript (or trading scripts) and how it interacts with the data stream, in order to convert a study.

02] anything can be automated. some things take a lot longer to do.

03] that is 2 wildly different questions.
...100s of hrs to manually convert?
don't think so. i haven't created a pinescript, but have converted one to thinkscript in a couple hours, by looking at a pine manual.
...time to create a conversion tool?
anybody's guess.
depends on the resources put into the project. 1 guy who knows a little bit could spend months on it. a good team,... weeks??

04] i don't think so. most of the studies are available elsewhere and described on stock trading web sites. TD has a few
proprietary scripts, that have hidden code. so you can't see them to copy them.
the issue would be when someone converts a purchased script and then distributes it.

05] why not?
speaking generaly, i'm going to guess:
...personal need,
no one uses dozens of studies to warrant the need of a conversion tool if they switch brokers.
If someone has the skills to make this, they're going to just make/remake the studies they need, in the environment they use.
...free time,
there may be people with skills to do it, but don't have the time, or no interest in it.
...or it does exist somewhere, but you haven't found it yet.

another guess, if someone changes brokers, there is a good chance they can search and find new studies, similar to what they had in the previous broker.
Last edited:
the most flexible effort would be to create a grammar that describes thinkscript and use a parser generator to emit code.

one well documented example is antlr. it is widely used, well documented, and there are hundreds of examples of existing grammars to crib from. one could use it to describe thinkscript and then anyone could generate code in Java, C#, Python, JavaScript, Go, C++, Swift, Dart, or PHP.
of course, antlr isn't the only game in town. there are plenty of other formats and tools. it is probably the easiest to bootstrap, though.
(grumpy old unix folks like me used flex/lex/yacc/bison and such but that typically only gets you as far as emitting C code.)

if there's interest, it could be a project that could be collaborated on via github or similar.
1) Yes, thinkscript is rather simple and generic among numerous similar scripting languages, brokerages, and platforms.

2) Human / manual conversion isn't required due to complexity, but rather, the simplicity negates the need for automation in the first place.

3) Just translating your scripts from one language to another is EXTREMELY easy compared to writing a tool to automate the process.

4) Nobody is going to file a lawsuit because you changed SimpleMovingAvg() to SMA(). Again, these languages are very generic.

5) It simply isn't needed. Well, not for real traders. It might be a good opportunity for meta-grifters who would rather just try to sell things to traders than actually trade, or a challenging experience for programmers who might find it entertaining, and so on.

if we'd developed a profitable strategy reliant on Thinkscript indicators and therefore locked to the ThinkOrSwim platform

This is simply not the case.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
435 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.