Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimization issues with boolean

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

    Optimization issues with boolean

    I am now able to reproduce the issue where the booleans for optimization completely ignores what you set and optimizes them anyway, or not. There seems to be no rhyme or reason as to whether it optimizes - it seems to flip its own coin and out comes your result, and usually it isn't what you intended.

    This is the same strategy that has the four trading sessions. I have it set to optimize between 5:00 am 7:00 am to 9:30 am to 1:30 pm with various stops and targets. I don't have Exit on Close 2 set because of the crash bug that happens when I want to run a secondary series in the background, which right now you unfortunately can't do so I didn't even implement that.

    But guess what you get?? It blows off Session 2 and optimizes Session 4 instead. You'll note that I have Session 4 set to false which means do not optimize. I don't have it set to true or Optimize. I have it set to false. Not only that, I only want to optimize Mondays, Tuesdays, Wednesdays and Thursdays - those are set to True. Sundays and Fridays are set to False, meaning don't optimize on Fridays and Sundays. It decided I should optimize on Fridays, but not on Mondays, Wednesdays or Thursdays. The screen shots shows you what I'm talking about. The first one shows you that it's optimizing on whatever it wants to and the second one shows you that it's serious about optimizing on whatever it wants to. It decided to optimize on the settings for Session 4 and that's exactly what it did. (As opposed to really optimizing on what you wanted and the results are wrong. Nope - the results are properly reflected in the chart.)

    It seems like a nice idea and I really hope you fix it rather than make it a hard-coded checkbox because in NT7 I have to optimize with each boolean set to true and then do the same thing over again with each boolean set to false. It's much nicer this way, if only it would work.
    Attached Files

    #2
    Hello,

    Thank you for providing this sample, I was able to import the sample and use the settings in the xml provided to see the same result. I will provide this to development for further review.

    I had noted also, the xml was missing the node for the DataSeries likely because you have a custom bar type used. I could not use the template directly as it was causing an exception, can you tell me, was this a Strategy template saved from the analyzer as you have pictured?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Yes, it came from C:\Users\Me\Documents\NinjaTrader 8\templates\Strategy\EMACrossSession and I didn't even think about the bar type. Sorry about that. Since you were able to reproduce it I assume you don't need the bar type? (I was asked not to share my conversion of that. If I would have thought of it, I would have used the NT stock Range bars like I did last time.)

      Comment


        #4
        Hello,

        Thank you for the details. I am actually glad you had used the custom bar type because I would like to test this on my end to see if I can reproduce the template problem.

        I will generate a new bar type and see if I can produce the missing DataSeries node as well. I don't believe I would need the type you had used, but if I do I would likely just ask you to work with me further through email for that as the code should not be public.

        I appreciate the samples, that was very easy to locate with the given information.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          If you need it, I would think there wouldn't be any objection to emailing it to you...
          Thanks Jesse!

          Comment


            #6
            Hello,

            I wanted to post back on this, could you re test on your end using RC2 and ensure this has been resolved?


            I am no longer able to reproduce this using the template and strategy as I was before.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Yes, booleans appear to be fixed. Except now I'm getting a whole slew of these errors, like hundreds of them:

              Indicator 'SMA': Error on calling 'OnBarUpdate' method on bar 2: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

              I remember getting this before and I swear I fixed it but I don't remember what I did. I don't suppose you or anyone can jog my memory. I don't get these when running the strategy normally in a chart window.

              I do have this at the very top of my script so why it's complaining about Bar 2 doesn't make sense to me because bar 2 shouldn't even be relevant. Not only that, if I'm using SMA, I don't know where.
              Code:
              	if( CurrentBars[1] < BarsRequiredToTrade 
              	     || CurrentBars[0] < BarsRequiredToTrade ) return;
              But in the end I get results from the optimization so I'm wondering if the error message is bogus.

              Comment


                #8
                Hello,

                Thank you for testing that and posting this item.

                Can you confirm in the analyzer prior to running the test, is the BarsRequired set to a number greater than 2?

                Based on the output, it would indicate that an SMA is using a BarsAgo greater than the BarsRequired.

                Testing on my end using the following example I have not been able to reproduce the error in a situation that did not warrant it:

                Code:
                protected override void OnStateChange()
                {
                	if (State == State.SetDefaults)
                	{
                		BarsRequiredToTrade	= 20;
                	}
                	else if (State == State.Configure)
                	{
                		AddDataSeries(BarsPeriodType.Minute, 60);
                	}
                }
                
                protected override void OnBarUpdate()
                {
                	if( CurrentBars[1] < BarsRequiredToTrade  || CurrentBars[0] < BarsRequiredToTrade ) return;
                	double sma = SMA(12)[B][2][/B];
                }

                In the case I use the default 20, this did not fail. In the case I had used 0 and 1 this did fail with the same error reporting the bar number in which it failed.

                Can you check the script for the BarsAgo you are using and also the BarsRequired being used to ensure the values are complimenting each other? If they are could you provide the script or a simple test like the above for me to review along with the steps used?

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thanks for looking at this...

                  I guess I forgot to be explicit but I'm only getting those errors in Optimization. Back testing does not generate these errors. BarsRequiredToTrade is left at the default 20.

                  I have heavily commented OnBarUpdate() to the point where the only statement in there is "return;". I still generated all those errors. So I went into OnStateChange() and commented every instance of every indicator I'm using and only then did I not get all those errors. So I backtracked from there and finally figured out that a couple of initializations I was doing in OnStateChange() when State == State.Configure, was causing it.

                  That works just fine when you're running the strategy in a chart or doing backtesting, but for some reason, Optimization wants those initializations done when State == State.DataLoaded.

                  So I moved them and it optimizes like a champ. Who knew?

                  Comment


                    #10
                    Thanks for sharing your findings. Can you be more specific regarding what initializations need to go into the State == State.DataLoaded within OnStateChange() to make the optimizer run correctly under RC2? Also, might you know if this is true for all backtest types in the Strategy Analyzer?.
                    whitmark
                    NinjaTrader Ecosystem Vendor - Whitmark Development

                    Comment


                      #11
                      I don't know what other types of backtest types this applies to, although I would think all of them that use optimization functionality, but I can be more specific.

                      A year ago one of the first indicators I converted was the Trader's Dynamic Index. Here's the declaration and OnStartUp() code for NT7:
                      Code:
                      		private RSI DYNRSI;
                      		private SMA DYNPrice;
                      		private SMA DYNSignal; 
                      		private SMA	DYNAverage; 
                      		private StdDev SDBB;
                      Code:
                      	protected override void OnStartUp()
                      	{
                      		DYNRSI = RSI(Input,RSIPeriod,1);
                      		DYNPrice = SMA(DYNRSI,PricePeriod);
                      		DYNSignal = SMA(DYNRSI,SignalPeriod);
                      		DYNAverage = SMA(DYNRSI, BandPeriod);
                      		SDBB = StdDev(DYNRSI,BandPeriod);
                      	}
                      Well, I had all of that OnStartUp() code in OnStateChange where State == State.Configured because I'm sure that a year ago when I first converted this, I didn't know any better. And since it worked at the time (and since then, really until I went to optimize,) who was I to worry about it? When I moved it to OnStateChange where State == State.OnDataLoaded, the optimization worked.

                      I'm thinking I can conclude that for purposes of conversion, OnStartUp() is analogous to OnStateChange where State == State.DataLoaded and Initialize() is analogous to OnStateChange where State == State.Configured. Perhaps support can correct me if I'm wrong or confirm that.

                      Comment


                        #12
                        That's exactly correct traderpards.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by yertle, Yesterday, 08:38 AM
                        7 responses
                        28 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by bmartz, 03-12-2024, 06:12 AM
                        2 responses
                        20 views
                        0 likes
                        Last Post bmartz
                        by bmartz
                         
                        Started by funk10101, Today, 12:02 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post funk10101  
                        Started by gravdigaz6, Yesterday, 11:40 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by MarianApalaghiei, Yesterday, 10:49 PM
                        3 responses
                        10 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X