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

How to access MACD variables in the Wizard

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

    How to access MACD variables in the Wizard

    Hello

    I'm currently developing an MACD-based strategy with the Wizard and I'd like to know how to access all 4 basic components of the MACD indicator (the "Avg Line", the "MACD Line", the "Diff" and the "Zero Line") as variables in the code.

    Basically, I'd like to be able to code the following: If the MACD Line crosses the Avg Line, then buy etc. In the MACD dropdown menu of the wizard I currently can only choose between the Fast, Slow and Smooth variables, but not the 4 MACD components.

    Thanks a lot for pointing me in the right direction.

    #2
    Hello,

    Press Add to add a condition, then when you use MACD, click next to the Plot feild where it says Avg and a drop down will allow you to select the MACD plot that you want to reference.
    DenNinjaTrader Customer Service

    Comment


      #3
      Hello Ben

      Thanks for your reply. I started to create the strategy I have in mind, but for some reason the diamonds I wanted to plot when the MACD Line crosses above the Avg Line don't appear.
      Could you tell me where I made a mistake? Thank a lot.

      This is the code snippet:

      // Condition set 1
      if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
      {
      DrawDiamond("" + CurrentBar, false, 0, 0, Color.Yellow);
      }

      Thanks & Regards

      Comment


        #4
        Hello,

        Since you are attempting to draw on value "0", I assumed that you wanted this to draw on the MACD panel. Attach the MACD on a panel greater than 1, and attach the indicator on the same panel and use this code:

        Put the first line in the Initialize() block and the rest in the OnBarUpdate() block:
        DrawOnPricePanel = false;

        if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
        {
        DrawDiamond(
        "macdtag" + CurrentBar, false, 0, 0, Color.Blue);

        }
        DenNinjaTrader Customer Service

        Comment


          #5
          Hello Ben

          It works perfectly, thanks a lot.
          If I may, I'd like to ask you one last thing: what can I do to avoid that a diamond is plotted on every bar that matches the criteria and instead plot it only on the first bar of every sequence where all criteria are met.

          Thanks again.

          Comment


            #6
            Hello,

            What do you mean by sequence?

            Taking a guess here: try adding more conditions in your if statement and don't rename your draw tag for each draw. Like this (no CurrentBar in the tag):
            DrawDiamond("macdtag", false, 0, 0, Color.Blue);
            DenNinjaTrader Customer Service

            Comment


              #7
              Hello Ben

              By "sequence" I meant that once the MACD Line has crossed above/below the Avg Line and the other conditions are met (I added quite a few), it plots a diamond only ONCE (on the first bar that meets all criteria and only on the first bar) until the MACD Line has crossed above/below the Avg Line again.

              Thanks

              Comment


                #8
                Hello,

                Sorry, what do you mean by first bar? Do you mean the first occurance left to right? If so, just add a bool flag that blocks another one from plotting:

                if(...conidtions here... && drew == false)
                {

                //draw here

                drew = true; //stops from drawing again
                }

                Of course you will need to add a criteria to reset the bool flag back to false at some point.
                DenNinjaTrader Customer Service

                Comment


                  #9
                  Access Plot value in Strategy wizard

                  I am using a volume indicator that plots the volume bars different colors if it meets some conditions. I want to be able to develop a strategy that for example would enter a buy order when a specific plot is displayed on the chart. I have selected the desired plot (climaxchurnbar) and set the value to 1. I will like to enter a buy order if this condition is true. Please see the attachment. Is this the proper way to access this plot condition because I am unable to get the strategy to buy when there is a climaxchurnbar.
                  Attached Files

                  Comment


                    #10
                    GeorgeO, this will likely not work as the direct value of the Volume churn on the chart would not display as literally 1 right if the signal is there?
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ScottWalsh, Today, 04:29 PM
                    0 responses
                    0 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by rtwave, 04-12-2024, 09:30 AM
                    2 responses
                    20 views
                    0 likes
                    Last Post rtwave
                    by rtwave
                     
                    Started by tsantospinto, 04-12-2024, 07:04 PM
                    5 responses
                    68 views
                    0 likes
                    Last Post tsantospinto  
                    Started by cre8able, Today, 03:20 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post cre8able  
                    Started by Fran888, 02-16-2024, 10:48 AM
                    3 responses
                    49 views
                    0 likes
                    Last Post Sam2515
                    by Sam2515
                     
                    Working...
                    X