Help with SetHiding

BOOMERMANG

New member
VIP
Trying to utilize the SetHiding command but I'm having trouble. Id like the moving average to hide when the "Close" is above it. Im trying to incorporate this into a bigger study with multiple moving averages and as the close price crosses above them the idea is that they'd disappear off the screen.

I know I could use:
Code:
def AvgExp_Def = ExpAverage(price[-displace], length);
plot AvgExp = If close(pricetype.last) >= AvgExp_Def then double.nan else AvgExp_Def;

I just wanted to try to use SetHiding. Is it possible to do? Im able to use "SetHiding" with other condition's but for some reason when I use "Close" it doesn't recognize it.

Code:
input price = close;
input length = 9;
input displace = 0;
input showBreakoutSignals = no;

plot AvgExp = ExpAverage(price[-displace], length);
plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

AvgExp.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


def Avg_HIDE = if close(pricetype.last) >= AvgExp then 1 else 0;
AvgExp.SetHiding(Avg_Hide);
 
Last edited:

halcyonguy

Well-known member
VIP
Lifetime
Trying to utilize the SetHiding command but I'm having trouble. Id like the moving average to hide when the "Close" is above it. Im trying to incorporate this into a bigger study with multiple moving averages and as the close price crosses above them the idea is that they'd disappear off the screen.

I know I could use:
Code:
def AvgExp_Def = ExpAverage(price[-displace], length);
plot AvgExp = If close(pricetype.last) >= AvgExp_Def then double.nan else AvgExp_Def;

I just wanted to try to use SetHiding. Is it possible to do? Im able to use "SetHiding" with other condition's but for some reason when I use "Close" it doesn't recognize it.

Code:
input price = close;
input length = 9;
input displace = 0;
input showBreakoutSignals = no;

plot AvgExp = ExpAverage(price[-displace], length);
plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

AvgExp.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


def Avg_HIDE = if close(pricetype.last) >= AvgExp then 1 else 0;
AvgExp.SetHiding(Avg_Hide);


i don't have an answer.
i don't think sethiding() can be used as you want.
i tried many variations, but didn't see any reliable outcomes, when variables were used in a condition, within sethiding( )

this is my test study. it has many variations of code lines that i tried.
most are disabled with #

Code:
# sethiding_var_00

# https://usethinkscript.com/threads/help-with-sethiding.14124/
#Help with SetHiding

def na = double.nan;
def bn = barnumber();

def lastbar = (!isnan(close) and isnan(close[-1]));

input price = close;
input length = 9;
input displace = 0;
input showBreakoutSignals = no;

def AvgExp = ExpAverage(price[-displace], length);

#def AvgExp2 = ExpAverage(price, 23);
#plot zz = avgexp2;


# move before plot. same
# tried [0] and [1] .  same  dont work. 
#def Avg_HIDE = if close(pricetype.last) >= AvgExp then 1 else 0;
def Avg_HIDE = if close >= AvgExp[0] then 1 else 0;
#def Avg_HIDE = if open >= AvgExp[0] then 1 else 0;
#def Avg_HIDE = if open >= 42 then 1 else 0;

#def Avg_HIDE = if AvgExp > 42 then 1 else 0;



# this works
#plot zavgexp = if close >= avgexp then na else avgexp;

plot zavgexp = avgexp;
zAvgExp.SetDefaultColor(GetColor(1));
#def Avg_HIDE = if close(pricetype.last) >= AvgExp then 1 else 0;

#def Avg_HIDE = if close >= AvgExp[0] then 1 else 0;
# doesnt work
zAvgExp.SetHiding(Avg_Hide);

#  put cond in function,  same. dont work
#zAvgExp.SetHiding( close >= AvgExp[0] );

#zAvgExp.SetHiding( close >= AvgExp2[0] );

#zAvgExp.SetHiding( close[1] >= 44 );
#plot yy = 44;


# all line gone
#zAvgExp.SetHiding( bn > 44 );
# all line visible
#zAvgExp.SetHiding( bn < 44 );

# is it determined by value at last bar ??


# shows line
#zAvgExp.SetHiding(0);


#def cnt = if (bn %4 == 0) then 1 else 0;
#zAvgExp.SetHiding(cnt);
#plot t = cnt;
#t.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);


addchartbubble(1 and lastbar, low*0.996,
 close + "\n" +
 AvgExp[0] + "\n" +
 (close >= AvgExp[0]) + "\n" +
 Avg_HIDE
, (if Avg_HIDE then color.yellow else color.gray), no);


plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#

--------------

here is something i did, that doesn't plot a line if it crosses some level.
a fold loop runs on bar#1 to read future values, then determine to plot a line or not.

https://usethinkscript.com/threads/...remove-it-once-price-hits-it.5257/#post-75706
 

Joshua

Well-known member
VIP
This will hide an average within a certain distance from the chart's right edge should the condition be met. The average will still appear far off to the left, but if you pick a large enough number, you will have to scroll back to see it, and it shouldn't interfere visually with recent prices.

Its not perfect, but in regard to sethiding() not accepting ohlc data, and the typical work-arounds being laggy or forcibly invoking the once_per_bar throttle, I believe this would be the most efficient method.

