MACD Histogram Label


Category:
0
0

Hello Pete

I wanted to know if it was possible to have a MACD Histogram Label that follows the colors for the MACD Histogram?

Label “MACD”

Green, Light-Green, Red, Light-Red

Thanks for any help with this.

Ellis

Marked as spam
Posted by (Questions: 3, Answers: 5)
Asked on June 8, 2021 1:05 pm
292 views
0
Private answer

The code required to do this has already been published but it was designed for a custom watchlist column, which is far more useful than applying this as a chart label. Here is the post to the solution that works as a custom watchlist column:

https://www.hahn-tech.com/ans/macd-watchlist-background-color/

If you truly want to adapt that for a chart study you only need to change the last two lines of code. Here they are in their original form for the watchlist column:

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);

And here are the changes you make to those two lines in order to get it to work as a label in a chart study:

def diff = Value - avg;
AddLabel(yes, "MACD", 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);

Just to be clear, you copy the entire code from the previous post I linked at the top of this answer, then replace the last to lines just as I have described above.

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 8, 2021 2:40 pm
0
Thank you Pete for your help with this.
( at June 9, 2021 12:17 pm)