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).
Watchlist column link
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 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);
Watchlist column link
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.