Fitzman
New member
Hi,
I am trying to write a watchlist column script. The script should:
a) color-code the cell if the price is below the 20-week SMA.
b) show the difference between the 20W-SMA and price as a percentage integer (rounded).
This is what I have, but it doesn't capture all stocks, and it does not show the percentage difference:
Any help is much appreciated.
Thanks,
Fitz
I am trying to write a watchlist column script. The script should:
a) color-code the cell if the price is below the 20-week SMA.
b) show the difference between the 20W-SMA and price as a percentage integer (rounded).
This is what I have, but it doesn't capture all stocks, and it does not show the percentage difference:
Code:
def weeklySMALength = 20;
def movingAvg = Average(close, weeklySMALength);
def percentageDifference = (close - movingAvg) / movingAvg * 100;
def roundedPercentage = Round(percentageDifference, 0);
plot myPercentageDifference = roundedPercentage;
def priceBelowMA = close < movingAvg;
myPercentageDifference.AssignValueColor(Color.BLACK);
AssignBackgroundColor(if priceBelowMA then Color.GREEN else Color.BLACK);
Any help is much appreciated.
Thanks,
Fitz