How to debug ThinkScript


Active member
I use Labels a lot. I like to put direction and percentages in a Label rather then taking up valuable screen space as a bottom indicator.

Yesterday I ran into a problem. Pretty simple code. But it just wouldn't work.

So I changed all my def variable definitions to plot definitions. This of course totally messed up the indicator's rendering; as these Label variables were near the zero range. But that didn't matter, as I was not interested in the indicator's plot. From the Style drop down, I tuned on the Floating Data Box, and suddenly all my def variables, (now rendered as plot variables), were visibly available in the Data Box, bar by bar.

Once I saw them in action like this, it was fairly simple to figure out the error in my code.

So... if you're ever stuck, temporarily convert the def variables in question to plot variables, so the show up in the Data Box.


New member
Is there a plugin (or similar) that allows use of Visual Studio to edit and debug thinkscripts (e.g., ability to step through code and see interim variable values)?

Failing that, is the best one can do, in terms of debugging, to let the entire script execute and look at values generated in a plot, as suggested by @Townsend here?


Well-known member
@dj45 No, there is no debugger other than insuring proper Thinkscript Editor code syntax while editing... And it only tests syntax, not semantics...


Well-known member
i use addchartbubble() to help me debug, to display variable values, on a chart.
you can use "\n" to force a return, to start the next text on a new line.
this is a long example
addchartbubble(show_bubbles and !isnan(volume), 0, 
 "v0 " + volk + "k" + "\n" + "v1 " + vol1k + "k" + "\n" + "v2 " + vol2k + "k" + "\n" + "v3 " + vol3k + "k" 
 + "\n" + "sm " + (vol1k + vol2k + vol3k) + "k" + "\n" +   "s " + pvsumk + "k" + "\n" + "av " + pvavgk + "k" 
 + "\n" + "% " + volpctz, if nmulti then color.yellow else color.cyan,yes);
Last edited: