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

Enum Values in Optimization Graph?

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

    Enum Values in Optimization Graph?

    Hi,
    I'm playing around with a strategy using (amongst other things) public enums as entry and exit conditions.
    The strategy itself works like a charm including optimization.
    However, when looking at the optimization graph, I don't have access to such enum values as Parameter 1 or 2.
    Any idea how to overcome this limitation (still using a narrative description of the condition in the Strategy Analyzer as shown below?

    Public enums added to my strategy include for example:
    public enum LongEntryStep : int { SQH3 = 0, SQH2 = 1, SQH = 2, PRC = 3 }

    Thx.
    NT-Roland



    #2
    I replicated your scenario (see Strategy code below).

    First, I observed the same thing you did, that the enum parameter is not available in the optimization graph. Enum parameters are not selectable in the drop downs.

    In theory, this could be done I think, but it looks like NT has chosen not to for now at least. There would be some added complications to using the integer values, then grabbing their corresponding enum names when drawing the axis labels.

    It's a bit of a hack, but you can get around this issue by adding an additional parameter which just returns the integer value of the enum parameter.

    Then you can select that integer paramter in the optimization graph. You'll have to translate in your head the plotted integer values back to their corresponding enumeration values.

    One note, NT told me a few times in the optimization graph that I didn't have enough data points to chart anything. But once I added the additional Multiplier parameter and ran with a few more iterations, it was happy.

    See the code for more details.

    Good luck!

    Steve

    UPDATE: The following code doesn't actually solve the problem. Keep reading.

    Code:
    using System;
    using NinjaTrader.Cbi;
    using System.ComponentModel.DataAnnotations;
    
    //This namespace holds strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies.Forum
    {
        public enum LongEntryStep : int { SQH3 = 0, SQH2 = 1, SQH = 2, PRC = 3 }
    
        public class Forum_EnumOptimization : Strategy
        {
    
            [NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Long Entry Step")]
            public LongEntryStep EntryStep { get; set; }
    
            [NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Step Multiplier")]
            public int Multiplier { get; set; }
    
            [NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Long Entry Step (int)")]
            public int EntryStepInt
            {
                get { return (int)EntryStep; }
                set { }
            }
    
            protected override void OnBarUpdate()
            {
                if (Position.MarketPosition == MarketPosition.Flat)
                {
                    EnterLong();
                }
                else
                {
                    int age = BarsSinceEntryExecution();
                    switch (EntryStep)
                    {
                        case LongEntryStep.PRC:
                            if (age >= 1 * Multiplier) { ExitLong(); }
                            break;
                        case LongEntryStep.SQH:
                            if (age >= 2 * Multiplier) { ExitLong(); }
                            break;
                        case LongEntryStep.SQH2:
                            if (age >= 3 * Multiplier) { ExitLong(); }
                            break;
                        case LongEntryStep.SQH3:
                            if (age >= 4 * Multiplier) { ExitLong(); }
                            break;
                    }
                }
            }
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "Forum - Enum Optimization";
                    BarsRequiredToTrade = 20;
                    EntryStep = LongEntryStep.SQH3;
                    Multiplier = 1;
                }
            }
    
    
    
        }
    }
    Last edited by Steve L; 10-13-2019, 09:03 AM. Reason: NOTE: This approach doesn't actually work.
    Steve L
    NinjaTrader Ecosystem Vendor - Ninja Mastery

    Comment


      #3
      Hi Steve,
      Thanks for your reply. Greatly appreciated.The code snipplet allows to display enums as ints in the Optimization graph. However, it appears as this approach implies duplication of all enums. They show up both as narrative enum (as intended) and as (int) enum (not intended) in Strategy Analyzer. NT considers them as separate inputs on Optimization which results in exploding iterations. Any idea how to hide the (int) enums from the analyzer yet still access the (int) enums in the Optimization graph? I couldn't (yet) figure this out, but consider diplay of ALL optimizing parameters in the Optimization graph as "must have".
      NT-Roland
      Enum Optimization Graph_Narrative AND Int_Must avoid.pdf

      Comment


        #4
        Hi NT-Roland,

        Couple of things:

        1)

        In my version of NT8, it allows me to not set the values of the int parameter in the optimization. They remain as

        Min=0
        Max=0
        Increment = 1

        ...even after I select all 4 checkboxes in the Long Entry Step enum parameter.

        Be sure your code for the int parameter is exactly the same as mine. Specifically, what do the getter and setter look like?

        2)

        However, this isn't a help, really, because then the int parameter, while it shows up in the optimization, always has a value of 0.

        So, you're correct, my approach doesn't actually work.


        ---

        So yes, support for enum parameters in the optimization graph will probably need to be submitted as a feature request unless someone else knows something we don't.

        ---

        For now, your best approach is probably to use the int parameter as a full fledged parameter and make the enum parameter readonly for your strategy's internal use.

        I've made this update.

        Code:
        using System;
        using NinjaTrader.Cbi;
        using System.ComponentModel.DataAnnotations;
        
        //This namespace holds strategies in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies.Forum
        {
            public enum LongEntryStep : int { SQH3 = 0, SQH2 = 1, SQH = 2, PRC = 3 }
        
            public class Forum_EnumOptimization : Strategy
            {
        
                [Display(Name = "Long Entry Step")]
                public LongEntryStep EntryStep { get { return (LongEntryStep)EntryStepInt; } }
        
                [NinjaScriptProperty]
                [Display(Name = "Step Multiplier")]
                public int Multiplier { get; set; }
        
                [NinjaScriptProperty]
                [Range(0, 3)]
                [Display(Name = "Long Entry Step (int)")]
                public int EntryStepInt { get; set; }
        
                protected override void OnBarUpdate()
                {
                    if (CurrentBar < BarsRequiredToTrade) { return; }
        
                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                        EnterLong();
                    }
                    else
                    {
                        int age = BarsSinceEntryExecution();
                        switch (EntryStep)
                        {
                            case LongEntryStep.PRC:
                                if (age >= 1 * Multiplier) { ExitLong(); }
                                break;
                            case LongEntryStep.SQH:
                                if (age >= 2 * Multiplier) { ExitLong(); }
                                break;
                            case LongEntryStep.SQH2:
                                if (age >= 3 * Multiplier) { ExitLong(); }
                                break;
                            case LongEntryStep.SQH3:
                                if (age >= 4 * Multiplier) { ExitLong(); }
                                break;
                        }
                    }
                }
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Name = "Forum - Enum Optimization";
                        BarsRequiredToTrade = 20;
                        EntryStepInt = (int)LongEntryStep.SQH3;
                        Multiplier = 1;
                    }
                }
        
        
        
            }
        }



        Click image for larger version  Name:	Capture.PNG Views:	0 Size:	168.9 KB ID:	1074233
        Last edited by Steve L; 10-13-2019, 08:57 AM.
        Steve L
        NinjaTrader Ecosystem Vendor - Ninja Mastery

        Comment


          #5
          Hi Steve,
          Thanks again for your support on this. You rock.
          I went back to ints. Not nice, since (1,2,3,4) is much more difficult for OTHER users to understand than for example (SQH3, SQH2, SQH, PRC), particularly, if you have several of similar ints, which should be enums, in a strategy, but what else can we do?
          I consider using ints instead of enums a dirty fix.
          What is the purpose of enums in optimization if you can't systematically evaluate the results of ALL parameters?
          Can NT please take this up?
          NT-Roland

          Comment


            #6
            Hello NT-Roland, thanks for your post.

            Right now the optimizer will not iterate through any enums. I will submit this as a feature request and report back with a feature tracking ID.

            Please let me know if I can assist further.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,
              That's great news. Perhaps this request can be added to my other one here, for which a tracking ID was already kindly provided?
              Hi, It is possible to optimize data series in Strategy Analyzer by checking &quot;Optimize Data Series&quot;, specifying Min. and Max. Value of the Data Series

              Slightly different focus (narrative enums here, specific enum (ints) only there), but overall the same topic. Would be a big step in the right direction from my pov.
              Thanks for considering.
              NT-Roland

              Comment


                #8
                Hi NT-Roland, yes there is already a ticket for this request. Refer to that feature ID upon future releases in the release notes to track the feature.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                1 view
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                238 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                383 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Started by oviejo, Today, 12:28 AM
                0 responses
                1 view
                0 likes
                Last Post oviejo
                by oviejo
                 
                Started by pechtri, 06-22-2023, 02:31 AM
                10 responses
                125 views
                0 likes
                Last Post Leeroy_Jenkins  
                Working...
                X