Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Printing results after each optimization run

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

    Printing results after each optimization run

    Hello,

    I'm trying to write some information to a file each time an optimization iteration is run in Strategy Analyzer. For example, let's say I have a strategy with 1 parameter Param_A that I want to optimize. When I run an optimization with Param_A set from 30 to 150 in increments of 10, I want to write to a file each time the strategy is finished, so I can see certain results of each iteration. I should have 13 lines of data in this particular test. However, I'm seeing unexpected behavior in that all of the parameter values are not hitting the file write code.

    I have pared this down to as minimum of code as I can to demonstrate this. I have commented out most of my actual strategy code, including the file write process, and just left a Print statement to show the strange behavior. In my strategy, I am using the following code:

    Code:
    else if (State == State.Terminated) { Print("Terminated using params " + DisplayParameters); }
    When I run this using the values I stated above (30 to 150 in increments of 10) I see this Output:
    Code:
    Terminated using params 150 (SmaPeriod)
    Terminated using params 40 (SmaPeriod)
    Terminated using params 50 (SmaPeriod)
    Terminated using params 60 (SmaPeriod)
    Terminated using params 70 (SmaPeriod)
    Terminated using params 80 (SmaPeriod)
    Terminated using params 90 (SmaPeriod)
    Terminated using params 100 (SmaPeriod)
    Terminated using params 110 (SmaPeriod)
    Terminated using params 120 (SmaPeriod)
    Terminated using params 130 (SmaPeriod)
    Terminated using params 140 (SmaPeriod)
    Terminated using params 60 (SmaPeriod)
    Terminated using params 80 (SmaPeriod)
    Terminated using params 60 (SmaPeriod)
    Terminated using params 80 (SmaPeriod)
    Terminated using params 10 (SmaPeriod)
    10 is the default value (set in State.SetDefaults) so that's fine. However, you can see 60 and 80 displayed 3 times each, and 30 is nowhere to be found. If I run this several times, I see slight differences in which ones are repeated, but I never see 30. If I click on the specific result in Strategy Analyzer results that uses the param value of 30, then I do see it appear in the Output window:

    Code:
    Terminated using params 30 (SmaPeriod)
    Terminated using params 10 (SmaPeriod)
    That looks like it used SetDefaults again but then ran the value of 30. It's weird though because in the actual strategy results window, it does display the results for the 30 param (otherwise I couldn't click on it as described above).

    Can anyone help shed light on this behavior or if I'm doing something wrong?

    Thank you!
    Paul

    #2
    Hello pdennis,

    May I test the test script on my end?

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Once exported, please attach the file as an attachment to your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea,

      This is now even stranger . I was testing again last night with the same strategy writing to files and it consistently wrote every value, from 30 to 150. I cannot get it to replicate what it was doing. I had tried restarting NinjaTrader 8 at the time but I believe my laptop may have fully rebooted since it was not writing all values. I didn't think to reboot my entire machine, but whatever the reason it seems to be working as expected now.

      Could you please verify that I am at least doing this the correct way and that it would be expected to write all parameter values in this way? Specifically, using the State.Terminated block in conjunction with the lock(obj) approach to write trade performance for optimization runs.

      Thank you!

      Comment


        #4
        Hello pdennis,

        Yes, printing these in State.DataLoaded or State.Terminated should give you the actual values used for that iteration.

        I want to test on my end, because what you have described seems unlikely.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DeskTroll, Today, 12:09 PM
        3 responses
        22 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Pabulon, 12-02-2024, 03:42 PM
        14 responses
        90 views
        0 likes
        Last Post Pabulon
        by Pabulon
         
        Started by tfa2806trader, Today, 12:04 PM
        10 responses
        25 views
        0 likes
        Last Post tfa2806trader  
        Started by trdninstyle, 11-26-2024, 12:23 PM
        62 responses
        186 views
        0 likes
        Last Post trdninstyle  
        Started by lorien, 08-08-2021, 07:33 AM
        12 responses
        721 views
        0 likes
        Last Post AndyM871  
        Working...
        X