• 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

Optimizing bool/enum/TimeSpan parameters

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

    Optimizing bool/enum/TimeSpan parameters

    Here is a little class to help anyone who wants to optimize properties in their strategies that are booleans, enums, or TimeSpans.

    Since NT only supports optimizing on integer and double parameters, all your optimizable parameters need to be of these types. The attached OptimizableProperty<T> class implements a generic property that can be treated as both an integer for exposing to NT optimization and a more natural type for the internals of your strategy. Currently it supports bool, enums, and TimeSpan types.

    To create one, simply specify the type of property you desire in the angle brackets. E.g.:

    public enum MovingAverageType { Simple, Exponential };

    OptimizableProperty<MovingAverageType> maType = MovingAverageType.Simple;

    OptimizableProperty<bool> fade = true;

    You can then treat the property either as an integer or whatever type you specified in the angle brackets:

    if (fade) {
    ...
    }


    if (maType == MovingAverageType.Exponential) {
    ...
    }


    ...


    public int Fade {
    get { return fade; }
    set { fade = value; }
    }


    public int MAType {
    get { return maType; }
    set { maType = value; }
    }

    Calling OptimizableProperty<T>.ToString() will return the natural string value of the property (e.g. 'true' or 'false' for OptimizableProperty<bool>).

    The integer values for an OptimizableProperty<bool> are 0 (false) or 1 (true) while for an enum they range from 0 (the first enum value) to n-1 (the last value) where n is the number of values in the enum. For OptimizableProperty<TimeSpan> it is the number of minutes since midnight (the seconds portion is ignored).

    Note that in some cases you will need to explicitly cast the OptimizableProperty<T> to either int or bool/enum/TimeSpan if the compiler is unable to automatically determine which type you want.

    To install, copy the attached file to My Documents\NinjaTrader 6.5\bin\Custom\Type and compile a strategy once.
    Attached Files

    #2
    Thanks for sharing this -Swig-!
    BertrandNinjaTrader Customer Service

    Comment


      #3
      This is an interesting workaround. I assume you have to then do data entry in the optimizer parameters dialog as an int, though, correct? You don't get the dropdown you get for enum parameters now?

      Comment


        #4
        Originally posted by Anagoge View Post
        This is an interesting workaround. I assume you have to then do data entry in the optimizer parameters dialog as an int, though, correct? You don't get the dropdown you get for enum parameters now?
        Yes, nope, respectively. Unfortunately the parameters have to be exposed to NT as int or double or else it won't allow optimisation on them.

        The main reason I put this together was so that NT's limitation to optimising doubles/ints wouldn't prevent use of more natural data types (i.e. bool/enum/TimeSpan) resulting in cleaner strategy code.

        All it really does is hide the boilerplate int <-> bool/enum/TimeSpan conversion code that would otherwise be needed.


        -Swig-

        Comment


          #5
          this is great. lets hope that NT7 allows one to set enum/timespan/datetime values in the optimization dialog...

          Comment


            #6
            Is the above still the best way to optimize on non-integer, non-double values?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by vevbarrq, Today, 12:11 AM
            0 responses
            2 views
            0 likes
            Last Post vevbarrq  
            Started by johnnybegoode, Yesterday, 10:16 PM
            0 responses
            4 views
            0 likes
            Last Post johnnybegoode  
            Started by reedstickets, Yesterday, 07:53 PM
            0 responses
            9 views
            0 likes
            Last Post reedstickets  
            Started by Atilla, Yesterday, 04:05 PM
            0 responses
            31 views
            0 likes
            Last Post Atilla
            by Atilla
             
            Started by Displacer, Yesterday, 02:57 PM
            2 responses
            17 views
            0 likes
            Last Post Displacer  
            Working...
            X