# plot a variable only if the variable is getting greater than the previous high

#### Mart

##### New member
VIP
I am new to TOS and would appreciate some help.

Basically I would like to plot a variable only if the variable is getting greater than the previous high, If it is less than the previous high then do not print it. Let’s use sma simple moving average for the variable. Thanks for your help.

if "sma" > "sma[-1]" then plot sma else 0;

or

plot sma if “sma” > “sma[-1]” else 0;

Last edited:
Solution
I am new to TOS and would appreciate some help.

Basically I would like to plot a variable only if the variable is getting greater than the previous high, If it is less than the previous high then do not print it. Let’s use sma simple moving average for the variable. Thanks for your help.

if "sma" > "sma[-1]" then plot sma else 0;

or

plot sma if “sma” > “sma[-1]” else 0;

Try this

Ruby:
``````#if "sma" > "sma[-1]" then plot sma else 0;
def sma        = SimpleMovingAvg(close, 21);
plot smahigher = if sma > sma[1] then sma else Double.NaN;
smahigher.SetLineWeight(5);``````
I am new to TOS and would appreciate some help.

Basically I would like to plot a variable only if the variable is getting greater than the previous high, If it is less than the previous high then do not print it. Let’s use sma simple moving average for the variable. Thanks for your help.

if "sma" > "sma[-1]" then plot sma else 0;

or

plot sma if “sma” > “sma[-1]” else 0;

Try this

Ruby:
``````#if "sma" > "sma[-1]" then plot sma else 0;
def sma        = SimpleMovingAvg(close, 21);
plot smahigher = if sma > sma[1] then sma else Double.NaN;
smahigher.SetLineWeight(5);``````

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
190 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?