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

    For the last bunch of releases, I have had a problem with NT8's optimization and it has to do with booleans. I'm using a base class that I've coded as a session manager, which will be applied to any strategy that inherits from it. There are four sessions, each controlling separate profit targets, stop losses, max/min gains, start and stop times and whether or not you want to close the trade at the designated stop time.

    1. The problem is the boolean that describes whether you want to close your current trade, if you have one, when the session ends as opposed to letting it run after the current session ends. I want to be able to optimize that boolean. They show up in backtesting, but don't show up in optimization. Well, one of the four does in the first session but does not show up in the other three. In the screen shots, I show those bools in the Strategy Analzyer (backtester) but three of them disappear in the other three sessions when you switch to the optimizer.

    2. The one that does show up, is getting optimized whether I want it to or not. In the midnight session, I'm probably going to have that bool set to false so I don't really want to optimize that. But the day session, I will want to optimize it. This is a midnight setting optimization and I've set it to false. As you can see in the screenshots, the optimizer doesn't care what I've set it to - it optimized it anyway.

    3. The third issue probably goes without saying because it has to do with a memory leak that multiple people have mentioned for the last several releases. I took note of how much memory was currently being used and it went up by 400 MB after it was done. It's still up by 400 MB three hours later. I'm going to want to run up to six of these at a time like I do with NT 7 and when I do, I'll have to restart NT after each one since the effect of the memory leak is cumulative. I'm not so much concerned with this one as the first two because at least I can still optimize, even if I have to restart Ninja every so often. But I can't really optimize the booleans that I can't see.

    Here's my properties code. I'm fairly certain there's nothing wrong with how I'm declaring these properties but here it is anyway since you never know. (It's for all of Session 4, Session 1 is exactly like Session 4 except in the method names there is a '1' instead of a '4', e.g. "ProfitTarget1" instead of "ProfitTarget4". Same for the other sessions:
    Code:
    		#region Session 4
    		[Display(Name="Use Session 4?", Description="Use session 4", Order=1, GroupName="Session 4")]
    		public bool UseSession4
    		{ get; set; }
    
    		[Range(1, int.MaxValue)]
    		[NinjaScriptProperty]
    		[Display(Name="Session  start", Description="Session 4 start time", Order=2, GroupName="Session 4")]
    		public int Session4Start
    		{ get; set; }
    
    		[Range(1, int.MaxValue)]
    		[NinjaScriptProperty]
    		[Display(Name="Session end", Description="Session 4 end time.", Order=3, GroupName="Session 4")]
    		public int Session4End
    		{ get; set; }
    
    		[Range(1, int.MaxValue)]
    		[NinjaScriptProperty]
    		[Display(Name="Profit target", Description="Sets the profit target (in ticks) for Session 4", Order=4, GroupName="Session 4")]
    		public int ProfitTarget4
    		{ get; set; }
    
    		[Range(1, int.MaxValue)]
    		[NinjaScriptProperty]
    		[Display(Name="Stop loss", Description="Stop loss (ticks). If zero, no stop loss is implied.", Order=5, GroupName="Session 4")]
    		public int StopLoss4
    		{ get; set; }
    
    		[Range(1, double.MaxValue)]
    		[NinjaScriptProperty]
    		[Display(Name="Max gain", Description="Sets the max gain for Session 4 which, when reached will halt trading.", Order=6, GroupName="Session 4")]
    		public double MaxGain4
    		{ get; set; }
    
    		[Range(1, double.MaxValue)]
    		[NinjaScriptProperty]
    		[Display(Name="Max loss", Description="Sets the max loss for Session 4 which, when reached will halt trading.", Order=7, GroupName="Session 4")]
    		public double MaxLoss4
    		{ get; set; }
    
    		[NinjaScriptProperty]
    		[Display(Name="Exit on session close?", Description="Select to exit all trades at the session 4 end time.", Order=8, GroupName="Session 4")]
    		public bool ExitSession4Close
    		{ get; set; }		
    		#endregion
    If nothing else, I'm sure you'll find it odd that Optimization ignores three booleans for seemingly no reason. Maybe you'll even want to figure out why... Or not...
    Attached Files

    #2
    Hello traderpards,

    Thank you for your patience.

    I am reviewing your report on these items and I will follow up when I have any details for you.

    Comment


      #3
      Remove the [NinjaScriptProperty] from the ExitSessionClose bools int he properties region. Then test again in the Strategy Analyzer for an optimization after compiling the changes in the NinjaScript Editor (Right Click > Compile.

      Comment


        #4
        Ok, that works but now they are bools that you can't optimize. What if I wanted to optimize those bools? (I would want to optimize one of them.) It seems to me there is something wrong with the Strategy Analyzer when if properly recognizes one of the booleans and fails to recognize the rest. I like being able to optimize booleans and appreciate the upgrade in NT8.

        Comment


          #5
          Hello traderpards,

          Thank you for your response.

          You should be able to optimize the bools. Can you attach a script that recreates the same behavior to your response?

          Comment


            #6
            Script, as requested

            Sure...

            In the interest of saving time, I was going to make a shell strategy (that didn't work) but would demonstrate the disappearance of the bools. But then I remembered that part of my issue is that if a boolean did show up in optimization mode, it would optimize whether you wanted it to or not so I ended up making a script with sessions that is (almost) fully functional - the trade times, entries and exits all work. Except I didn't feel like implementing the Exit on Session Close functionality because of the crash bug you get with a secondary data series that is currently still outstanding and has been for at least three releases. However, you don't need it hooked up to demonstrate its disappearing act when you switch from Strategy Analyzer mode to Optimization mode.

            This one is like the sample EMA but the extra boolean is whether or not you want to exit based on if the MACD is above/below zero. I wanted to demonstrate random optimization - (it either ignores the boolean parameter not to optimize or it is lying to you when it tells you it did after you didn't want it to) - of that MACD bool but I'll be damned if that one doesn't reproduce.

            So if you want to, you can document the disappearance issue and then if the "random optimization" shows up later we can worry about it then. But with this sample script, that doesn't seem to be a problem. (Glad I have a screen shot to prove it did it in my strategy.)
            Attached Files

            Comment


              #7
              Hello traderpards,

              Thank you for your response.

              For the Exit On Session Close bools you will need to ensure they have different DisplayName.Names. Different properties should not have the same DisplayName.Name. It would be expected that the properties disappear if using the same DisplayName.Name in an Optimization.

              Comment


                #8
                Thank you Patrick for looking at it.

                I tried what you said and that works, but your rationale makes absolutely no sense. First, they are in totally separate groups so naming shouldn't matter - whether or not they are the same names or not. If it did matter, not only would the bools be messed up, but the ints and doubles would matter too. I'm not sure if you noticed but the stop losses, profit targets and all the rest are named the same across groups and they work just fine. (I didn't implement MaxGain/MaxLoss in the sample I gave you but I have such a thing in my own strategy and doubles don't have a problem in the Optimizer. Michael has both my strategies that inherit from SessionManager that he used to reproduce the crash bug if you want to look at those.)

                Second, the Strategy Analyzer doesn't seem to have a problem with the bools being named the same and neither does the chart functionality. Out of everywhere you can name in Ninja land, only the Optimizer has a problem. That suggests a bug in the optimizer and I would look to see what the optimizer is doing differently than the strategy analyzer.

                What you have given is a workaround - thank you for that - but you - we - still have a problem with the bools. This is not, by any means, "expected behavior," no way. If it was, it would be "expected" to disappear in all mediums where they are being used and that is obviously not the case.

                Comment


                  #9
                  Hello traderpards,

                  Thank you for your response.

                  We have added the following to the Help Guide: "The "Name" parameter MUST be unique for each property of a particular object. Sharing the same Name can have undesirable consequences on various features of the property grid."
                  You can find this at the following link: http://ninjatrader.com/support/helpG...yattribute.htm
                  I will submit a request to development to change this behavior as you requested.

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello traderpards,

                    Thank you for your response.

                    We have added the following to the Help Guide: "The "Name" parameter MUST be unique for each property of a particular object. Sharing the same Name can have undesirable consequences on various features of the property grid."
                    You can find this at the following link: http://ninjatrader.com/support/helpG...yattribute.htm
                    I will submit a request to development to change this behavior as you requested.
                    Thank you Patrick...

                    Can you please post the tracking ID of this request when you get it so that I can look for it in subsequent releases?

                    Comment


                      #11
                      traderpards,

                      I will update the thread when I have the id.

                      Comment


                        #12
                        This suggestions has been assigned the id SFT-1611.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by alifarahani, Today, 09:40 AM
                        6 responses
                        36 views
                        0 likes
                        Last Post alifarahani  
                        Started by Waxavi, Today, 02:10 AM
                        1 response
                        17 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by Kaledus, Today, 01:29 PM
                        5 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by Waxavi, Today, 02:00 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by gentlebenthebear, Today, 01:30 AM
                        3 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Working...
                        X