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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            938 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            3 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            2 views
            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  
            Working...
            X