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

Accessing values of multiple manually added Data Series

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

    Accessing values of multiple manually added Data Series

    If I have a chart with two manually added Data Series, and I apply an indicator to the first Data Series; how can additionally obtain values from the second Series for calculation purposes?

    #2
    Hello drmartell,

    Thanks for writing in.

    NinjaScripts have no way of knowing how many data series have been added to a chart when that indicator is applied to that chart. You can manually set the indicator to point to the other data series, but the NinjaScript cannot know this on its own.

    If you would like to use multiple data series for calculations in an indicator, you will have to add the data series from code.

    You can use AddDataSeries() to accomplish this.

    There is a sample strategy on our forums that outlines how to use multiple data series which may be of use to you:
    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


    I will also copy links to the relevant documentation it uses.

    Please also take the time to read the documentation on creating NinjaScripts for Multi-Time Frame & Instruments: http://ninjatrader.com/support/helpG...nstruments.htm

    If you have any additional questions please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you, is there any way to add a Data Series as a user selected parameter?

      Comment


        #4
        If your adding a second or third data series to a chart you can add the same data series for calculation purposes inside the indicator as Ninja_Jim indicated. If you only need them on the chart for calculation purposes inside your indicator, you don't need to add them to the chart only in the indicator.

        Comment


          #5
          Hello drmartell,

          As DataSeries are added in State.Configure, this is not advised. You can, however, add all of the data series you need and you can add parameters that disable processes for certain overloads by adding a return condition for the data series you do not want to use.

          For example, for every additional data series that you add in State.Configure, you can use a bool to tell if that instrument is listed as a parameter. Please consider a private bool UseAdditionalESDataSeries in the example below.

          Code:
          protected override void OnStateChange()
          {
          	if (State == State.SetDefaults)
          	{
          		...
          		
          		Instrument1					= @"ES 06-17";
          	}
          	else if (State == State.Configure)
          	{
          		AddDataSeries("ES 06-17", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
          	}
          	else if (State == State.DataLoaded)
          	{
          		if( Instrument1 != "ES 06-17")
          			UseAdditionalESDataSeries = false;		
          	}
          }
          Code:
          protected override void OnBarUpdate()
          {
          	if ((UseAdditionalESDataSeries == false) && (BarsInProgress == 1))
          		return;
          	//Add your custom strategy logic here.
          }
          You can use the following reference sample for adding user defined input parameters to your NinjaScript: http://ninjatrader.com/support/forum...ead.php?t=5782

          Please let me know if you have any additional questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            Thank you,

            I ended up approaching it like this:



            Code:
            			else if (State == State.Configure)
            			{
            				try { AddDataSeries(SecondaryInstrument, MyBarsPeriodType, MyBarsPeriodValue); }
            				catch { System.Windows.Forms.MessageBox.Show("Unable to load secondary Data Series"); }
            			}
            			else if (State == State.DataLoaded)
            			{
            				if (MyBarsPeriodType != BarsPeriod.BarsPeriodType || MyBarsPeriodValue != BarsPeriod.Value)
            					System.Windows.Forms.MessageBox.Show("Secondary Data Series type and period must match Primary Series");
            			}
            I still would prefer to be able to default the values of the secondary series to match the Input series. However, it appears the indicator does not have access to that information even though it is accessible from the Indicator Properties dialog.

            Comment


              #7
              Ok actually, this is closer to what I wanted and is working:



              Code:
              			else if (State == State.Configure)
              			{
              				try { AddDataSeries(SecondaryInstrument, Bars.BarsPeriod.BarsPeriodType, Bars.BarsPeriod.Value); }
              				catch { System.Windows.Forms.MessageBox.Show("Unable to load secondary Data Series"); }
              			}
              I.e. the Input series type and period are inherited.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by WHICKED, Today, 02:02 PM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by selu72, Today, 02:01 PM
              0 responses
              0 views
              0 likes
              Last Post selu72
              by selu72
               
              Started by f.saeidi, Today, 12:14 PM
              8 responses
              21 views
              0 likes
              Last Post f.saeidi  
              Started by Mikey_, 03-23-2024, 05:59 PM
              3 responses
              49 views
              0 likes
              Last Post Sam2515
              by Sam2515
               
              Started by Russ Moreland, Today, 12:54 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Erick  
              Working...
              X