If you don't want to wait to see the effect, flip the ">" sign back and forth.

input EdgeDistance = 200;

def EdgeCount =
if !EdgeCount[1] and isNaN(close[-EdgeDistance]) then 1
else if isNaN(close[-EdgeDistance]) then EdgeCount[1] + 1
else no
;

def EdgeRem = EdgeDistance - EdgeCount;
def SMA = SimpleMovingAvg(close,20);

def eSMA = GetValue(SMA,-EdgeRem);
def eCls = GetValue(Close,-EdgeRem);

plot x = if EdgeCount and eCls > eSMA then Double.NaN else SMA;
x.setpaintingStrategy(paintingStrategy.POINTS);

plot y = SMA;
 

BOOMERMANG

New member
VIP
i don't have an answer.
i don't think sethiding() can be used as you want.
i tried many variations, but didn't see any reliable outcomes, when variables were used in a condition, within sethiding( )

this is my test study. it has many variations of code lines that i tried.
most are disabled with #

Code:
# sethiding_var_00

# https://usethinkscript.com/threads/help-with-sethiding.14124/
#Help with SetHiding

def na = double.nan;
def bn = barnumber();

def lastbar = (!isnan(close) and isnan(close[-1]));

input price = close;
input length = 9;
input displace = 0;
input showBreakoutSignals = no;

def AvgExp = ExpAverage(price[-displace], length);

#def AvgExp2 = ExpAverage(price, 23);
#plot zz = avgexp2;


# move before plot. same
# tried [0] and [1] .  same  dont work.
#def Avg_HIDE = if close(pricetype.last) >= AvgExp then 1 else 0;
def Avg_HIDE = if close >= AvgExp[0] then 1 else 0;
#def Avg_HIDE = if open >= AvgExp[0] then 1 else 0;
#def Avg_HIDE = if open >= 42 then 1 else 0;

#def Avg_HIDE = if AvgExp > 42 then 1 else 0;



# this works
#plot zavgexp = if close >= avgexp then na else avgexp;

plot zavgexp = avgexp;
zAvgExp.SetDefaultColor(GetColor(1));
#def Avg_HIDE = if close(pricetype.last) >= AvgExp then 1 else 0;

#def Avg_HIDE = if close >= AvgExp[0] then 1 else 0;
# doesnt work
zAvgExp.SetHiding(Avg_Hide);

#  put cond in function,  same. dont work
#zAvgExp.SetHiding( close >= AvgExp[0] );

#zAvgExp.SetHiding( close >= AvgExp2[0] );

#zAvgExp.SetHiding( close[1] >= 44 );
#plot yy = 44;


# all line gone
#zAvgExp.SetHiding( bn > 44 );
# all line visible
#zAvgExp.SetHiding( bn < 44 );

# is it determined by value at last bar ??


# shows line
#zAvgExp.SetHiding(0);


#def cnt = if (bn %4 == 0) then 1 else 0;
#zAvgExp.SetHiding(cnt);
#plot t = cnt;
#t.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);


addchartbubble(1 and lastbar, low*0.996,
 close + "\n" +
 AvgExp[0] + "\n" +
 (close >= AvgExp[0]) + "\n" +
 Avg_HIDE
, (if Avg_HIDE then color.yellow else color.gray), no);


plot UpSignal = price crosses above AvgExp;
plot DownSignal = price crosses below AvgExp;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#

--------------

here is something i did, that doesn't plot a line if it crosses some level.
a fold loop runs on bar#1 to read future values, then determine to plot a line or not.

https://usethinkscript.com/threads/...remove-it-once-price-hits-it.5257/#post-75706
Thank you for the reply! I too tried, tried, and tried... couldn't find anything that works. I think you're right its just not possible with '"sethiding".

This will hide an average within a certain distance from the chart's right edge should the condition be met. The average will still appear far off to the left, but if you pick a large enough number, you will have to scroll back to see it, and it shouldn't interfere visually with recent prices.

Its not perfect, but in regard to sethiding() not accepting ohlc data, and the typical work-arounds being laggy or forcibly invoking the once_per_bar throttle, I believe this would be the most efficient method.

If you don't want to wait to see the effect, flip the ">" sign back and forth.

input EdgeDistance = 200;

def EdgeCount =
if !EdgeCount[1] and isNaN(close[-EdgeDistance]) then 1
else if isNaN(close[-EdgeDistance]) then EdgeCount[1] + 1
else no
;

def EdgeRem = EdgeDistance - EdgeCount;
def SMA = SimpleMovingAvg(close,20);

def eSMA = GetValue(SMA,-EdgeRem);
def eCls = GetValue(Close,-EdgeRem);

plot x = if EdgeCount and eCls > eSMA then Double.NaN else SMA;
x.setpaintingStrategy(paintingStrategy.POINTS);

plot y = SMA;
You are the man!!! This is actually exactly what I'm looking for. I'm only using the last 20bars for trading so the 200 is more than enough to give me a clean picture. Thank you again so so so much! This community never ceases to amaze me day in and day out.
 

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.
Top