thinkScript Hide() and SetHiding() for a plot

vanczos

New member
I can't seem to find a way to dynamically hide parts of a plot. I essentially want to create a discontinuous line plot that only shows data points if they meet a condition. As far as I can tell, SetHiding() applies broadly to the entire plot, so is there any way to paint data points only if they meet a condition?

i.e. if I have a = {0, 0, 4, 5, 6, 0, 1, 3, 0, 2, 6}, I only want to display a[2] through a[4] and a[6] through a[7] based on criteria from a separate array b.

Thank you!

EDIT: After some more thought, perhaps people accomplish the look of "separate" lines by making the plot color the same as the background color? I guess I assumed the time dividers would conflict but I didn't consider the order things are painted.

In case anyone has the same problem, I hid the points by setting their color to the background color (which can be done dynamically on a point-by-point basis, which was my problem in the first place). The rgb color code (22, 22, 22) is the default background of ToS.

Code:
plot_name.AssignValueColor(if show_condition_is_true then color.red else CreateColor(22,22,22));
 
Last edited:
Solution
After some experimentation it appears that there is a limitation on the SetHiding() function.

Strangely, the SetHiding() function only works if the condition compares constants. If you try to compare values calculated within the script (such as if an oscillator is below an EMA, then it doesn't work .. at least for me, on 2023/02/27 @ 5pm CST).
After some experimentation it appears that there is a limitation on the SetHiding() function.

Strangely, the SetHiding() function only works if the condition compares constants. If you try to compare values calculated within the script (such as if an oscillator is below an EMA, then it doesn't work .. at least for me, on 2023/02/27 @ 5pm CST).
 
Solution
SetHiding is like unselecting the checkbox to show a study. It is designed for a one-time on/off switch.

If you want to dynamically hide studies, you could consider having your study plot show Double.NaN when the condition is true. This would mean, however, that you would need to have the data for your plot stored in a def variable so you could say: if condition then plot = Double.NaN else plot definition.

This would only hide it on the chart for some bars, however, so you'd just have a study with gaps rather than a fully hidden study. not sure if that meets your needs.
 
Normally that would work, but when using gradient colors it's not an option as it completely screws up the gradient. (Which itself is very poorly implemented... If you fade from something like Light-Blue to Orange it starts producing Green as they cross 🤯)

What is the consensus - should this be reported as a bug?

- My thought is yes, based on the following reasons;

1) If we're expected to use NaN to hide plots anyway, then why add a SetHiding function?

2) The SetHiding description makes it appear as though it's for dynamically hiding plots...

Code:
SetHiding ( double condition);   

Description
Controls visibility of a plot depending on a condition. If this condition is true, the plot is hidden; otherwise the plot is visible.

... Since when are "conditions" only allowed to be between constants?

3) Plus, the example given on the. SetHiding function's page is demonstrating dynamic hiding using GetAggregationPeriod. The key difference being GetAggregationPeriod() is one of the few functions that returns a pure constant.

As is, the SetHiding function can only be used for "dynamically" hiding plots based on things that don't change once the study has started (unless settings somewhere are changed).

Personally, I find the constant/non-constant restrictions to be an absolute ("constant") pain.

Sorry for the rant (and bad pun).
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
206 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