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

Inaccessible due to protection level

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

    Inaccessible due to protection level

    Hi. I am building an indicator that plots the slow and fast EMA's, as well as a calculated line based on the average of these EMA's The data for these values, comes from the built-in MACD indicator. I want to plot this on the price chart and not in a separate window. I first used the wizard to build the base of the indicator and set it up to shows 3 plots called: Plot1, Plot2 & Plot3. In the OnBarUpdate section, I placed this code and it works:

    Plot1.Set(MACD(fast,slow,smooth).Avg[0]);

    I then tried to build the second plot with this:

    Plot2.Set(MACD(fast,slow,smooth).slowEma[0]);

    Now I get this error: 'NinjaTrader.Indicator.MACD.slowEma' is inaccessible due to its protection level.
    Can someone tell me what I need to do to be able to access the slowEma and the fastEma from the original MACD indicator?

    #2
    You cannot directly do that.

    Your choices are:

    1. Copy @MACD.cs to MyMACD.cs and expose those Series yourself.

    2. Just use EMA(fast) and EMA(slow) -- the values for 'fast' and 'slow'
    plugged into the regular 'EMA' indicator should give you the same value.

    That is, you would use

    Plot2.Set(EMA(slow)[0]);

    instead.

    Comment


      #3
      Thanks, I will give that a go.

      Comment


        #4
        Hello Kaiviti57,

        Thanks for your post.

        The MACD indicator makes available 3 plots, the MACD plot, the Average plot and the Difference plot. These you can access without issue.

        Member bltdavid has provided advice for accessing the indicators that the MACD uses.



        Paul H.NinjaTrader Customer Service

        Comment


          #5
          For a bit more clarity, the three lines I want to plot on the price chart are the result of the MACD indicator. These are: Avg, slowEMA and fastEma. I have no issue in plotting the "Avg" line. When I try and use the slowEma or the fastEma I get the errors. I also tried copying the whole of the OnBarUpdate section and when I compile I get errors. I have copied the @MACD indicator, renamed it to MyMacd, and then tried to compile it. I get heaps of errors. I have attached the MyMACD indicator to show you these errors. Once I get the slowEma and thefastEma I should be good to go.
          Attached Files

          Comment


            #6
            You may be greatly confused by what you're trying to do.

            It makes no sense to plot 'Avg' in the price panel, since it is not really
            a price value anymore.

            Do you understand the MACD calculations?
            Have you looked at them?

            Open @MACD.cs and study the code.
            Look at how macd is calculated -- it is 'FastEma - SlowEma' -- right?
            Then look at macdAvg -- that gibberish looking code results in the EMA average
            of the last 'n' values of the previously calculated 'macd' values, where 'n' is the
            Smooth parameter.

            Both 'macd' and 'macdAvg' are always fairly small numbers.
            And yet, you want 'macdAvg' values plotted on the price panel?

            Are you sure you want to do that?

            You can plot EMA(Fast) and EMA(Slow) on the price panel -- no problem.
            That is simple and easy -- since these are price values.

            But, think about it --
            When you subtract those two values, you get a fairly small number, sometimes
            you even get zero (which can happen when they cross each other) -- so if you
            plot the average of that fairly small number (which is also going to be a fairly
            small number) in the price panel, I'm pretty certain you're going to be greatly
            disappointed in how it looks on the price chart, esp if AutoScale is True.

            What's wrong with plotting that number in a separate panel, like what MACD
            currently does?

            What are you really trying to achieve?

            Comment


              #7
              Let's go back to your original question.

              Why doesn't this code,

              Plot2.Set(EMA(slow)[0]);

              work for you?

              Comment


                #8
                Hi David. You guys must get very frustrated with blokes like me that don't explain things correctly. I said I wanted to plot the Avg line and this was wrong. It is not used on its own. It is actually added to the EMA(slow) line and the result is then plotted.

                Basically, I am trying to copy another indicator that I use (no code available). I have found that one of the lines from that indicator matches an EMA(23) exactly (as shown in the below code for Values[0].set). The other line approximates the MACD Avg line added to the EMA(23) (as shown in the below code for Values[1].set). It is not exact but is close enough for me.

                This is the code I am using at present in my custom indicator to plot the two lines:

                Values[0].Set(EMA(slow).Value[0]);
                Values[1].Set(MACD(fast,slow,smooth).Avg[0] + (EMA(slow).Value[0]));
                Values[2].Set(((EMA(fast).Value[0]+EMA(slow).Value[0])/2)+EMA(slow).Value[0]);

                I have looked at the code from the MACD indicator and your description of "gibberish looking code" is true. I can't decipher it. I understand how the MACD is calculated but the gibberish in the indicator has got me baffled. This is what is causing some of my problems.

                Aside from this gibberish, I have managed to plot 2 of the 3 lines. The plot for Valus[0] is simple and it plots OK. If you have a look at the code I am using for Valus[2], you will see that it isthe MACD(Avg) and this is added to the slow EMA(23) and this also plots OK. As far as I can see, Values[1] and Values[2] should plot the exact same line. Am I right so far? The code I am using for Values[2] compiles but it will not plot. What am I doing wrong here? If I can get Values[2] to plot, it will prove to me that the average of the EMA's is the same as MACD(Avg) and I will then be happy.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                4 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                40 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Kaledus, Today, 01:29 PM
                5 responses
                15 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X