• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why won't this simple Wizard created code plot?

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

    Why won't this simple Wizard created code plot?

    This code, named My Temporary, is exactly as the New Indicator Wizard created it -- no changes. Why won't it plot when loaded? The right scale appears as 0 to 1 in .2 increments but its panel, panel 2, is empty, other than showing the legend of MyTemporary. I created it because custom code I was working on didn't plot so I tested this simple indicator, expecting it to plot, with the intent of adding my coding to it. I've closed and reopened NT7 and created a brand new chart to preclude chart corruption issues. Native NT7 indicators do plot. Why not this wizard generated code. I expected it to plot both lines as the close of the primary data series which is es 03-17, which does plot in panel 1.

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class MyTemporary : Indicator
    {
    #region Variables
    // Wizard generated variables
    private double myInput0 = 0.000; // Default setting for MyInput0
    private double myInput1 = 0.000; // Default setting for MyInput1
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "Plot1"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(Close[0]);
    Plot1.Set(Close[0]);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot0
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot1
    {
    get { return Values[2]; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(0.000, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public double MyInput1
    {
    get { return myInput1; }
    set { myInput1 = Math.Max(0.000, value); }
    }
    #endregion
    }
    }

    #2
    Why won't this simple Wizard created code plot?

    Hello ProfitPilgrim,

    Thanks for writing in to our Support team.

    You are not seeing any lines being plotted from this indicator because you are trying to set two different plots at the same value. I tested your code on my end and received the same results, however when I removed either Plot0.Set(Close[0]); or Plot1.Set(Close[0]); I saw the corresponding line being plotted.

    Please let me know if I may be of any further assistance.
    Alan S.NinjaTrader Customer Service

    Comment


      #3
      Thanks Alan. Experimenting with your solution I discovered that in the Properties section of the code Plot0 was set to "get { return Values[0];" and Plot1 to "get { return Values[2];" When I set the Plot1 Values to 1 (a contiguous number from Plot0's setting of 0, both plots plotted.

      I still have a problem that occurs in my real indicator and in the posted simplified code when I Add symbols. In the Initialize code I can Add some symbols without their blocking the plots, but not other symbols. They are all plotable symbols that are up to date in the Instrument Manager. I use all caps because symbols are case sensitive. I format them this way:

      Add("YM 03-17", PeriodType.Tick, 1);
      Add("ES 03-17", PeriodType.Tick, 1);
      Add("NQ 03-17", PeriodType.Tick, 1);

      YM doesn't prevent plots from plotting but ES and NQ do. Why? Try it in your code. I'm offline but have data for the day I am test plotting.
      Last edited by ProfitPilgrim; 03-06-2017, 07:51 AM.

      Comment


        #4
        Hello ProfitPilgrim,

        Thanks for your reply.

        I tested adding these bar objects and did not run into any issues with my plots no longer being plotted. Have you ensured you are compiling your code after making changes and reloading NinjaScript on your chart by right clicking on your chart and selecting Reload NinjaScript?

        Also, may I ask what version of NinjaTrader are you using? You can check under Help -> About (Example: 7.0.1000.X)

        I look forward to your reply.
        Alan S.NinjaTrader Customer Service

        Comment


          #5
          Possible BUG in NT7 re. Add ordering in code?

          Thanks Alan, Yes to both questions -- I do recompile then Reload NinjaScript. I run version 7.0.1000.32 (multibroker live).

          With a lot more experimenting I have discovered that in the below list of Added symbols the order in which some (not all) symbols are Added determines whether the indicator plots!
          Add("YM 03-17", PeriodType.Tick, 1);
          Add("DX 03-17", PeriodType.Tick, 1);
          Add("NQ 03-17", PeriodType.Tick, 1);
          Add("6E 03-17", PeriodType.Tick, 1);
          Add("6J 03-17", PeriodType.Tick, 1);
          Add("ES 03-17", PeriodType.Tick, 1);

          DX and YM can be duplicated in any position but are the only symbols of these that I've tested that work in position 1 and 2.

          NQ,ES,6E,6J must not be in the 1st or 2nd positions or it kills the plots. Is this an NT bug? Why should the order in which I Add make any difference? The code is the simple wizard-generated indicator with no OnBarUpdate code other than plotting fixed numbers of 7 and 9. I've repasted the current code below.

          To reproduce my environment go offline and use stored historical data.

          I've also confirmed by recreating a wizard-produced indicator that when the wizard presents an opportunity to add plots, if the user skips the 2nd field and enters a plot in the 3rd field because they perhaps like the default color better than that in the second field (as I did when the first code I sent you accordingly failed) the values of the properties of those plots, not being contiguous, will prevent plots from plotting. You might advise your programmers to prevent a user from being able to generate that failure as it can cost the unaware a lot of troubleshooting time. I also confirmed that both plots can be the Close[0] and it will still plot

          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion

          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class MyTemporary : Indicator
          {
          #region Variables
          // Wizard generated variables
          private double myInput0 = 0.000; // Default setting for MyInput0
          private double myInput1 = 0.000; // Default setting for MyInput1
          // User defined variables (add any user defined variables below)
          #endregion

          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
          Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "Plot1"));
          Overlay = false;
          Add("YM 03-17", PeriodType.Tick, 1);
          Add("DX 03-17", PeriodType.Tick, 1);
          Add("NQ 03-17", PeriodType.Tick, 1);
          Add("6E 03-17", PeriodType.Tick, 1);
          Add("6J 03-17", PeriodType.Tick, 1);
          Add("ES 03-17", PeriodType.Tick, 1);
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.
          Plot0.Set(9);
          Plot1.Set(7);
          }

          #region Properties
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries Plot0
          {
          get { return Values[0]; }
          }

          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries Plot1
          {
          get { return Values[1]; }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public double MyInput0
          {
          get { return myInput0; }
          set { myInput0 = Math.Max(0.000, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public double MyInput1
          {
          get { return myInput1; }
          set { myInput1 = Math.Max(0.000, value); }
          }
          #endregion
          Last edited by ProfitPilgrim; 03-06-2017, 02:30 PM.

          Comment


            #6
            Hello ProfitPilgrim,

            Thanks for your reply.

            After adding bar objects to your code via the Add() method, you will need to use an if (BarsInProgress == x) check to reference the bars object that is calling the OnBarUpdate() method. It also would be prudent to include a check to make sure our bar objects contain enough bars to calculate information from. You can do this by running a check on the CurrentBars including the bar series index against the BarsRequired.

            Here is a sample for reference:
            Code:
            // Checks if the bar object with index value of 1 has enough bars to calculate
            if (CurrentBars[1] <= BarsRequired)
            return;
            if (BarsInProgress == 1)
            {
            // Do something
            }
            You can refer to this section of our help guide that includes useful information on coding with Multi-Time Frames and Instruments:
            http://ninjatrader.com/support/helpG...nstruments.htm

            Please let me know if I may be of any further assistance.
            Alan S.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Tradarr, Today, 06:25 PM
            2 responses
            5 views
            0 likes
            Last Post Tradarr
            by Tradarr
             
            Started by cocopod, Today, 04:47 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_JoshG  
            Started by digibob, Today, 02:47 AM
            2 responses
            14 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by mntemel, Today, 03:31 PM
            4 responses
            21 views
            0 likes
            Last Post mntemel
            by mntemel
             
            Started by mrlucky1x, Today, 03:14 PM
            2 responses
            7 views
            0 likes
            Last Post mrlucky1x  
            Working...
            X