Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Color MACD Bar Reversals

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to Color MACD Bar Reversals

    I wish for the MACD indicator bars to change color when the next bar is higher/lower than the previous as in the image below. Can you kindly inform me as to how I go about making this happen.

    Regards,

    Martin
    Montreal, Canada
    Attached Files

    #2
    Hello,

    You can easily compare the bar conditions by using the following:

    Code:
    // if the current close is greater than the close one bar ago
    if(Close[0] > Close[0])
    You can also compare different price points:

    Code:
    //if the current price is greater than the high of one bar ago
    if(Close[0] > High[1]
    From there, you can tell your indicator to change the bar color of the indicator

    Code:
    BarColor = Color.Bue;


    Please let me know if you have any questions.
    MatthewNinjaTrader Product Management

    Comment


      #3
      I wish this to happen directly on the chart with the default MACD indicator. Can that be done?

      Comment


        #4
        Yes, but you'd need to make a copy of the existing MACD indicator.

        To do this, please go to Tools--> Edit NinjaScript--> Indicator and open the MACD.

        Once opened, please right click on the indicator code and select "Save as" and give it a new name.

        From the new window that appears, you can make the changes you wish. I would recommend putting this below the rest of the logic in OnBarUpdate, starting around line 75

        Code:
        			if(CurrentBar < 1)
        				return; 
        			
        			if(Close[0] > Close[1])
        				PlotColors[2][0] = Color.Blue;
        			
        			else if(Close[0] < Close[1])
        				PlotColors[2][0] = Color.Yellow;
        MatthewNinjaTrader Product Management

        Comment


          #5
          I have followed your instructions but the new MACD indicator I saved does not appear in my list of indicators to add to a chart. I have even exited NT and restarted. What am I missing?

          Thanks

          Comment


            #6
            I apologize: you must right click on the new indicator and select "Compile" before it will show up.
            MatthewNinjaTrader Product Management

            Comment


              #7
              I think MV007 meant the MACD histgram bar, not the candlestick bar
              How to code that?

              Comment


                #8
                Hello Allen.

                Thanks for the post.

                You will first have to make your own copy of the MACD by right-clicking the locked MACD code in your NinjaScript editor> Save As> Give it a different name.

                Once you have your own copy of the MACD, follow this post where Jessica shows how to color the histogram bars based on price falling or rising.



                Please let us know if we may be of any further assistance.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by gemify, 11-11-2022, 11:52 AM
                6 responses
                803 views
                2 likes
                Last Post ultls
                by ultls
                 
                Started by ScottWalsh, Today, 04:52 PM
                0 responses
                3 views
                0 likes
                Last Post ScottWalsh  
                Started by ScottWalsh, Today, 04:29 PM
                0 responses
                7 views
                0 likes
                Last Post ScottWalsh  
                Started by rtwave, 04-12-2024, 09:30 AM
                2 responses
                22 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Started by tsantospinto, 04-12-2024, 07:04 PM
                5 responses
                70 views
                0 likes
                Last Post tsantospinto  
                Working...
                X