Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Size Algorithm

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

    Position Size Algorithm

    This is the NT default sample crossover strategy with a simple Position Size algorithm, I use 2 type of Position Size, Fix percent and Kelly, please comment on it, remember be kind it’s free.

    Maybe we can add some more Position Size method. If any want to jump in and help is welcome.

    Possible enhancements: made the Position Algorithm a function to be call from any strategy. Add some scaling feature, etc.
    Attached Files

    #2
    Thanks for the contribution PrTester!
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Problem using MACrossWMonMan

      Originally posted by PrTester View Post
      This is the NT default sample crossover strategy with a simple Position Size algorithm, I use 2 type of Position Size, Fix percent and Kelly, please comment on it, remember be kind it’s free.

      Maybe we can add some more Position Size method. If any want to jump in and help is welcome.

      Possible enhancements: made the Position Algorithm a function to be call from any strategy. Add some scaling feature, etc.
      Many thanks to PrTester for this very useful sample strategy code. The NT world is pretty much clueless about standard money management features in other widely used trade automation software (e.g. MT4), so this is an important contribution. I hope this will be addressed in NT7.

      Unfortunately, when I made some small modifications in your code to accomodate forex contracts, I got the following error message for line 20 when I attempted to compile: "The namespace '<global namespace>' contains a definition for "MMType'".

      I'm trying to modify the default lotsize from 1 to 10,000 to represent a minilot size in a standard forex account in Strategy Tester. Can anyone suggest the correct code modifications. I think this would benefit a lot of people.

      Thanks,
      John
      Last edited by raintree; 08-05-2009, 04:47 AM.

      Comment


        #4
        Originally posted by raintree View Post
        Many thanks to PrTester for this very useful sample strategy code. The NT world is pretty much clueless about standard money management features in other widely used trade automation software (e.g. MT4), so this is an important contribution. I hope this will be addressed in NT7.

        Unfortunately, when I made some small modifications in your code to accomodate forex contracts, I got the following error message for line 20 when I attempted to compile: "The namespace '<global namespace>' contains a definition for "MMType'".

        I'm trying to modify the default lotsize from 1 to 10,000 to represent a minilot size in a standard forex account in Strategy Tester. Can anyone suggest the correct code modifications. I think this would benefit a lot of people.

        Thanks,
        John
        Post your code to take a look

        Comment


          #5
          Thanks, here's the file. That compile error I reported only appears if I first try to save the modified strategy under a new name before compliling. If I don't try to save it under a new name, it compiles correctly.

          However, when I run your original strategy in Strategy Tester it never seems to change the lot size, no matter what is happening to the account balance. It could be as simple as needing a more successful strategy than the simple SMA cross sample to run the account balance up higher before it will change the lotsize. I do have one, of course, but one thing at a time: I wanted to test the forex lot size changes before changing anything else.

          Does the lot size change if this position sizing algorithm is used on other instruments with other strategies?

          Thanks for any help you can give.
          Attached Files

          Comment


            #6
            Originally posted by raintree View Post
            Thanks, here's the file. That compile error I reported only appears if I first try to save the modified strategy under a new name before compliling. If I don't try to save it under a new name, it compiles correctly.

            However, when I run your original strategy in Strategy Tester it never seems to change the lot size, no matter what is happening to the account balance. It could be as simple as needing a more successful strategy than the simple SMA cross sample to run the account balance up higher before it will change the lotsize. I do have one, of course, but one thing at a time: I wanted to test the forex lot size changes before changing anything else.

            Does the lot size change if this position sizing algorithm is used on other instruments with other strategies?

            Thanks for any help you can give.

            Comment this in your strategy

            public enum MMType
            {
            Fix_Percent,
            Kelly_F

            }

            IT CAN BE ONLY ONE, like the movie

            Probably need more than 3 month of data to change the position size.

            Comment


              #7
              Originally posted by PrTester View Post
              Comment this in your strategy

              public enum MMType
              {
              Fix_Percent,
              Kelly_F

              }

              IT CAN BE ONLY ONE, like the movie

              Probably need more than 3 month of data to change the position size.
              Ok, I'll add that to my list of suspicions. When it comes to Ninjascript, I don't have any hard knowledge, only suspicions. Thanks for the tip.

              Comment


                #8
                Thanks for this - good code to learn from.

                Comment


                  #9
                  Thanks for the code PRtester.

                  Looking forward to further contributions. I can contribute by testing in exchange for your generous posts.

                  Thanks again!

                  Comment


                    #10
                    PrTester - Thank you for the post. I think your solution is a sensible work around to the account size problem. However I am struggling to make some modifications to your strategy. Ninja is giving me the following error

                    **NT** Error on calling 'OnExecution' method for strategy 'DC1/24727490b1624fa4877b2ef3ad9108c9': Object reference not set to an instance of an object.

                    I am using OnExecution with the position entry

                    entryOrder=EnterLong((int)Psize, "long1");

                    Do you think this is causing the problem? If not I can post the full code. Thank you

                    Comment


                      #11
                      titleistbb22, do you have a check in place for the IOrder you attempt accessing not being null?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks for the quick response - I do have a ck for that. Below is my code to start the OnExecution method. My strategy worked as expected until I layered in the position sizing.

                        protected override void OnExecution(IExecution execution)
                        {
                        if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                        {
                        //checks that the Trade was filled or Patially filled
                        if ((execution.Order.OrderState == OrderState.Filled ||execution.Order.OrderState == OrderState.PartFilled ))

                        Also, I have the below code under my user variables

                        private IOrder entryOrder = null; // holds our entry order.

                        Comment


                          #13
                          Originally posted by titleistbb22 View Post
                          I am using OnExecution with the position entry

                          entryOrder=EnterLong((int)Psize, "long1");

                          Do you think this is causing the problem? If not I can post the full code. Thank you
                          I'm not an expert, but isn't there an error in this line? What are you trying to achieve with "(int)Psize" Titleistbb22?

                          It looks to me like some form of casting ( http://msdn.microsoft.com/en-us/libr...05(VS.80).aspx ), which seems out of place here.

                          Or are you trying to initialize an int-variable? Perhaps that can better be achieved through:
                          Code:
                          [FONT=Courier New]int Psize = 1000;[/FONT]
                          [FONT=Courier New]entryOrder=EnterLong([/FONT][COLOR=#282828][FONT=Courier New]Psize, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"long1"[/FONT][/COLOR][COLOR=#282828][FONT=Courier New]);[/FONT][/COLOR]
                          Regards & success,

                          Comment


                            #14
                            Thank you - I'll give that a shot - I was duplicating PrTester's code for position sizing, however I'm using IOrder to capture the price entry to drive the stops, unrealted to position size.

                            Ck out the code attached to the first post on this thread.

                            Thanks

                            Comment


                              #15
                              Jos - tested that line of code you suggested, I can not convert double to int without (int). Ninja tosses an error message

                              Open to other suggestions

                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              23 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X