Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Macd Diff Change Direction

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

    Macd Diff Change Direction

    Can you please tell me how to program a condition to be true when the Macd "diff" has changed direction from up to down or down to up?
    Thanks
    Last edited by kenb2004; 09-20-2010, 02:55 PM.

    #2
    Hello Kenb2004,

    You can use Rising and Falling conditions if you just want to compare the MACD value to its prior value. The following reference sample can help you set this up in the Strategy wizard condition builder:
    Using Rising and Falling conditions in the Strategy Wizard
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I get
      if (Rising(MACD(12, 26, 9).Diff) == true)
      but how do I compare it to the "Diff" Falling AbarAgo?
      Thanks

      Comment


        #4
        Hello Ken,

        These methods only compare the current MACD value to its prior value. If you want to test a longer duration condition, you have to reference specific values to compare.

        if (MACD(12, 26, 9).Diff[0] > MACD(12, 26, 9).Diff[1]) //this is all rising method checks for.

        You work with the index [] values to specify the condition you're looking for.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I tried
          if (Rising(MACD(12, 26, 9).Diff) == true
          && Rising(MACD(12, 26, 9).Diff, 1) == false)
          but I got an error "No overload for method 'Rising' takes '2' arguments

          Comment


            #6
            What you showed only creates a condition that shows Rising. I am trying to create a condition that shows a "Change in Direction". Rising is Rising whether it has changed direction or not. How do I create a condition that shows a "Change in Direction"?

            Comment


              #7
              You can specify that there was a falling condition just prior to that, by specifying the bars ago setting for the index.

              if (MACD(12, 26, 9).Diff[1] < MACD(12, 26, 9).Diff[2]) //Checks if one bar back was less than 2.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                I tried the following:
                //Condition set 7
                if (Macd(Fast, Slow, Smooth).Diff[1] > Macd(Fast, Slow, Smooth).Diff[2]
                && Falling(Macd(Fast, Slow, Smooth).Diff) ==
                true)
                {
                DrawTriangleDown(
                "My triangle down" + CurrentBar, false, 0, (Macd(Fast, Slow, Smooth).Diff[0]) * (1 + 2), Color.Red);
                }
                It compiled but did not display. When I added condition 7 only an empty panel displayed.
                Last edited by kenb2004; 09-21-2010, 09:08 AM.

                Comment


                  #9
                  Ken, please try with a different offset for the drawing object or include in the autoScale to see where it gets placed so you can adjust it's Y axis value as needed.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I tried the following and only got a blank panel. I'm trying to get a conditon that watches for a Diff Direction Change, from up to down Or down to up. I'm thinking that the Rising Method isn't the best way to ackomplish this. What do you think?
                    //Condition set 7
                    if (Macd(Fast, Slow, Smooth).Diff[1] > Macd(Fast, Slow, Smooth).Diff[2]
                    && Falling(Macd(Fast, Slow, Smooth).Diff) ==
                    true)
                    {
                    DrawArrowDown(
                    "My down arrow" + CurrentBar, false, 0, (Macd(Fast, Slow, Smooth)[0]) * (1 + -6), Color.Red);
                    //DrawTriangleDown("My triangle down" + CurrentBar, false, 0, Diff[0] + .4 * TickSize, Color.Red);
                    //DrawTriangleDown("My triangle down" + CurrentBar, false, 0, (Macd(Fast, Slow, Smooth).Diff[0]) + .4 * TickSize, Color.Red);
                    }
                    Last edited by kenb2004; 09-21-2010, 11:06 AM.

                    Comment


                      #11
                      Ken, then it means that your conditon does not evaluate to 'true' to trigger the drawings - please try something like this below -

                      if (MACD(12, 26, 9).Diff[0] > MACD(12, 26, 9).Diff[1]
                      && MACD(
                      12, 26, 9).Diff[1] < MACD(12, 26, 9).Diff[2])
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        That sure looks like it would work but all I get is a blank panel. I've replaced it with other conditons and it works fine, but it doesn't seem to like diff greater than diff???

                        Comment


                          #13
                          Ken, do you see any log errors being reporting in the Control Center log tab as you try the Diff conditions?
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Yes. _KenMac2 is the name of the script. It works fine until the I put in the code you suggested.
                            I also put in the following and it works fine:
                            if (CrossAbove(_KenMac(Fast, Slow, Smooth).Diff, 0.001, 1))

                            Error on calling the 'OnBarUpdate' method for indicator '_KenMac2' on bar 0: Index was out of range. Must be non-negative and less than the
                            Parameter name: index
                            9/21/2010 12:23:34 PM Strategy Starting NinjaScript strategy

                            Comment


                              #15
                              Hi Ken,

                              You will need to follow this article about accessing invalid objects:
                              Make sure you have enough bars in the data series you are accessing

                              To resolve, you can add a CurrentBar check for the highest index [ ] value in your script.

                              if (CurrentBar < 2)
                              return;
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X