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

AddDataSeries doesn't work with Strategy Analyzer Optimization

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

    AddDataSeries doesn't work with Strategy Analyzer Optimization

    Hello,
    I'm using NT 8.0.9.0 64-bit. When I try to test multi-timeframe strategy in Strategy Analyzer with Backtest type Optimization, it fails with error:
    Strategy '<name>': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
    Testing those strategies with Strategy Analyzer Backtest type Standard, it works fine.
    Ex. Take SampleMACrossOver and add second timeframe:
    Code:
    else if (State == State.Configure)
    {
      AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 1);
     }
    With that code, strategy can't pass State.Configure, when run in SA with Optimization.
    Why Strategy Analyzer can't optimize strategy with second timeframe?

    #2
    Hello InteRadek,

    Thanks for opening the thread.

    This is a known limitation involving dynamically added Data Series which is not fully supported by NinjaScripts.

    From the help guide:
    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.
    However in this case, the Instrument is returning as a null object when it is accessed in State.Configure for the optimization.

    We are tracking interest to fully support dynamically added data series with the feature request ticket ID SFT-882. I'll submit a vote on your behalf.

    Upon implementation, this ID will be listed in the Release Notes page of the version of NinjaTrader that includes it. You can find the Release Notes here: https://ninjatrader.com/support/help...ease_notes.htm

    Feature requests are fulfilled based on our development team's schedule and priorities and we cannot provide a time frame for it to become available.

    If there is anything else I can do in the meantime, please let me know.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you for the informations. Hopefully dynamically added data series will be available soon.
      What is a good way to check if a strategy is running in Optimization mode?
      Code:
      else if (State == State.Configure)
      {
        if (?optimization?)
          AddDataSeries("instrument name", BarsPeriodType.Tick, 1);
        else
          AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 1);
      }
      Last edited by InteRadek; 10-09-2017, 01:24 AM.

      Comment


        #4
        Hello InteRadek,

        This is not documented and we could not guarantee the functionality will remain unchanged and will always work. I was able to find some direction you could follow to detect this, however.

        Code:
        if (State == State.Configure)
        {
        	if (Category == Category.Backtest)
        		Print("Strategy is running a regular backtest ");
        	else if (Category == Category.Optimize)
        		Print("Strategy is running an optimization ");
        	else if (Category == Category.WalkForward)
        		Print("Strategy is running walk forward optimization");
        	else if (Category == Category.MultiObjective)
        		Print("Strategy is running a multi objective optimization ");
        	else if (Category == Category.NinjaScript)
        		Print("Strategy is running on an account from a chart/strategies tab ");
        }
        See post #2 here: https://ninjatrader.com/support/foru...ad.php?t=78992

        Please let me know if this does not resolve your inquiry.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        0 responses
        2 views
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        6 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        217 views
        1 like
        Last Post PaulMohn  
        Working...
        X