Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multiple data series for a strategy

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

    multiple data series for a strategy

    Is there anyway where I can apply two data series to a strategy. I would like conditions for the tick chart and another condition for a minute chart for a particular future contract. If Ninjatrader can handle this I would greatly appreciate any guidance.

    #2
    Hello Chris001,

    This is certainly possible in NinjaScript.
    I will post a simple sample showing how you would use multiple series. You may also want to take a look at these documents


    Multi Data Series


    All of the methods you usually use to get your price data Close[0], Open[0], High[0], Low[0] have a second method named identical with an "s" letting Ninjascript know you want to access multiple data series, so Closes[0][0], Opens[0][0], Lows[0][0], Highs[0][0] and so on.

    You get an extra [0] at the end and this I will explain, Closes[DataSeriesIndex][BarsAgo]

    The example I have attached prints to the output window and shows the Close price for the 1 minute chart you start with and automatically adds a 5 minute data series to the chart and uses the 5 minute data as well. You may want to take a look in the code as I have used the ES 06-14 instrument for the example, you can change this to anything you normally use to view the example.

    Code:
     protected override void Initialize()
            {
                CalculateOnBarClose = true;
    			Add("ES 06-14", PeriodType.Minute, 5);
            }
    
            protected override void OnBarUpdate()
            {
    				Print ("one minute Data series close: " + Closes[0][0] + "   five minute Data series close: "  + Closes[1][0]);
            }
    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I think this will help, it seems to make sense to me but I have yet to test it. Something I am concerned about as the examples do not seem to specify, how can I set an indicator (say Volume Moving Average) in my strategy conditions to a specific instrument (1 minute) while the other indicators are referenced to the other instrument (Renko). Thanks.

      Comment


        #4
        I am clearly doing some things very wrong. I have attached the csv file for the compiling errors of my strategy, I copied some bits where the indicated lines of code relate to the errors. In this case I want Momentum to be from the 1 minute chart, and the rest of the condition is for the chart default which is a Renko.

        Thanks



        protected override void Initialize()
        {
        Add("6C 06-14", PeriodType.Minute, 1);
        Add(Momentum("6C 06-14",14)); //line 44



        if (Slope(DonchianChannel(DonchainPeriod).Upper, 1, 0) > 0
        && Momentum("6C 06-14",14)[0] > 0 //line 104
        && NBarsUp(BarUPandDOWNCount, true, true, true)[0] == one
        && ToTime(Time[0]) != ToTime(Time[1]))
        Attached Files

        Comment


          #5
          Hello Chris001,
          You almost have that correct. I will attach an example Strategy using what you have provided. The reason you are getting errors is the way the chart is set up and the data series that you are trying to access.

          To start open the base chart you want to start with so in this case it sounds like you wanted the Renko.
          Once you have the Renko as your first chart, you can use Ninjascript to add an additional dataseries to the chart from your strategy. I have used Close prices in this example as I did not see what value you were trying to base this off of.

          Code:
          Add("6C 06-14", PeriodType.Minute, 1);
          Now you have added an additional data series as a 1 minute chart, you will not see a difference on the chart because you have not told NinjaTrader to plot this data but only use it.
          You do not need to add the momentum the same way unless you are just trying to plot it on the chart

          For your if statement you almost had that set up correctly as well, I only had to change the dataseries in the momentum statement
          Code:
          && Momentum(Closes[1],14)[0] > 0)
          If you are not planning on plotting the indicator but only get values from it you can just call it by its name, and use the dataseries of your choosing for its input.

          You will notice throughout the example I have used Closes[1] - the 1 being the second dataseries on the chart, the initial Renko chart is an index of 0 then the added by Ninjascript dataseries assumes the index of 1 after being added, a third data series would be an index of 2.

          Please let me know if I may be of additional assistance.
          Attached Files
          JesseNinjaTrader Customer Service

          Comment


            #6
            [0] and [1] both seem to reference Renko

            CalculateOnBarClose = true;
            Add("6J 06-14", PeriodType.Minute, 1);
            Add(Momentum(Closes[1],14));
            Attached Files

            Comment


              #7
              Hello Chris001,
              It looks like this is being caused by adding the momentum to the chart in the initialize. The momentum is trying to access 14 bars back at the start when there is no data yet to calculate on for the newly added 1 minute chart. this makes the Closes[0] the same as Closes[1].

              It seems for your specific setup that you may want to try the following

              In the data series box
              Add a Renko chart so you will have a new chart with Renko added only

              Change your Initialize to this
              Code:
              protected override void Initialize()
              {
              CalculateOnBarClose = true;
              Add("6C 06-14", PeriodType.Minute, 1);
              }
              Finally you can access the Momentum in OnBarUpdate by using calling the indicator name, the value is produced for the current bar [0]. This works for getting the indicators data for the added 1 minute chart.
              Code:
              protected override void OnBarUpdate()
              {
              Print(Momentum(Closes[1],14)[0]);					
              }
              There is no reason to add the momentum to the Initialize unless you want to plot the momentum based off the default chart data series. You can instead just use the indicator to calculate the values of the 1 minute chart by calling it in the onBarUpdate. This will allow you to use this data in your conditional statements (if statement).

              Because the strategies work differently than indicators, If you need to see the momentum plotted you could add a 1 minute chart through the data series box and add a momentum indicator to it. If you just want to see the momentum and not the 1 minute chart you could hide the visibility of the 1 minute chart also.

              I will post a link to a video on Hidden dataseries for reference if you would like to hide a data series but uses its values to plot on the chart.
              Download NinjaTrader FREE at http://www.ninjatrader.comThis video demonstrates how to plot an indicator based off of one data series, overlay it onto another...


              Please let me know if I may be of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thank you Jesse. Thanks for all your help walking me through this. I think it is working the way I want it to, I have a couple tests in mind to confirm this, but I still need to check. Running the optimizer for a strategy with two different data series on different time scales is painfully slow. Running an optimization that would normally take a couple minutes for one data series is now taking upwards of a couple hours when the strategy is utilizing Renko and minute data. This is also only on a subset of my historical data for that instrument. Are you free to disclose if there are plans for multithreading for NT 8.0? If so is there a target date of release?

                Comment


                  #9
                  Hello Chris001,

                  NinjaTrader 8 is going to see several performance improvements including being fully multi -threaded. Unfortunately we do not have a target date at this time.

                  Please let me know if I may be of additional assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi,

                    I am working on coding a multi-chart strategy. The sample shows Periodtype.Minute. I want it to be Periodtype.NTRenkoCandle but for some reason it does not work.

                    Is it even possible? The drop down menu shows all options like: custom1,minute,renko etc. but the NTRenkoCandle is missing.

                    Any help will much appreciated

                    Comment


                      #11
                      Hello,

                      Thank you for the post.

                      To use custom BarsTypes you would utilize the Custom or Final names depending on which this BarsType takes. If this is an open source item you can look at its code to find this out, otherwise you could use the following tool: http://ninjatrader.com/support/forum...08&postcount=2

                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Is there a way to not have to hard-code the instrument and contract expiration when referencing another data series? For instance, let's say I want to run the strategy on a 1-minute chart of CL 03-18, but want the strategy to look at values of an indicator over a renko 4-brick chart of the same instrument and expiration. I don't want to have to update the strategy with new expirations, and also don't want to have a different strategy for every instrument I decide to use the strategy with.

                        Comment


                          #13
                          Hello,

                          Thank you for the post.

                          While it is possible to use variables in the Add syntax, it is known to fail in some cases so it is not suggested to do so. You are free to test this but please be aware that it is known that dynamic properties used in combination with Add can cause issues. Generally, if you do this, you need to ensure that the script is fully removed and re-added instead if using F5 or just refreshing the script. This would also apply to indicators and is also still the case going forward in NT8. This is further documented going forward in NT8 as a warning in the helpguide.

                          I will take in a feature request from this comment to add support for dynamic data series adding.

                          I look forward to being of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Thanks, Jesse.

                            Due to issues with backtesting renko bars, I want the primary data series to be time- or tick-based, with the entry criteria based on indicator values at the close of the renko bar. Will the OnBarClose statement apply to both data series?

                            Comment


                              #15
                              Hello,

                              Yes, when you Add an additional series it subscribes to that instrument/timeframe/barstype which would, in turn, call the overrides in the script.

                              This is considered a Multi series script, we do have a document which describes these concepts here: https://ninjatrader.com/support/help...ub=multi%2Bbar

                              You would need to utilize BarsInProgress to identify which series has called OnBarUpdate, this is documented in the above link with examples.

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CortexZenUSA, Today, 12:53 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by CortexZenUSA, Today, 12:46 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by usazencortex, Today, 12:43 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post usazencortex  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              168 responses
                              2,265 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X