Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimizing on BarsArray with MultiData Strategies

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

    Optimizing on BarsArray with MultiData Strategies

    Hello,

    I am getting errors when I try to optimize a MultiData Strategy where i am using variables for the AddDataSeries statements.

    For instance in State.Configure :
    Code:
    AddDataSeries(BarsPeriodType.Tick, BarsPeriod.Value / PeriodFactorVariable);
    I believe I was able to do this effectively in NT7. But in NT8B10 I am receiving the following error when I try to optimize:

    Code:
    2016-04-15 16:41:03:969 ---- DEBUG ASSERTION FAILED ----
    ---- Assert Short Message ----
    NinjaScript.NinjaScriptBase.InitializeBarsPool: callback == null
    ---- Assert Long Message ----
    
       at NinjaTrader.NinjaScript.NinjaScriptBase.InitializeBars(Bars[] barsArray, IProgress progress, Action`1 callback)
       at NinjaTrader.NinjaScript.Optimizers.Optimizer.RunBacktest(StrategyBase template, Parameter[] parameters)
       at NinjaTrader.NinjaScript.Optimizers.Optimizer.<>c__DisplayClass67_0.<WaitForIterationsCompleted>b__0()
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    Interestingly, no errors are generated when I just run a single backtest (i.e. the Bars Array is created correctly and the backtests completes correctly).

    Any reason I am unable to do this in NT8?

    Thanks,
    ATC

    #2
    Originally posted by tornadoatc View Post
    Hello,

    I am getting errors when I try to optimize a MultiData Strategy where i am using variables for the AddDataSeries statements.

    For instance in State.Configure :
    Code:
    AddDataSeries(BarsPeriodType.Tick, BarsPeriod.Value / PeriodFactorVariable);
    I believe I was able to do this effectively in NT7. But in NT8B10 I am receiving the following error when I try to optimize:

    Interestingly, no errors are generated when I just run a single backtest (i.e. the Bars Array is created correctly and the backtests completes correctly).

    Any reason I am unable to do this in NT8?

    Thanks,
    ATC
    Bars/Instrument objects are not guaranteed to be loaded until at least State.DataLoaded.

    i.e., BarsPeriod.Value


    They may be available from a standard backtest, but as you have encountered, accessing those objects in an earlier state may be problematic and should not be relied upon.

    NT7 has similar issues for similar reasons and we never recommended using these types of properties in Initialize()

    The implications of such behavior prevents you from dynamically loading a bars series through AddDataSeries() based on the current selected input. While it may work in some situations, it is not guaranteed and should be avoided.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Hello Matthew,

      And this is a perfect example as to why the ability to script optimizations would be very helpful.

      For instance via a json configuration file as metioned here:


      Please let me know when that is ready! Your competitor has the lead in this area!

      Thanks,

      Comment


        #4
        Originally posted by NinjaTrader_Matthew View Post
        Bars/Instrument objects are not guaranteed to be loaded until at least State.DataLoaded.

        i.e., BarsPeriod.Value


        They may be available from a standard backtest, but as you have encountered, accessing those objects in an earlier state may be problematic and should not be relied upon.

        NT7 has similar issues for similar reasons and we never recommended using these types of properties in Initialize()

        The implications of such behavior prevents you from dynamically loading a bars series through AddDataSeries() based on the current selected input. While it may work in some situations, it is not guaranteed and should be avoided.
        Hello Matthew,

        I took another look at this. I am getting the same error in all scenarios where I use anything other than a fixed scalar value.

        Meaning I get the same error when I use either
        Code:
        [COLOR=blue]var[/COLOR] myBarPeriod = 3350 * SI_LTCPeriodFactor; 
         AddDataSeries([COLOR=#2b91af]BarsPeriodType[/COLOR].Tick, myBarPeriod);
        OR
        Code:
        [COLOR=blue]const[/COLOR] [COLOR=blue]int[/COLOR] myBarsPeriod2 = 7000;  
         AddDataSeries([COLOR=#2b91af]BarsPeriodType[/COLOR].Tick, myBarsPeriod2);
        Why would neither of these work ? Just by switching from Backtest to Optimization run both fail. The AddDataSeries only works when the value is a scalar as in

        Code:
         AddDataSeries([COLOR=#2b91af]BarsPeriodType[/COLOR].Tick, 7000);
        Is this expected behavior? Thanks,

        Comment


          #5
          Hello tornadoatc,

          The methods used in NinjaTrader use specific types in the overload parameters.

          What happens when you declare your variable as an int, as required by the overload parameters?

          Code:
          int aValue = 10;
          int myValue = aValue * 2;
          AddDataSeries(BarsPeriodType.Tick, myValue);
          Are you certain that SI_LTCPeriodFactor is an int and is able to print a value before being used?
          Last edited by NinjaTrader_ChelseaB; 04-21-2016, 09:48 AM.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello tornadoatc,

            I'm not sure what the SI_LTCPeriodFactor is or what value this is holding so I am not able to test this.

            However, I've tested using const int and this appears to work without any issue.
            I've made a test script. Can you confirm if this script is causing an error on your end?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              First, I am adding the Data Series in a strategy and the error is only generated when I switch from "Backtest" to "Optimize" in the Strategy Analyzer.

              The following works fine in a backtest but when I attempt to optimize the variable SI_LTCPeriodFactor I get the Assertion Error:
              Code:
              [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
               AddDataSeries([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]BarsPeriodType[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Tick, ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2])(3350 * SI_LTCPeriodFactor));
              [/SIZE][/FONT][/SIZE][/FONT]
              Basically I am trying to optimize a multi Data Series Strategy where LTC represents a Longer Term Chart that is used to filter trading decisions.

              This should work. I am almost certain that I had this working / optimizing in NT7.

              Thanks for your help.

              Comment


                #8
                Hello tornadoatc,

                You will not be able to optimize a parameter that is being used in the AddDataSeries() method.

                All data is loaded before the optimizations begin. By changing the series this would require that different data be loaded which causes the crash.

                So the AddDataSeries() cannot use values that are optimized or changed dynamically.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Christopher_R, Today, 12:29 AM
                0 responses
                9 views
                0 likes
                Last Post Christopher_R  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                166 responses
                2,235 views
                0 likes
                Last Post sidlercom80  
                Started by thread, Yesterday, 11:58 PM
                0 responses
                3 views
                0 likes
                Last Post thread
                by thread
                 
                Started by jclose, Yesterday, 09:37 PM
                0 responses
                8 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,415 views
                0 likes
                Last Post Traderontheroad  
                Working...
                X