Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wasting time trying to optimize with doubles

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

    Wasting time trying to optimize with doubles

    So, after spending over a day trying to debug why the Strategy Analyzer wasn't showing results when I ran optimizations, I FINALLY found this post: https://forum.ninjatrader.com/forum/...type-parameter

    WHY WHY WHY doesn't the Analyzer pop-up a warning when you try to use non-integer double values??? Instead, everything looks to be running fine, and then when it finishes running (an hour later since I'm running multiple days with multiple params and using Tick Replay), there's just no results. But also no warnings, message, or any hint at all about why there's no results.

    Please add a check for this - and any other "secret requirements" the Strategy Analyzer has that would result in the same frustration.

    Thanks

    #2
    Hello GregX999,

    Thank you for your post.

    Not being able to optimize doubles was an issue in prior versions of NinjaTrader that has since been resolved. I suspect there is some other underlying reason that you were not getting results when you ran an optimization. As a test to see that doubles may be optimized, please see the attached script where I modified the Sample MA CrossOver to include a double parameter. You may set it to optimize, such as between values of 1 and 1.5 with an increment of .1. Keep the NinjaScript Output window open during the optimization and you will see the values print between 1.0, 1.1, 1.2, 1.3, 1.4, and 1.5.

    So I may assist you more accurately, please answer all of the following questions regarding your optimization with the double parameter in your strategy and not showing results:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • Do you see similar results when running the same test on the attached SampleMaCrossOverWithDouble strategy in NinjaTrader with the same/similar settings as your strategy?
    • Who are you connected to? This is displayed in green in the lower-left corner of the Control Center window.
    • Are you connected to your data feed provider when running this test?
    • What instrument(s) (and expiry if applicable) have you selected?
    • What Data Series Type have you selected? Example: Tick, Minute, Day
    • What From and To date is selected?
    • If you open a chart for the same instrument(s) and the same date range, then right-click the chart and select 'Reload all historical data' is the historical data showing on the chart?
    • Is your strategy a multi-instrument or multi-time frame strategy?
    • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    Thanks in advance; I look forward to further investigating this item.​
    Attached Files

    Comment


      #3
      Doh!! I figured it out.
      If I was optimizing with more than three values/combinations of values (ie: 0.5;3;0.5 ... so from 0.5 to 3, stepping 0.5 - thus 6 values) then all but three of the runs would error (and stop) because they were all trying to write to the same text file (w/ StreamWriter). I had a bug in my logic that was detecting when to write log files (my intent was to not write log files when running in the strategy analyzer).

      When I tried changing "0.5;3;0.5" to "1,3,1", then it worked fine, as that's just three runs, and all three runs were all able to write to the same text file (for some reason).

      So, I thought "hmmm... maybe something to do with non-integer values", and then found that old post.

      But, fixing my bug so it's not writing to any text files while in the Strategy Analyzer fixed the issue.

      Sorry for the false alarm.

      But... now for an actual request...
      I wasn't seeing the errors about "unable to write to text file" because my output log was getting truncated as I'm also outputting a lot of debug messages to the output windows.

      Can there be an option (or make it default behavior) to completely stop the Strategy Analyzer if any of the runs fail (are cancelled due to an error)?
      Or, if not that, maybe popup an error window (like it does when trying to set a long stop order above the current price for example)?

      And something else I noticed... if I click "Abort" in the Strategy Analyzer, all of the running strategies still keep running (I can see messages continuing to be written to the Output Window) until the last day selected is finally complete. So I can't start a new run for sometimes 10, 20, or even 30 minutes.

      Thanks

      Comment


        #4
        Originally posted by GregX999 View Post
        Doh!! I figured it out.
        If I was optimizing with more than three values/combinations of values (ie: 0.5;3;0.5 ... so from 0.5 to 3, stepping 0.5 - thus 6 values) then all but three of the runs would error (and stop) because they were all trying to write to the same text file (w/ StreamWriter). I had a bug in my logic that was detecting when to write log files (my intent was to not write log files when running in the strategy analyzer).

        When I tried changing "0.5;3;0.5" to "1,3,1", then it worked fine, as that's just three runs, and all three runs were all able to write to the same text file (for some reason).

        So, I thought "hmmm... maybe something to do with non-integer values", and then found that old post.

        But, fixing my bug so it's not writing to any text files while in the Strategy Analyzer fixed the issue.

        Sorry for the false alarm.

        But... now for an actual request...
        I wasn't seeing the errors about "unable to write to text file" because my output log was getting truncated as I'm also outputting a lot of debug messages to the output windows.

        Can there be an option (or make it default behavior) to completely stop the Strategy Analyzer if any of the runs fail (are cancelled due to an error)?
        Or, if not that, maybe popup an error window (like it does when trying to set a long stop order above the current price for example)?

        And something else I noticed... if I click "Abort" in the Strategy Analyzer, all of the running strategies still keep running (I can see messages continuing to be written to the Output Window) until the last day selected is finally complete. So I can't start a new run for sometimes 10, 20, or even 30 minutes.

        Thanks
        You could potentially trap the error in a try-catch block with that particular message and then call CloseStrateg() to disable the strategy if that error is thrown:Try-catch blocks can be helpful tools but they can also make debugging difficult if used too liberally. There are certain use cases where they make sense to catch and resolve run-time errors, such as the StreamWriter error you are referring to. In other scenarios, preventing the behavior resulting in an error is often far more valuable than just catching the error.

        The "Abort" button will stop the Strategy Analyzer from starting any further iterations, though it does not terminate any currently running iterations of the strategy in an optimization. The behavior you have described is expected.

        Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X