Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

workaround for dynamic AddDataSeries in strategy optimizer

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

    workaround for dynamic AddDataSeries in strategy optimizer

    Hello everybody,

    first things first --> I am aware of:
    Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.

    Source:
    https://ninjatrader.com/support/help...dataseries.htm
    My strategy currently uses following code because I want to have the additional data series (in minutes) used as a selectable user value:
    Code:
    [...]
    protected override void OnStateChange()
    {[INDENT]if (State == State.SetDefaults)[/INDENT][INDENT]{[/INDENT][INDENT=2][...]
    DataSeriesMinutes = 60;
    [...][/INDENT][INDENT]}
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, DataSeriesMinutes);
    }[/INDENT]
      [...]
    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="DataSeriesMinutes", Description="Secondary DataSeries in minutes", Order=1, GroupName="Parameters")]
    public int DataSeriesMinutes
    { get; set; }
    [...]
    This works fine and as expected when manually changing the values in the strategy configuration. But I'd like to optimize and run through a set for this variable, eg I want to find out which values for the variable "DataSeriesMinutes" will generate best results for that strategy. I understand that I run into the mentioned limitation but my question is

    ==> Is there any workaround we could use for that goal? It would be time-consuming when I click on strategy analyzer and manually run a backtest for DataSeriesMinutes=1, DataSeriesMinutes=2, DataSeriesMinutes=3, DataSeriesMinutes=4, etc.

    any help appreciated.

    Thanks in advance!
    Patricia

    #2
    Hello Patricia,

    There is not a workaround for selectively and dynamically adding series. Instead, we suggest calling AddDataSeries() for every series, and then within the logic decide which BarsInProgress you would like to use data from.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sad to hear. But thanks for your reply Chelsea. However, your suggestion would not be suitable for the mentioned task. The goal is to have the strategy analyzer find the best value. Let's say I want to test 500 different values, I need to perform all those time-consuming tasks to get a result:

      - disable the running strategy
      - modify the value "DataSeries in minutes" to a new value
      - enable the running strategy
      - apply and hit OK
      - wait until finished
      - right-click onto the chart display and choose Strategy Performance --> historical
      - write down the result and compare to the previous ones
      - repeat the process until best result is found

      Now imagine how fun this is for a large set. even by using strategy analyzer --> backtest which is slightly quicker in running, it'll take a lot of time and nerves to get to the wanted results. My question was related to the thought that maybe there's a workaround for automatically performing all these tasks, something like a batch script or similar.

      However, thank you. Have a nice day
      Patricia.
      Last edited by patricia70; 07-07-2021, 07:54 AM.

      Comment


        #4
        Hello patricia70,

        There would not be anything supported for running those tasks. The supported approach would be adding all 500 series and within the logic of OnBarUpdate choosing the series used for data.

        The primary series can be optimized over. Would be possible to optimize the primary series and have the added series be the same?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The goal is to find out WHICH data series will perform best on that particular strategy.

          Comment


            #6
            Hello patricia70,

            That would be the result with the most net profit based on the data used for logic that triggers the orders.

            Optimizing the primary series or using a variable to optimize that is used in the logic to switch between BarsInProgress would both allow for this.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I'm very sorried, I did not understand that. My strategy produces different net profit results when using 1min bars or 30min bars oder 60min bars or ... Can you explain more detailled, please? Maybe you can show a small example ?

              Comment


                #8
                Originally posted by patricia70 View Post
                first things first --> I am aware of:

                My strategy currently uses following code because I want to have the additional data series (in minutes) used as a selectable user value:

                But I'd like to optimize and run through a set for this variable, eg I want to find out which values for the variable "DataSeriesMinutes" will generate best results for that strategy. I understand that I run into the mentioned limitation
                Did you try it?
                Did you experience a problem?

                Comment


                  #9
                  Hello patricia70,

                  Below is a link to a short video of optimizing over the primary data series.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by bltdavid View Post

                    Did you try it?
                    Did you experience a problem?
                    What you mean exactly? Of course I tried it, read above. When I am using the variable for my secondary data series (see my code) I get the error message in strategy analyzer optimizer:
                    Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.
                    Source: https://ninjatrader.com/support/help...dataseries.htm

                    Comment


                      #11
                      Hello patricia70,

                      Adding series dynamically is not supported.

                      You could instead optimize the primary series, and have a set added series with AddDataSeries().

                      If you are trying to do this without optimizing the primary series, have you added all series without using variables in AddDataSeries(), and then in the logic in OnBarUpdate used logic to switch between series?

                      AddDataSeries(BarsPeriodType.Minute, 1);
                      AddDataSeries(BarsPeriodType.Minute, 2);

                      public int UseSeries;

                      UseSeries = 1;

                      if (UseSeries == 1 && BarsInProgress == 1)
                      {
                      // execute code for series 1
                      }

                      if (UseSeries == 2 && BarsInProgress == 2)
                      {
                      // execute code for series 2
                      }
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chelsea,

                        but that would not help me in finding out which of the 500 added series will perform best, would it?

                        Comment


                          #13
                          Hello patricia70,

                          If UseSeries is 2, then the 2 minute series is placing orders. If this results in a higher net profit than when UseSeries is 1, then a 2 minute series "performs better" than a 1 minute series.. In my opinion this would help in finding out which series will perform best.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Yes, but I need to switch manually each run. This needs also interaction. I'm not sure if I understood correctly but I see no gain in your example. Better to let my current strategy untouched and run it through [Control Center] --> [New] --> [Strategy Analyzer] --> Backtest and manually enter the field for the current data series set in the parameters (see my code). That's where my question began to raise because I have entered about >100 times different settings for that variable DataSeriesMinutes in the backtest window.

                            EDIT: Ah, maybe I understand NOW. Did you mean I should run 200 tests in the primary data series and do a comparison between each run (or output the results of 200 runs in the output window) and manually compare the best result?

                            Comment


                              #15
                              Hello patricia70,

                              I'm not certain that I am understanding. UseSeries would be optimized and not manually set. What are you manually setting or interacting with?

                              The logic could also just compare to the variable.. 'if (BarsInProgress == UseSeries)'
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by usazencort, Today, 01:16 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post usazencort  
                              Started by kaywai, 09-01-2023, 08:44 PM
                              5 responses
                              603 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              6 responses
                              22 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Pattontje, Yesterday, 02:10 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post Pattontje  
                              Started by flybuzz, 04-21-2024, 04:07 PM
                              17 responses
                              230 views
                              0 likes
                              Last Post TradingLoss  
                              Working...
                              X