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

Generate Random Value

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

    Generate Random Value

    Hello,

    Essentially i'm trying to create a 'Monte Carlo' type simulation using NinjaScript and Optimization in Strategy Analyzer. I've written a simple SMA strategy and when I run it in Optimization it seems to work, except that the results that show up for each iteration aren't what they actually are. In other words, the data in the 'list' of all iterations is wrong. If you click on one particular line it doesn't show the same information as it does in the Summary section. I've attached a screenshot of this and also a copy of the strategy.

    I suspect the reason it's broken is because of the way i've coded the Random class. I think i've overly complicated it, and perhaps placed code in the wrong spot. What i'm trying to do is run a number of iterations for a strategy (refer the property Iterations). For each Iteration I want the strategy to chose random values for both the Fast and Slow SMA, and I want the strategy to keep those values for the whole Time Frame (not change them after every trade). So after running the strategy in Optimization with Iteration set to 10 for example I should get 10 different sets of parameters for both Fast and Slow SMA.

    I couldn't work out how to generate random values outside of OnBarUpdate. Is there a better way to code this and get the performance results to show correctly in Strategy Analyzer?
    Attached Files

    #2
    Hello,

    May I confirm you have enabled the Monte Carlo simulation?

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, but it doesn't do what I'm trying to accomplish. I want random parameter sets to be chosen for every iteration. Thanks

      Comment


        #4
        Hi kabes223,

        What is the Optimization fitness being used?

        What is the Optimizer being used?

        What version of NinjaTrader are you using? (Help -> About...)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea

          That Optimization info is in the screenshot I attached in my original post, or are you referring to something else? The Optimization fitness doesn't work for Net Profit either (if that's what you mean).

          NT version i'm using is 8.0.5.2. I also tried it on older version 8.0.4, same issue.

          Thanks

          Comment


            #6
            Hello kabes223,

            Attached is a screenshot of the Strategy Analyzer with the Optimize on (optimization fitness) and Optimizer highlighted.

            As a heads up, in your script you randomize a few numbers and this is changing the results each time i run a backtest.
            Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the video Chelsea.

              The strategy works fine when you run it the way you did. My issue is when you run it over a range of parameters in Optimization, the list of each iteration's performance is wrong. See my original post and it's attached screenshot. If you click any iteration line up the top, the performance info that displays in the summary below doesn't match. The info in the summary is correct, the info in the list is wrong. So maybe that's an issue with the software then? If not then it must be the way i've coded the random function.

              Comment


                #8
                Sorry, when I said "My issue is when you run it over a range of parameters in Optimization". I meant when you run it with a range of the 'Iterations' parameter. Cheers.

                Comment


                  #9
                  Hello kabes223,

                  Thanks for steering me in the right direction.

                  I was able to reproduce the behavior and I have reported the behavior to our development.

                  Once I have more information I will post in this thread.
                  I appreciate your patience.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello kabes223,

                    Thank you for your patience.

                    As the values for the Period of the SMAs are not NinjaScript Properties they are not optimized in any way. This also means that as the Periods are Random Ints it will never be the same run for each iteration. The behavior you are seeing is expected in the context that what you are doing would not work for the Optimization/Strategy Analyzer results and would skew those results.

                    Please let me know if you have any questions.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by RookieTrader, Today, 07:41 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post RookieTrader  
                    Started by kujista, Today, 05:44 AM
                    2 responses
                    12 views
                    0 likes
                    Last Post kujista
                    by kujista
                     
                    Started by trilliantrader, Today, 08:16 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post trilliantrader  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    9 responses
                    175 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by funk10101, Today, 08:14 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post funk10101  
                    Working...
                    X