MACD watchlist background color


Category:
0
0

Hi Pete.  I’ve searched the forum and was not able to locate a post regarding a code to mimic the MACD color in the watchlist background.  If the MACD is above 0 and increasing the color would be green, if above 0 and declining it would be dark green, if below 0 and decreasing the color would be red, if below 0 and increasing the color would be dark green.  Thank you so much for your help!

Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on July 22, 2019 11:14 am
522 views
0
Private answer

Here is the code for that. Pretty much just copied the code straight from the MACD that comes with Thinkorswim. All I did was tweak the color assignment. Screenshot below shows the result.

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def avg = MovingAverage(averageType, value, MACDLength);
plot diff = Value - avg;
AssignBackgroundColor(if diff >= 0 then if diff > diff[1] then Color.GREEN else Color.DARK_GREEN else if diff < diff[1] then Color.RED else Color.DARK_RED);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 22, 2019 2:08 pm