Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not Plotting

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

    Not Plotting

    I wrote my very first indicator from scratch. However, its not plotting and I'm not sure why. How do I share my code and see if anyone has any input?

    Thanks!

    #2
    Hello Shiner452,

    If the script is not plotting I would suggest as a first step to check the NinjaScript output window and control center log tab to check for any runtime errors.

    You can attach the script to the post, indicators are held in the folder: Documents\NinjaTrader 8\bin\Custom\Indicators

    Comment


      #3
      Jesse thanks for the response! This is what it says on the Output window...

      Indicator 'FibRange': Error on calling 'OnStateChange' method: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      I do not have any script that says 5 bars ago...there is not a [5]...and there are 1825 bars on the chart....its a weekly chart and this is the default setting. Any thoughts on this error?

      Comment


        #4
        I do have

        else if (State == State.Configure)
        {PeriodHigh = High[1];
        PeriodLow = Low[1];
        PeriodRange = PeriodHigh-PeriodLow;
        }

        Comment


          #5
          Hello Shiner452,

          Any bar related code needs to go inside the OnBarUpdate method. State.Configure is happening before bars begin processing. You will also need a current bar check for checking 1 BarsAgo::

          Code:
          if(CurrentBar < 1) return;

          Comment


            #6
            If I move it to the on bar update section i get the error

            PeriodHigh does not exist in the current context.

            Comment


              #7
              Well I fixed that by moving Double PeriodHigh to the same section.

              Comment


                #8
                I now get no errors in the ninja output window but also no plots. Hmmm...I am attaching the .cs file...Maybe if you have time you can check it out. I thought it would be pretty straightforward but maybe i'm batting way out of my league with it.
                Attached Files

                Comment


                  #9
                  Hello Shiner452,

                  From the file it looks like you have incorrectly set up the plots. From this point I would suggest to do the following to make the fix easier:
                  1. In the NinjaScript editor right click on Indicators -> New.
                  2. In the indicator wizard add the plots and configure them using the plots page
                  3. Generate the indicator.

                  After doing that you will end up with a new file with the correct format for the plots. You can copy the AddPlot statements into your existing script along with the associated public properties.

                  You did add plots to your script but you did not add public properties for the plots which is going to make setting values difficult with this many plots.

                  The problem is how you defined the plot names:

                  Code:
                  Double Fib1;
                  Double Fib2;
                  Double Fib3;
                  Double Fib4;
                  Double Fib5;
                  Double Fib6;
                  Double Fib7;
                  Double Fib8;
                  Double Fib9;
                  Double Fib10;
                  Double Fib11;
                  Double Fib12;
                  Double Fib13;
                  Double Fib14;
                  Double Fib15;
                  Double Fib16;
                  Double Fib17;
                  Double Fib18;
                  Double Fib19;
                  These are just double numbers, your actual plots that did get created are at the bottom of the file in the properties:

                  Code:
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> Fib1
                  {
                  get { return Values[0]; }
                  }

                  When you create plots using the wizard it generates these public properties which makes is so in OnBarUpdate you set the plots like this:

                  Code:
                  Fib1[0] = Close[0]; //or whatever double number you wanted to set here

                  Comment


                    #10
                    Jesse thanks so much its working! woot woot!

                    i have another question. In the attached image you can see the horizontal lines display for only the period in which they are called. currently my lines are HLines and they extend right and left depnding on the candle that is at the right side of the screen. Is there a way to make this to where they diaplay he same as in the image?
                    Attached Files

                    Comment


                      #11
                      Hello Shiner452,

                      To do what you have displayed in the image would require using a Plot. You would have to plot a value for each bar, once the value changes it would end up looking like what you displayed in the image. The only problem with using a plot is that it will make an angled line between the two different values. To make a better version of that you could do something like the Pivots indicator does and use a plot to store data and custom render it using OnRender.

                      Comment


                        #12
                        This sounds exactly what I need to do but its a little out of my understanding. I'll read up on OnRender and storing data. Thanks!

                        Comment


                          #13
                          Is there a way to make it to only display the calculation for RTH? Here is how I have it set up...I have a second data series on the chart set for the weekly time frame. That data series is set for RTH only. I link that data series with the indicator but it still calculates using the full period high and low. I'd like it to only calculate using the high and low from the RTH session.

                          Comment


                            #14
                            I have added this code to the OnStateChange section but I don't know how to link it to the plot

                            AddDataSeries("MNQ", new BarsPeriod { BarsPeriodType = BarsPeriodType.Week, Value = 1 }, "US Equities RTH");

                            Comment


                              #15
                              Hello Shiner452,

                              To display calculations only for RTH hours would require making a time condition which plots during those hours and then does not plot outside those hours. Adding a secondary series won't necessarily help because the plotting still has to be done on the primary series so it would be easiest to just add a time condition for the plotting and select the ETH hours when running the script.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 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