# Combine PLOT and ROUND?

#### Fitzman

##### New member
Disclaimer 1: I searched but couldn't find an answer.
Disclaimer 2: might be a stupid question, but I just started learning to think script.

I have been working on a watchlist column code to display 30 week moving averages 12 days ago (might not be working correctly yet..., but this post is about the displayed format).

Code:
``````# Calculate the percentage difference between the close price from 12 days ago and the 30-period SMA from 12 days ago

def weeklySMALength = 30;
def movingAvg = Average(close, weeklySMALength);

def closeFiveDaysAgo = close[12];
def movingAvgFiveDaysAgo = movingAvg[12];

def percentageDifference = (closeFiveDaysAgo - movingAvgFiveDaysAgo) / movingAvgFiveDaysAgo * 120;
def roundedPercentage = Round(percentageDifference, 0);

plot myPercentageDifference = roundedPercentage;

def priceBelowMA = closeFiveDaysAgo < movingAvgFiveDaysAgo;

myPercentageDifference.AssignValueColor(Color.BLACK);
AssignBackgroundColor(if priceBelowMA then Color.BLUE else Color.BLACK);``````

My desired plot in the cell is the whole numbers/integer/number without any decimals only, e.g., -1, -13, -34, etc... . Here is my dilemma:

A) If I use the plot function, it will always plot with one decimal, but the column will sort correctly
B) If I use the AddLabel function to print the value, it will omit the decimal, but the column no longer sorts correctly because it's now as string (it will sort 1, 2, 21, 3, 33, 4, 41, etc...)

I tried to combine PLOT and ROUND to zero decimals, but it does not seem to work. The plotted number is always still with one decimal... Could anyone advise on how to use PLOT and return an integer/whole number without a decimal? Or anther way to return an integer that sorts correctly in the column.

Thanks,
Fitz.

Thanks,
Jan.

Disclaimer 1: I searched but couldn't find an answer.
Disclaimer 2: might be a stupid question, but I just started learning to think script.

I have been working on a watchlist column code to display 30 week moving averages 12 days ago (might not be working correctly yet..., but this post is about the displayed format).

Code:
``````# Calculate the percentage difference between the close price from 12 days ago and the 30-period SMA from 12 days ago

def weeklySMALength = 30;
def movingAvg = Average(close, weeklySMALength);

def closeFiveDaysAgo = close[12];
def movingAvgFiveDaysAgo = movingAvg[12];

def percentageDifference = (closeFiveDaysAgo - movingAvgFiveDaysAgo) / movingAvgFiveDaysAgo * 120;
def roundedPercentage = Round(percentageDifference, 0);

plot myPercentageDifference = roundedPercentage;

def priceBelowMA = closeFiveDaysAgo < movingAvgFiveDaysAgo;

myPercentageDifference.AssignValueColor(Color.BLACK);
AssignBackgroundColor(if priceBelowMA then Color.BLUE else Color.BLACK);``````

My desired plot in the cell is the whole numbers/integer/number without any decimals only, e.g., -1, -13, -34, etc... . Here is my dilemma:

A) If I use the plot function, it will always plot with one decimal, but the column will sort correctly
B) If I use the AddLabel function to print the value, it will omit the decimal, but the column no longer sorts correctly because it's now as string (it will sort 1, 2, 21, 3, 33, 4, 41, etc...)

I tried to combine PLOT and ROUND to zero decimals, but it does not seem to work. The plotted number is always still with one decimal... Could anyone advise on how to use PLOT and return an integer/whole number without a decimal? Or anther way to return an integer that sorts correctly in the column.

Thanks,
Fitz.

Thanks,
Jan.

numbers sort right to left
test sorts left to right
if you want to sort text, from a addlabel(), then all data needs to have the same quantity of characters.

look at the addlabel code lines in these studies

Last edited:

87k+ Posts
193 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
• 1 full year of unlimited support

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?