Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to create a separate window (like macd)?

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

    how to create a separate window (like macd)?

    Is there an explanation for how an indicator can create it's own window, like the MACD does? I have been looking at the code for the MACD and I can't see any code that obviously creates a second window.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        /// <summary>
        /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator 
        /// that shows the relationship between two moving averages of prices.
        /// </summary>
        public class MACD : Indicator
        {
            private    Series<double>        fastEma;
            private    Series<double>        slowEma;
            private double                constant1;
            private double                constant2;
            private double                constant3;
            private double                constant4;
            private double                constant5;
            private double                constant6;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionMACD;
                    Name                        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameMACD;
                    Fast                        = 12;
                    IsSuspendedWhileInactive    = true;
                    Slow                        = 26;
                    Smooth                        = 9;
    
                    AddPlot(Brushes.DarkCyan,                                    NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameMACD);
                    AddPlot(Brushes.Crimson,                                NinjaTrader.Custom.Resource.NinjaScriptIndicatorAvg);
                    AddPlot(new Stroke(Brushes.DodgerBlue, 2),    PlotStyle.Bar,    NinjaTrader.Custom.Resource.NinjaScriptIndicatorDiff);
                    AddLine(Brushes.DarkGray,                0,                NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);
                }
                else if (State == State.Configure)
                {
                    constant1    = 2.0 / (1 + Fast);
                    constant2    = (1 - (2.0 / (1 + Fast)));
                    constant3    = 2.0 / (1 + Slow);
                    constant4    = (1 - (2.0 / (1 + Slow)));
                    constant5    = 2.0 / (1 + Smooth);
                    constant6    = (1 - (2.0 / (1 + Smooth)));
                }
                else if (State == State.DataLoaded)
                {
                    fastEma = new Series<double>(this);
                    slowEma = new Series<double>(this);
                }
            }
    
            protected override void OnBarUpdate()
            {
                double input0    = Input[0];
    
                if (CurrentBar == 0)
                {    
                    fastEma[0]        = input0;
                    slowEma[0]        = input0;
                    Value[0]        = 0;
                    Avg[0]            = 0;
                    Diff[0]            = 0;
                }
                else
                {
                    double fastEma0    = constant1 * input0 + constant2 * fastEma[1];
                    double slowEma0    = constant3 * input0 + constant4 * slowEma[1];
                    double macd        = fastEma0 - slowEma0;
                    double macdAvg    = constant5 * macd + constant6 * Avg[1];
    
                    fastEma[0]        = fastEma0;
                    slowEma[0]        = slowEma0;
                    Value[0]        = macd;
                    Avg[0]            = macdAvg;
                    Diff[0]            = macd - macdAvg;
                }
            }
    }
    Attached Files

    #2
    Hello majoraspberry,

    Thank you for the post.

    Indicators will be added to new panels by default. Indicators with the IsOverlay property set to true will be placed on the input series panel by default.

    For example, the MAX indicator has:

    Code:
    IsOverlay	= true;
    If there is anything else I may assist with please let me know.
    Attached Files

    Comment


      #3
      But the code for MACD doesn't have an IsOverlay property.

      You mentioned using the MAX indicator, but that indicator is just overlaid on top of the chart. I mean a separate chart in the same window, as with the MACD indicator that I highlighted in red attached to my previous post. I'm sorry to have caused this misunderstanding.

      Comment


        #4
        Hello majoraspberry,

        Thank you for the follow up.

        This property is set to false by default. It exists higher up in the class hierarchy so the indicators that want to default to a new panel will not even use it. Try it out in your custom indicator. Set IsOverlay to true, then false. You will see the indicator is added to the input series panel by default when IsOverlay is true.

        If there is anything else I may assist with please let me know.

        Comment

        Latest Posts

        Collapse

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