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).
You can hide or show your plot programmatically with the function “SetHiding()”. The argument should be 0 for show, 1 for hide. If you wanted to show our EMA only when price was above today’s open, you could use this code:

Code:
myindicator.setHiding(if close>open(period="DAY") then 0 else 1);

Note that this will either hide or show THE ENTIRE plot based on the results of the “if” test in real time.

Code:
plot_name.AssignValueColor(if show_condition_is_true then color.red else CreateColor(22,22,22));

Is there no other way to turn off plots during certain conditions only?
 
Hello, new to the forum. I've been learning everything I can about scripting, and this site seemed like a great resource.

I've tried searching here and other places, but I can't seem to find a way to do what I'm looking for, so it may not be possible.

Is it possible to hide an entire study based on a condition? I know you can hide individual plots, but this would be tedious when you want to hide all of them in a single study. I will use that approach if it is the only option, however.

Also as a bonus question, is it possible to show only a bubble for a plot, and not the plot line? When I turn off the plot, it automatically hides the bubble as well. Any way around that?

Thanks for the help guys.
 
As far as I can tell, you can hide an entire upper study using conditions like declare hide_on_intraday; and declare hide_on_daily;
 
As far as I can tell, you can hide an entire upper study using conditions like declare hide_on_intraday; and declare hide_on_daily;
Thanks for the extremely fast response. I don't think this would work in my case however, so maybe I'll give a brief description of what I'm trying to achieve.

In short, I want to hide the studies I used to take a position once I've taken the position.

def pos = GetAveragePrice();

if pos > 0 then {Study.Hide()} else {Study.Show()}

When I think about how plots work, it makes sense that there may be no way to do this at a study level, but thought I'd check.
 
I recently set out to implement my own version of the TOS Sequence Counter study. The TOS version is lacking on many fronts; Several guidelines associated with the TD Sequential indicators are not implemented in this study. I wish I had the code to build upon it.

This morning, I ran into an issue with the SetHiding method. It seemed quite straightforward, but when I used it, I just couldn't get it to hide my plot even though the condition I'm passing it is true. Here's the experimental code that shows the problem. I've even plotted the condition itself to make sure it's correct (=1) in the data box.

Any help would be appreciated.

Code:
declare upper;
#
input Setup_Min = 9;

def TDSS_CONDITION = if close > close[4] then yes else no;
def TDBS_CONDITION = if close < close[4] then yes else no;
def buPF = TDSS_CONDITION and TDBS_CONDITION[1];
def bePF = TDBS_CONDITION and TDSS_CONDITION[1];

def TDSS;
if buPF
then {
    TDSS = 1;
} else {
    if TDSS_CONDITION
    then {
        TDSS = TDSS[1] + 1;
    } else {
        TDSS  =TDSS[1];
    }
}

def TDBS;
if bePF
then {
    TDBS = 1;
} else {
    if TDBS_CONDITION
    then {
        TDBS = TDBS[1] + 1;
    } else {
        TDBS  = TDBS[1];
    }
}

plot TDSS_PLOT = TDSS;
plot TDBS_PLOT = TDBS;

plot TDSS_HIDE = if TDBS_CONDITION and TDSS[1] < Setup_Min then 1 else 0;
plot TDBS_HIDE = if TDSS_CONDITION and TDBS[1] < Setup_Min then 1 else 0;

TDSS_PLOT.SetHiding(TDSS_HIDE);
TDBS_PLOT.SetHiding(TDBS_HIDE); 

TDSS_PLOT.DefineColor("ORANGE", CreateColor(255, 128, 0));
TDBS_PLOT.DefineColor("ORANGE", CreateColor(255, 128, 0));

TDSS_PLOT.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
TDBS_PLOT.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
TDSS_PLOT.SetDefaultColor(TDSS_PLOT.Color("ORANGE"));
TDBS_PLOT.SetDefaultColor(TDBS_PLOT.Color("ORANGE"));

# End Study
 
Last edited by a moderator:
Hi. I’m trying to understand what I have to put on a script to hide a set of plots on a specific time frame.

for example:

plot RedLine_1
plot RedLine_2
plot RedLine_3

Now I want to place an input Hide function when these 3 plotted redlines when i switch to a weekly Timeframe.

any help on this would be greatly appreciated!!
 
Thanks Ben. I should have added that there are other plots in there which I would like to avoid hiding.

say:
plot greenline_1
Plot greenline_2

declare hide daily would hide all the plots?

I wanted to just place it for redline

wonder if I have to individually do the following if there is no better way.

example:
input Hide_Redline_1_on= {monthly, default Weekly, Daily, Hourly, None}
input Hide_Redline_2_on= {monthly, default Weekly, Daily, Hourly, None}

was hoping not to have this much noise. Let me know if this way is the best way to go about it.

thanks again for all your great work here!
 
