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 Value

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

    MACD Value

    I have looked all over and I can't seem to figure out how to get the value of ZeroLagMACD fast and slow lines into a strategy.

    I know how to do crossabove/below, but I was wanting the actual values in a strategy.

    Anybody can help?

    Thank you.

    #2
    Hello shawnkm,

    Thank you for writing in.

    I am not familiar with the ZeroLagMACD indicator. Is this an indicator that can be provided so I may investigate further?

    If not, let's use the standard MACD indicator as an example.

    Within your strategy, you can print out the current values of the Avg and Macd lines, and Diff bar, for example, by doing the following:
    Code:
    private MACD macd;
    
    protected override void Initialize()
    {
         macd = MACD(12, 26, 9);
    }
    
    protected override void OnBarUpdate()
    {
         Print("Average: " + macd.Avg[0]);
         Print("Macd: " + macd[0]);
         Print("Diff: " + macd.Diff[0]);
    }
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Multi time frame MACD

      Does anyone have a script or know of one for a multi time frame MACD,along the lines of 1;2;and 4 times present time frame on chart?

      Comment


        #4
        Hello laredo787,

        Thank you for writing in.

        I would suggest taking a look at the NinjaTrader help guide at this link for additional information on how you would be able to utilize multiple DataSeries within one script: http://ninjatrader.com/support/helpG...nstruments.htm

        Using this approach, you would be able to plot multiple lines based off of different time frames and/or instruments.

        I have provided a sample indicator demonstrating this. It will plot both the close price of the instrument you have placed the indicator on and the close price of a 1 minute ES 06-16 instrument.
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          extract

          DO i extract that in order to view it please

          Comment


            #6
            Hello laredo787,

            You will not want to extract the file.

            To import the indicator, please follow the steps below:
            1. From the Control Center window select the menu File> Utilities> Import NinjaScript
            2. Select the downloaded .zip file
            3. NinjaTrader will then confirm if the import has been successful.


            Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Zachary G,
              version: NT8B11
              Could you please explain the discrepancy in the MACD result using the following:
              1. MACD(12,26,9).GetValueAt(ibar) returns the Close price at ibar.
              2. MACD(12,26,9)[Count-2-ibar] returns the correct MACD value at ibar.
              3. MACD(12,26,9).Avg.GetValueAt(ibar) returns same result as MACD(12,26,9).Avg[Count-2-ibar].

              For the NT8B11 version, the index function Indicator[ibarAgo] is only valid during OnBarUpdate(). Is there any other function to obtain MACD, similar to that of the GetValueAt(ibar) function?

              Comment


                #8
                Hello kkc2015,

                Please take a look at the documentation for GetValueAt(), specifically within the Tip section: http://ninjatrader.com/support/helpG...getvalueat.htm

                Additionally, take a look at the documentation for MACD(): https://ninjatrader.com/support/help...gence_macd.htm

                Specifying a barsAgo index will return the MACD value. When using GetValueAt(), you will need to specify the value or plot you wish to pull from or you will just be getting the close value of the bar, per the information about the GetValueAt() method.

                Take a look at the MACD indicator's code and you will see that you'll want to pull from the Default Series.

                Code:
                MACD(12, 26, 9).Default.GetValueAt(ibar);
                You'll want to use the GetValueAt() method if you are trying to obtain the MACD value from outside of data driven events. The Implementation changes section of the current version's release notes touches on this: https://ninjatrader.com/support/help.../?8_0_0_11.htm
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Zachary G,
                  Thank you very much for your quick response, which answered the question. In order to obtain the correct syntax, one would need a NinjaTrader decipher to find the "Default" reference well within the "Properties" section of the MACD indicator source code. The worst part is that MACD(12,26,9).GetValueAt(ibar) actually returns an incorrect value, rather than flagged as "syntax error" by the compiler.

                  Comment


                    #10
                    Hello kkc2015,

                    Note as stated in the help guide, when using GetValueAt(), you will need to specify the value or plot you wish to pull from or you will just be getting the close value of the bar, per the information about the GetValueAt() method.

                    Additionally, please note that when using GetValueAt(), you do not want to pass a barsAgo value. Rather, you will want to pass a barIndex value. With barsAgo, 0 is the current bar, 1 is the previous, so on and so forth. However, with barIndex, CurrentBar is the current bar, CurrentBar - 1 is the previous, so on and so forth.



                    Please, let us know if we may be of further assistance.
                    Zachary G.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Radano, 06-10-2021, 01:40 AM
                    19 responses
                    604 views
                    0 likes
                    Last Post Radano
                    by Radano
                     
                    Started by KenneGaray, Today, 03:48 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post KenneGaray  
                    Started by thanajo, 05-04-2021, 02:11 AM
                    4 responses
                    470 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Started by aa731, Today, 02:54 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post aa731
                    by aa731
                     
                    Started by Christopher_R, Today, 12:29 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post Christopher_R  
                    Working...
                    X