• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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?

    http://ninjatrader.com/support/helpG...arloSimulation
    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.
            https://www.screencast.com/t/bXUZkEcWAh
            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.
                    Patrick H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Jschmelz, Today, 01:13 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_EricB  
                    Started by Newtrader101, Today, 12:37 PM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_EricB  
                    Started by Robert87, Yesterday, 11:07 AM
                    1 response
                    24 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by U0000999, Today, 12:20 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_EricB  
                    Started by im197, Today, 02:54 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X