Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position Sizing During Backtest

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

    Position Sizing During Backtest

    I know it's not officially supported, but I was told that you could use the Performance class to do position sizing for backtests.

    Check out this code:

    Code:
    if (Demo == true && Realtime == false)
                {            
                    //Print("My account size is: " + (Performance.AllTrades.TradesPerformance.Currency.CumProfit + AccountSize));
                    double myRiskAmount = ((Performance.AllTrades.TradesPerformance.Currency.CumProfit + AccountSize) * (RiskPercentage * .01) / SL);
                    //Print("My risk amount is: " + myRiskAmount);
                    double myPositionSize = (myRiskAmount * 10000);
                    //Print("My test position size is: " + myPositionSize);
                    int PositionSize = (int)myPositionSize;
                    //Print("My final position size is: " + PositionSize);
                }
    All of those print statements was me testing my code. Basically, the final position size shows the correct position size -- let's say, for example, 11980 units.

    Then this is my entry code:

    Code:
    if (Close[0] > Close[1])
    {
       EnterLong(PositionSize);
    }
    But it still enters whatever is specified in the parameters... I don't understand that... I mean, it's in the code... it should work.
    Last edited by trend747; 07-13-2011, 09:29 PM.

    #2
    trend747, if you startup the strategy by what are you then defining position size, ByDefaultQuantity or ByStrategy?

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      trend747, if you startup the strategy by what are you then defining position size, ByDefaultQuantity or ByStrategy?
      ByStrategy

      Comment


        #4
        If you directly enter your position size needed hard-coded in the EnterLong() for a test - would it then use the qty specified?

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          If you directly enter your position size needed hard-coded in the EnterLong() for a test - would it then use the qty specified?
          Yes. I used a random number (123485) and it used it.

          Comment


            #6
            Here's the output from the Print() statements of what I just ran. As you can see, the positionSize variable is being populated correctly:

            My account size is: 9814.79010000007
            My risk amount is: 1.06682501086957
            My first position size is: 10668.2501086957
            My final position size is: 10668

            Comment


              #7
              Since the hardcoded entry is working out fine, the issue is to be found in your code - are you using a public property for positionsize as well here? If you send your script to support we could give it a run here as well.

              Comment


                #8
                It's not working Bertrand. I forgot to remove the hardcoded number that we put in there... LOL. Can you take a look at this code?

                Comment


                  #9
                  Too bad, sure please send it over to support at ninjatrader dot com to my Attn.

                  Thanks,

                  Comment


                    #10
                    Ok, just sent. Thanks so much for your prompt attention. Your support is top notch!

                    Comment


                      #11
                      Thanks for the kind words - just replied to your note sent to support, I feel it's an issue of the scope of your variable defining the position size used.

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        Thanks for the kind words - just replied to your note sent to support, I feel it's an issue of the scope of your variable defining the position size used.
                        It works! Thanks bro!
                        Last edited by trend747; 07-14-2011, 01:24 PM.

                        Comment


                          #13
                          could you please publish the working code?

                          i know the reply is a bit late

                          Comment


                            #14
                            Originally posted by trend747 View Post
                            It works! Thanks bro!
                            trend747 would you be able to post the required adjustment, or send me a private msg. I am looking for the same solution, but I am stuck. Thanks

                            Comment


                              #15
                              Originally posted by NinjaTrader_Bertrand View Post
                              Thanks for the kind words - just replied to your note sent to support, I feel it's an issue of the scope of your variable defining the position size used.
                              Bertrand, would you be able to give us a hint on how you solved this issue?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              71 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              43 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              25 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              28 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              56 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X