MACD Histogram Color

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #172317 quote
    satini
    Participant
    New

    Hi,

    I’m looking for a MACD indicator that changes the Histogram color with reference to the last bar eg. current bar higher than previous bar= green and lower than previous bar= red). I tried downloading the  MACD histogram color indicator but notice that it behaves completely different from  the built-in MACD. I would really appreciate if someone could point me to a solution or alternative indicator if available.

    Thank you

    #172319 quote
    robertogozzi
    Moderator
    Master

    There you go:

    // MACD 12,26,9
    //
    MyMACD       = ExponentialAverage[12](close) - ExponentialAverage[26](close)
    MySignalLine = ExponentialAverage[9](MyMACD)
    MyHisto      = MyMACD - MySignalLine
    r            = 0
    g            = 255    //Green
    b            = 0
    IF high < high[1] THEN
       r = 255            //Red
       g = 0
    ENDIF
    RETURN MyMACD coloured(0,0,238,255) Style(Line,1) AS "Macd",MySignalLine coloured(238,99,99,255) Style(Line,1) AS "Signal",MyHisto coloured(r,g,b,255) Style(Histogram,1) AS "Histogram"
    #172388 quote
    satini
    Participant
    New

    Thank you Sir. I’ve tried the indicator and noticed that it still doesn’t color  all the bars correctly. I’ve attached a sample screen shot with the default MACD on top and the MACD histogram color at the bottom. I’ve marked some of the bars where the color is off. Really appreciate some help to solve this.

    Best Regards

    #172389 quote
    satini
    Participant
    New

    not sure if the attachment went thru earlier

    #172399 quote
    robertogozzi
    Moderator
    Master

    They are ALL correct, as per your request “eg. current bar higher than previous bar= green and lower than previous bar= red“.

    Any bar higher than the previous one is GREEN, otherwise it’s RED.

    #172831 quote
    satini
    Participant
    New

    Hi Sir ,

    My apologies for the confusion. What I meant is that if the macd histogram bar is increasing with respect to the last one, it should color the forming bar green. Conversely, if its is declining with respect to the previous bar, then the bar should paint red.

    Regards

    #172833 quote
    robertogozzi
    Moderator
    Master

    If the higher is higher than before it must be green, if the low is lower than before it’s red, is this correct!

    In all other cases what colour should it have?

    To check for ascending and descending prices shall I use CLOSE or HIGH/LOW?

    #172984 quote
    satini
    Participant
    New

    Hi Sir, please refer to the attached chart from MT4. I’m trying to get the indicator to do the same in PRT.

    When a bar is above  0  line and increasing in  value ie becoming more postive wrt previous bar, it  should paint green and signal a change to red if  it go lower than previous  bar.

    When a bar is below 0 line and  becoming more negative  wrt previous bar , the bar should paint red. If it’s below o line and becoming more positive wrt last bar, it should paint green.

    #172995 quote
    robertogozzi
    Moderator
    Master

    There you go:

    // MACD 12,26,9
    //
    MyMACD       = ExponentialAverage[12](close) - ExponentialAverage[26](close)
    MySignalLine = ExponentialAverage[9](MyMACD)
    MyHisto      = MyMACD - MySignalLine
    ONCE b       = 0
    IF (MyMACD > MyMACD[1]) AND (MyMACD > 0) THEN
       r         = 0
       g         = 255    //Green
    ENDIF
    IF (MyMACD < MyMACD[1]) AND (MyMACD <= 0) THEN
       r         = 255            //Red
       g         = 0
    ENDIF
    RETURN MyMACD coloured(0,0,238,255) Style(Line,1) AS "Macd",MySignalLine coloured(238,99,99,255) Style(Line,1) AS "Signal",MyHisto coloured(r,g,b,255) Style(Histogram,1) AS "Histogram"
    #173057 quote
    satini
    Participant
    New

    Hi, i tried copying the code into the indicator and am getting strange output as attached.

    [attachment file=”173058″]

    #173064 quote
    robertogozzi
    Moderator
    Master

    What is strange?

    #174226 quote
    2point1
    Participant
    New

    Create Variables called ShortTermMA, LongTermMA and SignalNBRPeriods, and set them to your liking, e.g. 14, 32 and 9

    MyMACD = ExponentialAverage[ShortTermMA](close) - ExponentialAverage[LongTermMA](close)
    MySignalLine = ExponentialAverage[SignalNBRPeriods](MyMACD)
    MyHisto = MyMACD - MySignalLine
    
    r = 0
    g = 0
    b = 0
    
    IF MyHisto > 0 THEN
    // Normal Green
    IF MyHisto[1] < MyHisto THEN
    r = 38
    g = 166
    b = 154
    ENDIF
    // Light Green
    IF MyHisto[1] > MyHisto THEN
    r = 178
    g = 223
    b = 202
    ENDIF
    ENDIF
    
    IF MyHisto < 0 THEN
    // Normal Red
    IF MyHisto[1] > MyHisto THEN
    r = 255
    g = 82
    b = 82
    ENDIF
    
    // Light Red
    IF MyHisto[1] < MyHisto THEN
    r = 255
    g = 205
    b = 210
    ENDIF
    ENDIF
    
    RETURN MyHisto coloured(r,g,b,255) Style(Histogram,1) AS "Histogram", MyMACD coloured(0,0,238,255) Style(Line,1) AS "Macd",MySignalLine coloured(238,99,99,255) Style(Line,1) AS "Signal"
    satini thanked this post
    #174241 quote
    satini
    Participant
    New

    Thank you so much. It’s perfect now.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

MACD Histogram Color


ProBuilder support

New Reply
Author
author-avatar
satini @satini Participant
Summary

This topic contains 12 replies,
has 3 voices, and was last updated by satini
4 years, 6 months ago.

Topic Details
Forum: ProBuilder support
Language: English
Started: 06/24/2021
Status: Active
Attachments: 6 files
Logo Logo
Loading...