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?
    BertrandNinjaTrader Customer Service

    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?
        BertrandNinjaTrader Customer Service

        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.
              BertrandNinjaTrader Customer Service

              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,
                  BertrandNinjaTrader Customer Service

                  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.
                      BertrandNinjaTrader Customer Service

                      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 bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,603 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X