Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating hypothetical results using position sizing in backtests

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

    Calculating hypothetical results using position sizing in backtests

    I am trying to see backtest results using dynamic position sizing, 1% risk of a hypothetical account per trade, instead of a static number of contracts. How can I achieve this?

    Thanks

    #2
    Hello Bmatarese,

    Thank you for your post.

    When backtesting there is no means to set the values of the account. You would instead implement internal calculations in your strategy to calculate and track your own custom values for the desired account values, then calculate position size based on that. You could make the account starting balance a user input if you wish.

    You should confirm with your broker the formula for calculating the funds required for each trade or contract.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Is there anywhere I could get assistance in setting up the internal calculations, don't know where to start. And then would I need to export the data as a text file in order to see the results of it?


      Comment


        #4
        Hello Bmatarese,

        Thank you for your reply.

        Well, if you set up a user input for the account's starting cash value, you could use that to establish a position size this way:


        onePercent = Convert.ToInt32(myCashValue * .01);
        myOrderQuantity = onePercent / priceForOneContract;

        Where myCashValue would be your user input for the cash value, and priceForOneContract would be the funds required for one contract. You'd likely need to round the resulting number to a whole number, for which you can use Math.Round, so here is publicly accessible documentation from Microsoft on that:

        Rounds a value to the nearest integer or to the specified number of fractional digits.


        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Is it possible to adjust the position size based on a cumulative account balance? And where can I see the results of all of the calculations?

          Comment


            #6
            Hello Bmatarese,

            Thank you for your reply.

            You would need to track the PnL of each trade and add or subtract that from the variable for the cash value.

            To get the PnL you'd need to use the TradeCollection to find the most recently completed trade and retrieve the PnL for it. I'd suggest taking a look at this example from our help guide:



            As far as viewing the end result, you would likely want to use Print() statements in your code to print that information to a NinjaScript Output window.

            This forum post goes into great detail on how to use prints to help figure out where issues may stem from — in your case you would want to use them to print the value of the variable you use to track the account balance. You can even add these using the Strategy Builder.

            https://ninjatrader.com/support/foru...ns-not-working

            Please let us know if we may be of further assistance to you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X