Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple MACD signal crossover question

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

    Simple MACD signal crossover question

    Hi Guys,

    I know this is a simple question, and I've looked in the forum but it's still not 100% clear to me.

    How do I code an MACD and signal line crossover?

    i.e. if MACD crosses Signal Line
    EXIT!!

    I guess it it will just use CrossBelow but I'm unsure what the values should be.

    Sorry for the stupid question - still learning.

    #2
    Something like this -

    Code:
    if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
        ExitLong();
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks Ray.

      I might be following up with another stupid question here but ...

      is your example below saying
      if MACD value crosses below the average of the MACD for previous bar
      do something?

      Is that going to give me a realtime actual crossover?

      I assume it's not specifically a crossover of MACD and signal? Sorry, I'm just trying to understand exactly what I'm doing. I've tried printing out the values to the output window as per below, but I'm not sure it's helped me get it.

      if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
      ExitLong();

      The current MACD value [0] is 0.0849033617174939
      The current MACD value avg [1] is is 0.110320765678418
      The current MACD value [0] is 0.705493932279808
      The current MACD value avg [1] is is 0.51412018703849
      The current MACD value [0] is 0.0924098265641931
      The current MACD value avg [1] is is 0.105237284886233

      Comment


        #4
        Just tried a quick test and it looks to me like that code is exiting me at the lower larger circle in attached image, rather than the cross of MACD and signal.

        Is that what you would expect to happen?

        Thanks
        Attached Files

        Comment


          #5
          Yes, that is what I coded as an example.

          Your options are -

          MACD(12, 26, 9) - MACD value
          MACD(12, 26, 9).Avg - Average line
          MACD(12, 26, 9).Diff - Diff line

          You can use any of these value in the CrossBelow() method to achieve what you wish.
          RayNinjaTrader Customer Service

          Comment


            #6
            Sorry, I think I'm probably suffering from too long staring at some code but I can't make sense of the values I'm printing out.

            MACD = 12 period EMA - 26 period EMA
            Signal = 9 period EMA of MACD

            So I want to do something when MACD crosses Signal, but when I print out timestamps and MACD, AVG, and Diff values to the output window they don't seem to compare to the crosses and timeframes I'm seeing visually on the chart so I'm still not clear on what I need to do.

            Am I being an idiot here?

            Comment


              #7
              It would seem I'm an idiot

              The penny dropped eventually though.

              Many thanks for the help.
              Last edited by altrader; 03-11-2008, 05:54 PM. Reason: Deleted image

              Comment


                #8
                Glad you got it worked out.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Help

                  I am just starting working with Strategy Wizard and thought this would be a great place to start.. I created what I thought was a cross up Go Long and then cross down Go Short.. But when I backtest it takes NO orders at all..

                  Here is the code generated... can someone help me debug..)

                  thanks in advance


                  protected override void OnBarUpdate()
                  {
                  // Condition set 1
                  if (CrossAbove(MACD(Fast, Slow, Smooth), MACD(Fast, Slow, Smooth), 1))
                  {
                  EnterLong(DefaultQuantity, "");
                  }

                  // Condition set 2
                  if (CrossBelow(MACD(Fast, Slow, Smooth), MACD(Fast, Slow, Smooth), 1))
                  {
                  EnterShort(DefaultQuantity, "");
                  }
                  }

                  Comment


                    #10
                    How would you incorporate a cross above/below the zero line as the trigger instead of a crossing of the fast and slow?

                    Regards

                    Originally posted by dwt1020 View Post
                    I am just starting working with Strategy Wizard and thought this would be a great place to start.. I created what I thought was a cross up Go Long and then cross down Go Short.. But when I backtest it takes NO orders at all..

                    Here is the code generated... can someone help me debug..)

                    thanks in advance


                    protected override void OnBarUpdate()
                    {
                    // Condition set 1
                    if (CrossAbove(MACD(Fast, Slow, Smooth), MACD(Fast, Slow, Smooth), 1))
                    {
                    EnterLong(DefaultQuantity, "");
                    }

                    // Condition set 2
                    if (CrossBelow(MACD(Fast, Slow, Smooth), MACD(Fast, Slow, Smooth), 1))
                    {
                    EnterShort(DefaultQuantity, "");
                    }
                    }

                    Comment


                      #11
                      Use CrossAbove/CrossBelow in the Condition Builder, choose the MACD plot you want to use and on the right side, choose "Numeric Value" from the Misc section then select 0.

                      Comment


                        #12
                        It looks to me that no plots have been selected. In the condition builder you'll want the plot parameter on one side to be .MACD and the other to be .Avg. By the looks of your code you are waiting for the MACD line to cross the MACD line, which it never will as they have the same value.

                        Hope that helps.

                        Originally posted by dwt1020 View Post
                        I am just starting working with Strategy Wizard and thought this would be a great place to start.. I created what I thought was a cross up Go Long and then cross down Go Short.. But when I backtest it takes NO orders at all..

                        Here is the code generated... can someone help me debug..)

                        thanks in advance


                        protected override void OnBarUpdate()
                        {
                        // Condition set 1
                        if (CrossAbove(MACD(Fast, Slow, Smooth), MACD(Fast, Slow, Smooth), 1))
                        {
                        EnterLong(DefaultQuantity, "");
                        }

                        // Condition set 2
                        if (CrossBelow(MACD(Fast, Slow, Smooth), MACD(Fast, Slow, Smooth), 1))
                        {
                        EnterShort(DefaultQuantity, "");
                        }
                        }

                        Comment


                          #13
                          ??

                          I know this is a stupid question but which line which regarding AVG & MACD and what is Diff.

                          thanks in advance

                          david

                          Comment


                            #14
                            LOL.. thank you very much.. TOTALLY over looked that..)

                            David


                            Originally posted by Elliott Wave View Post
                            It looks to me that no plots have been selected. In the condition builder you'll want the plot parameter on one side to be .MACD and the other to be .Avg. By the looks of your code you are waiting for the MACD line to cross the MACD line, which it never will as they have the same value.

                            Hope that helps.

                            Comment


                              #15
                              The Diff is the histogram (bars). Instead of doing MACD CrossAbove Avg etc, you could use:

                              If .Diff CrossAbove 0
                              Go Long
                              If .Diff CrossBelow 0
                              Go Short

                              Its exactly the same as the diff is merely the difference between the two lines.

                              You might want to give the PPO indicator a try. Its almost the same as MACD but uses %, I personally find it better. The QQE is also very good, but its not included by default so you'd need to grab it from the file sharing section.
                              Last edited by Elliott Wave; 11-12-2008, 07:06 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              673 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              577 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X