Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem adding Plot to Strategy

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

    Problem adding Plot to Strategy

    I want to add plots to strategies so that after a backtest, if I click the "Charts" tab, I can see the indicator plotted.

    The first line of line works fine. It is the MACD line, 1 of 3 parts of the MACD indicator.

    The second line of code is the MACD average, also a line and part 2 of 3 of the MACD indicator.

    NT7 doesn't like the syntax on this line. How do I fix it?

    Thx.

    MACD(12, 26, 9).Plots[0].Pen.Color = Color.Blue;
    MACD(12, 26, 9).Avg.Plots[0].Pen.Color = Color.Orange; // gives error CS1061

    #2
    Hello Brooksrimes,

    What you have to do is add the indicator, and then all plots of the indicator will be included.

    Add(MACD(12, 26, 9));

    You can set a specific color by referencing the plot index for that indicator. You would have to open up the MACD indicator to see that AVG is the second plot, or 1 index. Statement below sets this line to orange.

    MACD(12, 26, 9).Plots[1].Pen.Color = Color.Orange;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan, that's helpful.

      I was reading the docs on the Add statement and it sounded like it was more like it was needed if you were going to refer to that indicator in code. So the Add causes the MACD to plot just by itself? And the Plots is only needed if you want to change one of the attributes/properties?

      How would I code it to omit the histogram part of MACD and plot just the MACD and its Average line?

      Comment


        #4
        The add statement is only used for strategy plots. You can access indicator values in the strategies OnBarUpdate() without having to add the indicator.

        Correct. Add() will add the indicator including all associated plots. The Plots statements are then used to define specific attributes.

        If you didn't want to plot the histogram, you could set the color attribute for histogram plot as transparent.

        Add(MACD(12, 26, 9));
        MACD(
        12, 26, 9).Plots[2].Pen.Color = Color.Transparent;
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X