Since you logged into the forum using your Twitter account we don't have a valid email address for you. This means you are not getting email notifications when you post new content on our website. Don't post your email address here or you will get spammed. Contact me directly and we can get that updated.
Here is the solution you requested:
input minimumValue = 0.0;
input maximumValue = 0.35;
input maLengthOne = 21;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot percentFrom = 10 * (close / maOne – 1);
percentFrom.AssignValueColor(if percentFrom > minimumValue and percentFrom < maximumValue then Color.BLACK else Color.CURRENT);
AssignBackgroundColor(if percentFrom > minimumValue and percentFrom < maximumValue then Color.GREEN else Color.CURRENT);
I included user inputs for min/max values so the rest of our viewers can use this for their own preferences.
And while I was working this I realized the percentFrom variable is not computed correctly. That line of code should be as follows:
plot percentFrom = 100 * (close / maOne – 1);
But changing this would also require you to update the min/max value inputs to account for the adjusted value. I am providing this correction for the benefit of those who come across this post at a later date. And I will updated the solution in the original post as well.
Edit: Someone requested this to be converted to a chart label. Since the solution to create a chart label will also work as a watchlist column I will provide that solution here instead of requiring that request be posted as a new question. When we use the AddLabel() statement to display values in a watchlist column, those values get converted to text. Which means we loose the ability to sort by the values of that column. But we can do neat things with this, such as add the "%" sign to the displayed value:
input minimumValue = 0.0;
input maximumValue = 0.35;
input maLengthOne = 21;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def percentFrom = 100 * (close / maOne – 1);
AddLabel(yes, Concat(percentFrom, "%"), if percentFrom > minimumValue and percentFrom < maximumValue then Color.GREEN else Color.GRAY);