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

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
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        213 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        544 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        12 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X