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 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>         pricePeakpriceValley;
                  public 
          Series<double>         uOPeakuOValley;


                  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>(thisMaximumBarsLookBack.Infinite);
                          
          priceValley            = new Series<double>(thisMaximumBarsLookBack.Infinite);
                          
          uOPeak                = new Series<double>(thisMaximumBarsLookBack.Infinite);
                          
          uOValley            = new Series<double>(thisMaximumBarsLookBack.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(), truelookbackHigh[lookback], Brushes.White);
                      if(
          priceValley[0] > 0)
                          
          Draw.Dot(this,     "PriceValley" Time[0].ToString(), truelookbackLow[lookback], Brushes.White);
                      if(
          uOPeak[0] > 0)
                          
          Draw.Dot(this,     "UO" Time[0].ToString(), truelookbackHigh[lookback] + 2Brushes.Yellow);
                      if(
          uOValley[0] > 0)
                          
          Draw.Dot(this,     "UO" Time[0].ToString(), truelookbackLow[lookback] - 2Brushes.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
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Lumbeezl, 01-11-2022, 06:50 PM
            31 responses
            817 views
            1 like
            Last Post NinjaTrader_Adrian  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            5 responses
            14 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by swestendorf, Today, 11:14 AM
            2 responses
            6 views
            0 likes
            Last Post NinjaTrader_Kimberly  
            Started by Mupulen, Today, 11:26 AM
            0 responses
            7 views
            0 likes
            Last Post Mupulen
            by Mupulen
             
            Started by Sparkyboy, Today, 10:57 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X