Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot a line connecting the MACD Histogram

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

    Plot a line connecting the MACD Histogram

    Hi,

    I thought I understand how Add(0, DataSeries, etc. work in NinjaTrader but apparently I don't.

    I'm trying plot a line by connecting the MACD Histogram.

    Attached is the changes I made thorugh comments // ... new code. Please let me know what I did wrong.

    Thanks,

    Richard
    Attached Files
    Last edited by Richard168; 02-08-2012, 04:49 PM.

    #2
    Hello,

    Thanks for the note.

    What specifically is wrong or giving error?

    -Brett
    BrettNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Brett View Post
      Hello,

      Thanks for the note.

      What specifically is wrong or giving error?

      -Brett
      Brett,

      The MACD Histogram line does not print but the Histogram prints. i.e. I can't see the line which should be colored black.

      The following is the code I added:

      private DataSeries diff;
      ...
      Add(new Plot(Color.Black, "Diff")); // should be postion [4]
      ...
      diff = new DataSeries(this);
      ...
      diff.Set(macd - macdAvg); // new code
      ...
      /// <summary>
      /// </summary>
      [Browsable(false)]
      [XmlIgnore()]
      public DataSeries Diff
      {
      get { return Values[4]; }
      }


      /// <summary>
      /// </summary>

      Thanks in advance for your help.

      Richard

      Comment


        #4
        Richard,

        Could you possibly post more of your code so we can test on our end as well as see more of it?

        Also please note that the "new dataseries(this)" initialization isn't necessary for plots.

        We look forward to helping you resolve your issue.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AdamP View Post
          Richard,

          Could you possibly post more of your code so we can test on our end as well as see more of it?

          Also please note that the "new dataseries(this)" initialization isn't necessary for plots.

          We look forward to helping you resolve your issue.
          Hi Adam,

          Please see attached file: RichardMACDHistogram.txt for the entire source code.

          Hope this will help you test the code.

          Thanks,

          Richard
          Attached Files

          Comment


            #6
            Hi Richard,

            Thanks for the code snippet. You've added a couple Transparent plots for these. Does it correct the issue if you change these to plot a color?
            Instead of Transparent, make it something like:
            Code:
            Add(new Plot(Color.Black, "Macd"));	// [0]
            Add(new Plot(Color.Blue, "Avg"));	// [1]
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Hi Ryan,

              By making the MACD and Avg line plot transparent, I don't want to show them as I just want to show the Histogram. However, I also want to show the Histogram as a line, i.e.
              Add(new Plot(Color.Black, "Diff")); // should be postion [4]

              The problem is that Diff (which is difference between MACD and Avg) does not show.

              Thanks,

              Richard

              Comment


                #8
                I see -- Thanks for the reply. In your code you never set the plot for Diff, only the DataSeries diff.

                DataSeries and Plots are identical data structure. Plots are a special kind of DataSeries that allows the visuals on charts. So for items that you want to use as calculations only, like MACD and Avg, these are best as a DataSeries only. Your Transparent work around is fine as well if you don't want to change this yet.

                It doesn't seem like your indicator will require a separate diff (lowercase) data series, so you could remove that, and then make sure to use Diff (uppercase), which is the plot you defined for this.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Ryan,

                  I see what you are saying but I like to better understand Plot and DataSeries because I belive that this is a very important concept in NinjaScript coding.

                  I added a new plot (which will be stored in postion [4]):

                  Add(new Plot(Color.Black, "Diff")); // [4]

                  Where will Diff get the value of (macd - macdavg)?

                  That's why I added:

                  Private DataDeries diff;
                  diff = new DataSeries(this);
                  diff.Set(macd - macdavg).

                  It works after I made the following changes:
                  Diff.Set(0);
                  Diff.Set(macd - macdavg)

                  and deleted:
                  Private DataDeries diff;
                  diff = new DataSeries(this);

                  Thanks very much for your help,

                  Richard
                  Last edited by Richard168; 02-09-2012, 09:59 AM.

                  Comment


                    #10
                    Sure, I'm happy to clarify. Basically your diff data series is redundant to the Diff plot, so you could remove that completely. Then, within your OnBarUpdate code, change from diff to Diff.

                    Looks like you got that working. Thanks for following up here!
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by blar58, Today, 03:16 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Melissa  
                    Started by alcorr247, Today, 02:52 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_ChrisL  
                    Started by Radano, Today, 02:30 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_ChrisL  
                    Started by DrummerBoy, Today, 01:34 PM
                    3 responses
                    29 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by kangethe, Today, 02:11 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X