Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to display values of my Series<> in data box

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

    How to display values of my Series<> in data box

    I have created a series for holding some values among my variables as follows:

    private Series<int> TPO_BLdiff_Series;

    and added the following code in the OnStateChange() method:

    if (State == State.DataLoaded)
    {
    // "this" refers to the NinjaScript object itself. This syncs the Series object to historical data bars
    // MaximumBarsLookBack determines how many values the Series<double> will have access to

    TPO_BLdiff_Series = new Series<int>(this, MaximumBarsLookBack.Infinite);
    }

    For the OnBarUpdate() method, I have calculated values and added them to my series as follows:

    //my code for calculating and storing values

    if(VAt.IsValidDataPoint(0) && POC.IsValidDataPoint(0) && VAb.IsValidDataPoint(0))
    {
    TPO_BLdiff_Series[0] = Convert.ToInt32(100*(POC[0]-VAb[0]));
    }

    Now the hurdle I have been unable to overcome is how to display the values of my series in the data box. I don't know how to code the xml of the Properties region to achieve this so that if I hover my mouse cursor above a bar on the chart, I can see the value of TPO_BLdiff_Series for that bar in the data box. I have reached the limits of my programming know-how and would highly appreciate if someone could kindly help me to accomplish my desired task. Many thanks in advance.

    #2
    Hello mbesha,
    Thanks for your post.

    You need to assign your series to 'Value'. Try this.

    Code:
    if(VAt.IsValidDataPoint(0) && POC.IsValidDataPoint(0) && VAb.IsValidDataPoint(0))
    {
    	TPO_BLdiff_Series[0] = Convert.ToInt32(100*(POC[0]-VAb[0]));
    	Value[0] = TPO_BLdiff_Series[0];
    }
    Help Guide - Value
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks JoshG. Does this hold true if I already have other Values[] in the indicator? As it stands, there are already Series<> objects ranging from Values[1] to Values[6] that are plotted on the chart.

      Comment


        #4
        Yes, you would need to assign a Value[] to any series to have it appear in the data box. You can assign as many Values as you like to appear in the data box starting at an index of zero.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          I was trying to get my data into the Data Box, so I added a "Values[0] = " statement, but received this error.

          "Error on calling "OnBarUpdate" method on bar 50: Index was outside the bounds of the array.

          I know this is a common error if you are asking for bars not in the array.


          I know it's related to my statement of
          PHP Code:
                      if (CurrentBar < 50) return; 
          
          but I put that statement to make sure I didn't get this error.

          But I can't figure out where in my pretty simple code I went wrong. Any help is appreciated.

          here is my code

          PHP Code:
          public class PeakValley : Indicator
              {
                  public override string DisplayName
                      {get {if (State == State.SetDefaults) return "PeakValley"; else  return ""; }}
          
                  public Series<double>         pricePeak, priceValley;
                  public Series<double>         uOPeak, uOValley;
          
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                                    = @"Enter the description for your new custom Indicator here.";
                          Name                                        = "PeakValley";
                          Calculate                                    = Calculate.OnBarClose;
                          IsOverlay                                    = true;
                          DisplayInDataBox                            = true;
                          DrawOnPricePanel                            = true;
                          DrawHorizontalGridLines                        = true;
                          DrawVerticalGridLines                        = true;
                          PaintPriceMarkers                            = true;
                          ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                          //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                          //See Help Guide for additional information.
                          IsSuspendedWhileInactive                    = true;
                      }
                      else if (State == State.Configure)
                      {
                      }
          
                      else if(State == State.DataLoaded)
                      {
                          pricePeak            = new Series<double>(this, MaximumBarsLookBack.Infinite);
                          priceValley            = new Series<double>(this, MaximumBarsLookBack.Infinite);
                          uOPeak                = new Series<double>(this, MaximumBarsLookBack.Infinite);
                          uOValley            = new Series<double>(this, MaximumBarsLookBack.Infinite);
          
                      }
          
                  }
          
                  protected override void OnBarUpdate()
                  {
                      if (CurrentBar < 50) return;    
          
                      int lookback = 1;
                      FindPricePeak();
                      FindUOPeak();
                      FindPriceValley();
                      FindUOValley();
          
                      if(pricePeak[0] > 0)
                          Draw.Dot(this,     "PricePeak" + Time[0].ToString(), true, lookback, High[lookback], Brushes.White);
                      if(priceValley[0] > 0)
                          Draw.Dot(this,     "PriceValley" + Time[0].ToString(), true, lookback, Low[lookback], Brushes.White);
                      if(uOPeak[0] > 0)
                          Draw.Dot(this,     "UO" + Time[0].ToString(), true, lookback, High[lookback] + 2, Brushes.Yellow);
                      if(uOValley[0] > 0)
                          Draw.Dot(this,     "UO" + Time[0].ToString(), true, lookback, Low[lookback] - 2, Brushes.Yellow);
          
                  }
          
          //==========================================================================================
                  private void FindPricePeak()
                  {
                      if(Close[0] < Open[0] && Close[1] > Open[1] && Close[2] > Open[2])
                          pricePeak[0] = High[0];
                      else
                          pricePeak[0] = 0;
          
                      Value[0] = pricePeak[0];
                  }&#8203; 
          

          Comment


            #6
            Hello cre8able,

            Thanks for your notes.

            Only plot values will appear in the Data Box window.

            You could add a plot to the script and assign your calculated value to the plot if you want it to appear in the Data Box window.

            AddPlot: https://ninjatrader.com/support/help...t8/addplot.htm
            Values: https://ninjatrader.com/support/help...nt8/values.htm

            See the forum thread linked below for more information and sample code.
            https://forum.ninjatrader.com/forum/...90#post1262590
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            590 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            342 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            555 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X