How to debug ThinkScript

Townsend

Active member
VIP
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.
 

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

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?
 
@dj45 No, there is no debugger other than insuring proper Thinkscript Editor code syntax while editing... And it only tests syntax, not semantics...
 
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
Code:
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);
VK5TxLI.jpg
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
464 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.
Back
Top