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

Optimize with bools? Here's how!

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

    Optimize with bools? Here's how!

    I really needed to run the Optimizer and be able to test bools. In other words, optimize with the bool variable false and then try it with true. Currently, this is not supported in NT7.

    Here's the simple method I worked out to make this easy:

    1. Declare bools as normal in NinjaScript. Use them as normal. Too easy!

    private bool MyFavouritebool = false ; // Just a normal bool

    2. In the Properties region, declare bools as follows:

    // Pseudo-bool -- 0 is false, 1 is true.
    public int _MyFavouritebool
    {
    get { return MyFavouritebool ? 1 : 0 ; }
    set { MyFavouritebool = value % 2 == 1 ? true : false ; }
    }

    3. Set the parameter value to 0 for false and 1 for true. This makes optimization with bools simple. To leave the bool as false, use 0;0;1. To leave it as true, use 1;1;1. To optimize using the bool as false, then true, use 0;1;1.

    I hope you find this useful.

    Cheers.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    jeronymite

    Thank you for sharing your work in this area!
    MatthewNinjaTrader Product Management

    Comment


      #3
      I'm trying to implement this code. Since adding it, I'm getting the following errors when I compile:

      9/18/2012 10:06:06 PM Default Strategy 'NinjaTrader.Strategy.TrendlineBreakOutDT' could not be deserialized: There is an error in XML document (1, 6787).

      9/18/2012 10:06:07 PM Strategy Error on getting/setting property 'MacdExit' for strategy 'TrendlineBreakOutDT/8bacaef5f437438d95661270b6885a6c': Object of type 'System.Boolean' cannot be converted to type 'System.Int32'.

      Any ideas?

      Despite these errors, the code does appear to work correctly, but it bothers me that it doesn't compile cleanly.

      Thanks!

      Comment


        #4
        Hi Style,

        Glad you find the code useful.

        I too have experienced de-serialization issues, but they were not specifically caused by the pseudo-boolean construct. I found the issue when I tried to rename a strategy.

        In any case, the approach I took to overcome the issue was to create a completely new strategy using the Strategy Wizard that was empty of any content -- essentially a shell strategy. I then copied and pasted my source code into the new strategy and saved/recompiled. No more de-serialization errors since, and I use the pseudo-boolean construct all the time. Try this and see how you go. If you still see the errors, I would suggest it is not the pseudo-boolean construct and you may need to look elsewhere for the source of the issue. Perhaps the NT support folks may have some insights on this?

        Cheers.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment


          #5
          Style

          Can you please post the exact region properties section of the code you are using?
          MatthewNinjaTrader Product Management

          Comment


            #6
            Originally posted by jeronymite View Post
            Hi Style,the approach I took to overcome the issue was to create a completely new strategy using the Strategy Wizard that was empty of any content -- essentially a shell strategy. I then copied and pasted my source code into the new strategy and saved/recompiled.
            That did the trick. Weird. Thanks!

            Originally posted by NinjaTrader_Matthew View Post
            please post the exact region properties section of the code you are using?
            #region Properties

            [Description("")]
            [GridCategory("Parameters")]
            public int StartTime
            {
            get { return startTime; }
            set { startTime = Math.Max(1, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int EndTime
            {
            get { return endTime; }
            set { endTime = Math.Max(1, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int ThreeBarExit
            {
            get { return threeBarExit ? 1 : 0 ; }
            set { threeBarExit = value % 2 == 1 ? true : false ; }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int MacdExit
            {
            get { return macdExit ? 1 : 0 ; }
            set { macdExit = value % 2 == 1 ? true : false ; }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public bool StaticStop
            {
            get { return staticStop; }
            set { staticStop = value; }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public bool StaticTarget
            {
            get { return staticTarget; }
            set { staticTarget = value; }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public bool StaticEntry
            {
            get { return staticEntry; }
            set { staticEntry = value; }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public bool SineExit
            {
            get { return sineExit; }
            set { sineExit = value; }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int FasterTimeFrame
            {
            get { return fasterTimeFrame; }
            set { fasterTimeFrame = Math.Max(10, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int MacdSineTimeFrame
            {
            get { return macdSineTimeFrame; }
            set { macdSineTimeFrame = Math.Max(10, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int Strength
            {
            get { return strength; }
            set { strength = Math.Max(1, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public double Ratio
            {
            get { return ratio; }
            set { ratio = Math.Max(1, value); }
            }
            #endregion

            Comment


              #7
              The next time this occurs, rather than recreating the strategy, can you please try resetting the database to see if this resolve the issue? You can do this by going to Tools--> Options--> Data tab--> select "Reset DB".
              MatthewNinjaTrader Product Management

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rocketman7, Today, 01:00 AM
              0 responses
              1 view
              0 likes
              Last Post rocketman7  
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 04-23-2024, 09:53 PM
              2 responses
              74 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              193 views
              0 likes
              Last Post Hasadafa  
              Working...
              X