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

Multiple Line Plots

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

    Multiple Line Plots

    I'm trying to develop an indicator with three line plots. I followed the steps in the Level 2 tutorial and created Plot0, Plot1 and Plot2. When I compile, I get:
    "The name Plot1 does not exist in the current context."
    "The name Plot2 does not exist in the current context."

    #2
    I believe somehow you might have accidentally deleted the properties Plot1 and Plot2 inadvertently. Try replacing Plot1 and Plot2 with Values[0] and Values[1] and see if that works?
    RayNinjaTrader Customer Service

    Comment


      #3
      I'm lost. I tried to delete the file and try over again. I get:
      "This file is likely referenced by other Ninja script files and these dependencies need to be removed first."

      Comment


        #4
        Ray,
        You're right. I can't re Compile indicators that use Plot1. I get error CS1002 in the plot0 line

        Comment


          #5
          Jerry, if you post the code we can take a look - have you ended the statement offending properly with a semicolon? http://www.ninjatrader-support.com/H...V6/CS1002.html
          BertrandNinjaTrader Customer Service

          Comment


            #6
            How do I post it?

            Comment


              #7
              Open the code in the editor and then copy the relevant parts into here and then put code tags around it, the little romb icon whe you post here...
              BertrandNinjaTrader Customer Service

              Comment


                #8
                I can't find the ode tags. Get:

                "The name Plot1 does not exist in the current context."
                "The name Plot2 does not exist in the current context."

                // 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 GVsTry3Plots : Indicator
                {
                #region Variables
                // Wizard generated variables
                // 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.White), PlotStyle.Line, "Plot1"));
                Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot2"));
                CalculateOnBarClose = true;
                Overlay = false;
                PriceTypeSupported = 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]);
                Plot2.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[1]; }
                }

                [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 Plot2
                {
                get { return Values[2]; }
                }

                #endregion
                }
                }

                #region NinjaScript generated code. Neither change nor remove.
                // This namespace holds all indicators and is required. Do not change it.
                namespace NinjaTrader.Indicator
                {
                public partial class Indicator : IndicatorBase
                {
                private GVsTry3Plots[] cacheGVsTry3Plots = null;

                private static GVsTry3Plots checkGVsTry3Plots = new GVsTry3Plots();

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public GVsTry3Plots GVsTry3Plots()
                {
                return GVsTry3Plots(Input);
                }

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public GVsTry3Plots GVsTry3Plots(Data.IDataSeries input)
                {

                if (cacheGVsTry3Plots != null)
                for (int idx = 0; idx < cacheGVsTry3Plots.Length; idx++)
                if (cacheGVsTry3Plots[idx].EqualsInput(input))
                return cacheGVsTry3Plots[idx];

                GVsTry3Plots indicator = new GVsTry3Plots();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.SetUp();

                GVsTry3Plots[] tmp = new GVsTry3Plots[cacheGVsTry3Plots == null ? 1 : cacheGVsTry3Plots.Length + 1];
                if (cacheGVsTry3Plots != null)
                cacheGVsTry3Plots.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheGVsTry3Plots = tmp;
                Indicators.Add(indicator);

                return indicator;
                }

                }
                }

                // This namespace holds all market analyzer column definitions and is required. Do not change it.
                namespace NinjaTrader.MarketAnalyzer
                {
                public partial class Column : ColumnBase
                {
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.GVsTry3Plots GVsTry3Plots()
                {
                return _indicator.GVsTry3Plots(Input);
                }

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public Indicator.GVsTry3Plots GVsTry3Plots(Data.IDataSeries input)
                {
                return _indicator.GVsTry3Plots(input);
                }

                }
                }

                // This namespace holds all strategies and is required. Do not change it.
                namespace NinjaTrader.Strategy
                {
                public partial class Strategy : StrategyBase
                {
                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.GVsTry3Plots GVsTry3Plots()
                {
                return _indicator.GVsTry3Plots(Input);
                }

                /// <summary>
                /// Enter the description of your new custom indicator here
                /// </summary>
                /// <returns></returns>
                public Indicator.GVsTry3Plots GVsTry3Plots(Data.IDataSeries input)
                {
                if (InInitialize && input == null)
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

                return _indicator.GVsTry3Plots(input);
                }

                }
                }
                #endregion

                Comment


                  #9
                  Hmm and you are sure you get this error for the code you posted? Please double click on the error at the bottom to see exactly where those offending lines were found and in which script - NinjaTrader would compile all scrips all the time, so all need to be conflict free.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    They are in another indicator where I tried to lot straight lines:

                    Plot1.Set(50);
                    Plot2.Set(-50);

                    Comment


                      #11
                      Ok, then please ensure you have defined those Plots in the properties in the related indicator code.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Not clear. I didn't do anything for Plot1.

                        #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>
                        /// Plot Woodie's CCI
                        /// </summary>
                        [Description("Plot Woodie's CCI")]
                        public class GVsWoodiesCCI : Indicator
                        {
                        #region Variables
                        // Wizard generated variables
                        private int period = 20; // Default setting for Period
                        // 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.Red), PlotStyle.Line, "Plot0"));
                        Plots[0].Pen.Width = 2;
                        Period = 20;

                        Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot1"));
                        Plots[1].Pen.Width = 2;
                        Period = 20;

                        Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot2"));
                        Plots[2].Pen.Width = 2;
                        Period = 20;

                        CalculateOnBarClose = true;
                        Overlay = true;
                        PriceTypeSupported = true;

                        }

                        /// <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]);

                        // Do not calculate if we don't have enough bars
                        if (CurrentBar < Period) return;

                        double myCCIVal = WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2)[0];
                        Plot0.Set(myCCIVal);
                        Plot1.Set(50);
                        Plot2.Set(-50);

                        }

                        #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]; }
                        }

                        [Description("Number of periods")]
                        [Category("Parameters")]
                        public int Period
                        {
                        get { return period; }
                        set { period = Math.Max(1, value); }
                        }
                        #endregion
                        }
                        }

                        #region NinjaScript generated code. Neither change nor remove.
                        // This namespace holds all indicators and is required. Do not change it.
                        namespace NinjaTrader.Indicator
                        {
                        public partial class Indicator : IndicatorBase
                        {
                        private GVsWoodiesCCI[] cacheGVsWoodiesCCI = null;

                        private static GVsWoodiesCCI checkGVsWoodiesCCI = new GVsWoodiesCCI();

                        /// <summary>
                        /// Plot Woodie's CCI
                        /// </summary>
                        /// <returns></returns>
                        public GVsWoodiesCCI GVsWoodiesCCI(int period)
                        {
                        return GVsWoodiesCCI(Input, period);
                        }

                        /// <summary>
                        /// Plot Woodie's CCI
                        /// </summary>
                        /// <returns></returns>
                        public GVsWoodiesCCI GVsWoodiesCCI(Data.IDataSeries input, int period)
                        {
                        checkGVsWoodiesCCI.Period = period;
                        period = checkGVsWoodiesCCI.Period;

                        if (cacheGVsWoodiesCCI != null)
                        for (int idx = 0; idx < cacheGVsWoodiesCCI.Length; idx++)
                        if (cacheGVsWoodiesCCI[idx].Period == period && cacheGVsWoodiesCCI[idx].EqualsInput(input))
                        return cacheGVsWoodiesCCI[idx];

                        GVsWoodiesCCI indicator = new GVsWoodiesCCI();
                        indicator.BarsRequired = BarsRequired;
                        indicator.CalculateOnBarClose = CalculateOnBarClose;
                        indicator.Input = input;
                        indicator.Period = period;
                        indicator.SetUp();

                        GVsWoodiesCCI[] tmp = new GVsWoodiesCCI[cacheGVsWoodiesCCI == null ? 1 : cacheGVsWoodiesCCI.Length + 1];
                        if (cacheGVsWoodiesCCI != null)
                        cacheGVsWoodiesCCI.CopyTo(tmp, 0);
                        tmp[tmp.Length - 1] = indicator;
                        cacheGVsWoodiesCCI = tmp;
                        Indicators.Add(indicator);

                        return indicator;
                        }

                        }
                        }

                        // This namespace holds all market analyzer column definitions and is required. Do not change it.
                        namespace NinjaTrader.MarketAnalyzer
                        {
                        public partial class Column : ColumnBase
                        {
                        /// <summary>
                        /// Plot Woodie's CCI
                        /// </summary>
                        /// <returns></returns>
                        [Gui.Design.WizardCondition("Indicator")]
                        public Indicator.GVsWoodiesCCI GVsWoodiesCCI(int period)
                        {
                        return _indicator.GVsWoodiesCCI(Input, period);
                        }

                        /// <summary>
                        /// Plot Woodie's CCI
                        /// </summary>
                        /// <returns></returns>
                        public Indicator.GVsWoodiesCCI GVsWoodiesCCI(Data.IDataSeries input, int period)
                        {
                        return _indicator.GVsWoodiesCCI(input, period);
                        }

                        }
                        }

                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                        public partial class Strategy : StrategyBase
                        {
                        /// <summary>
                        /// Plot Woodie's CCI
                        /// </summary>
                        /// <returns></returns>
                        [Gui.Design.WizardCondition("Indicator")]
                        public Indicator.GVsWoodiesCCI GVsWoodiesCCI(int period)
                        {
                        return _indicator.GVsWoodiesCCI(Input, period);
                        }

                        /// <summary>
                        /// Plot Woodie's CCI
                        /// </summary>
                        /// <returns></returns>
                        public Indicator.GVsWoodiesCCI GVsWoodiesCCI(Data.IDataSeries input, int period)
                        {
                        if (InInitialize && input == null)
                        throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

                        return _indicator.GVsWoodiesCCI(input, period);
                        }

                        }
                        }
                        #endregion

                        Comment


                          #13
                          Jerry, you copied in the Add Plot1 and Plot2 statement, this way the indicator wizard did not generate the needed code lines in the properties section, you would need to add here -

                          Code:
                           
                          #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 Plot1
                          {
                          get { return Values[1]; }
                          }
                           
                          #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 Plot2
                          {
                          get { return Values[2]; }
                          }
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Thank You,

                            I don't completely understand but I learned a lot from this.

                            Comment


                              #15
                              You're welcome - this should help clarify - http://www.ninjatrader-support.com/HelpGuideV6/Add.html
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              23 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X