@azmaestro You could use a comparison to GetAggregationPeriod() as a condition for whether or not to plot those lines...

Ruby:
plot RedLine_1 = GetAggregationPeriod() < AggregationPeriod.WEEK  [and . . . . ] else Double.NaN;
Thank you. I have tried this and it still kept those lines on the time frame. At this point I created an individual script for each of my different lines. Issue I’m running across is hiding an entire study on the 4hour time frame as the only options are hide on daily and hide on intraday. Thanks again for any further help on this.
 
@azmaestro
you are limited to hide on intraday or hide on daily because of this you have to trick it.
you can trick it using seconds from time if your on a intraday multiday chart...
if time from the prior day close is equal to 1600 and prior day close previous bar is equal to 1200 then hide_on_intraday else plot.

theory is the prior day close is equal to 1600 and the prior bar has to equal 1200, this is 4hours, so if its 4 hours then dont show and everything else show.
 
Last edited:
@azmaestro
you are limited to hide on intraday or hide on daily because of this you have to trick it.
you can trick it using seconds from time if your on a intraday multiday chart...
if time from the prior day close is equal to 1600 and prior day close previous bar is equal to 1200 then hide_on_intraday else plot.

theory is the prior day close is equal to 1600 and the prior bar has to equal 1200, this is 4hours, so if its 4 hours then dont show and everything else show.
Thank you, nice trick workaround. New to scripting. How would I write that on the script. Sorry lol. I tried a few ways but couldn’t figure it out.
 
to be honest with you i have a few studies that I've used that i didn't ant showing on certain intraday timeframes and i just would leave the chart with the timeframes i wanted individually rather than attempt to code what i mentioned above just for simplicity. However in the case that someone might pick up your request you will First need to post the code and explain a bit more what you want done so someone can attempt to code it.
 
.sethiding did end up doing the trick. Some rookie mistakes on my behalf between the < and > plus selecting four hour as the aggregate period instead of Hour.

insert plot name<.setHiding(getAggregationPeriod() >AggregationPeriod.HOUR);

Thanks everyone for the assistance on this.
 
.sethiding did end up doing the trick. Some rookie mistakes on my behalf between the < and > plus selecting four hour as the aggregate period instead of Hour.



Thanks everyone for the assistance on this.
glad you found it, when i typed it into the thinkscript learning center i typed "hide" so it missed "hiding" which is the only thinkscript syntax ending in "ING" for hiding... lol ..was funny because i was thinking i could have sworn there was a easier way, glad you found it and shared your update
 
I recently set out to implement my own version of the TOS Sequence Counter study. The TOS version is lacking on many fronts; Several guidelines associated with the TD Sequential indicators are not implemented in this study. I wish I had the code to build upon it.

This morning, I ran into an issue with the SetHiding method. It seemed quite straightforward, but when I used it, I just couldn't get it to hide my plot even though the condition I'm passing it is true. Here's the experimental code that shows the problem. I've even plotted the condition itself to make sure it's correct (=1) in the data box.

Any help would be appreciated.

Code:
declare upper;
#
input Setup_Min = 9;

def TDSS_CONDITION = if close > close[4] then yes else no;
def TDBS_CONDITION = if close < close[4] then yes else no;
def buPF = TDSS_CONDITION and TDBS_CONDITION[1];
def bePF = TDBS_CONDITION and TDSS_CONDITION[1];

def TDSS;
if buPF
then {
    TDSS = 1;
} else {
    if TDSS_CONDITION
    then {
        TDSS = TDSS[1] + 1;
    } else {
        TDSS  =TDSS[1];
    }
}

def TDBS;
if bePF
then {
    TDBS = 1;
} else {
    if TDBS_CONDITION
    then {
        TDBS = TDBS[1] + 1;
    } else {
        TDBS  = TDBS[1];
    }
}

plot TDSS_PLOT = TDSS;
plot TDBS_PLOT = TDBS;

plot TDSS_HIDE = if TDBS_CONDITION and TDSS[1] < Setup_Min then 1 else 0;
plot TDBS_HIDE = if TDSS_CONDITION and TDBS[1] < Setup_Min then 1 else 0;

TDSS_PLOT.SetHiding(TDSS_HIDE);
TDBS_PLOT.SetHiding(TDBS_HIDE);

TDSS_PLOT.DefineColor("ORANGE", CreateColor(255, 128, 0));
TDBS_PLOT.DefineColor("ORANGE", CreateColor(255, 128, 0));

TDSS_PLOT.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
TDBS_PLOT.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
TDSS_PLOT.SetDefaultColor(TDSS_PLOT.Color("ORANGE"));
TDBS_PLOT.SetDefaultColor(TDBS_PLOT.Color("ORANGE"));

# End Study
its looking for a double, not a bool or integer...
 

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
181 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