Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamic position sizing in NT7 backtests

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

    Dynamic position sizing in NT7 backtests

    I'm a relative newcomer to NinjaTrader, and I'm now attempting to test multi-instrument strategies using "unmanaged" orders with position sizing dependent on the current state of an imaginary account. This leads me to ask a few questions! I have looked through the forum, but haven't found definitive answers to some of them. If they exist, perhaps someone can point me in the right direction?

    1. NT7 introduced GetAccountValue(). This seems to be the obvious way to go in live trading, but it also always seems to return 0 in a backtest. Is this behaviour likely to change in the future, perhaps in NT8?

    2. I discovered this example of how to incorporate a dynamic (and hopefully monotonically increasing!) account into a backtest. Is this still the recommended way of doing things in NT7?

    3. The combination of 1 & 2 suggest there is no option but to use different position sizing code for testing and live trading. Not an ideal situation, or so it seems to me. If there's no way around that issue, is there a better way for a strategy to work out whether it's running in a live or testing environment, other than the test suggested by my question 1?

    Thanks in advance,

    Jim

    #2
    Hello Jim,
    Thanks for your post.

    1. Yes, GetAccoutValue is a real time property only and not available in backtest or in the historical bars. Unfortunately I am not aware how it will function in our next major release.

    2. You can take reference from the custom code, however the final outcome will depend on what your strategy is trying to do.

    3. Unfortunately there are no native way to do it. You have to custom code any such function for backtesting purpose.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hi Joydeep,

      Thanks for your swift response, which confirms that there's no easy way to achieve what I want to achieve in NT7! I can't believe that I'm the first person to ask for these additional features to be added to NTn, but what would you estimate the probabilities are for something along the lines of:

      1. IsBacktest()?

      2. GetAccountValue() that emulates "real life" during a backtest?

      Cheers,

      Jim

      Comment


        #4
        Hello Jim,
        You can refer to the Historical function for it.


        GetAccountValue is a real time property only. You have to custom code any such functions for the historical bars.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thanks for that suggestion too. I can see that Historical will come in handy in other ways also.

          Jim

          Comment


            #6
            Originally posted by SoulSurfer View Post
            Hi Joydeep,

            Thanks for your swift response, which confirms that there's no easy way to achieve what I want to achieve in NT7! I can't believe that I'm the first person to ask for these additional features to be added to NTn, but what would you estimate the probabilities are for something along the lines of:

            1. IsBacktest()? I made this a Boolean property of the strategy.

            2. GetAccountValue() that emulates "real life" during a backtest? - I specified the initial value of the account, and let the strategy calculate values during the run by adding profits and subtracting losses. Cumbersome, but eminently workable.

            Cheers,

            Jim
            Just some suggestions. They are inside your original text.

            Comment


              #7
              Good morning Koganam,

              Thanks for your suggestions also. Historical does #1 near enough, and to start with I've implemented #2 using the Performance object, as suggested in my original link. Can you foresee any problems using that approach? Do you keep track of "open" PnL for example?

              Coming to NT from other platforms, it seems like a significant omission to have to code this sort of thing oneself. Is there a good reason why it is necessary? Do Ninja Traders not concern themselves with testing position sizing / money management as a rule?

              Jim

              Comment


                #8
                Hello SoulSurfer,
                You can use the GetProfitLoss function to retrive the unrealized PnL.

                Please refer to our help guide to know more about it.


                We do expose the PnL etc via the Positions, TradeCollections etc classes. For any custom requirements you have to custom code your own functions.


                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by junkone, Today, 11:37 AM
                2 responses
                15 views
                0 likes
                Last Post junkone
                by junkone
                 
                Started by frankthearm, Yesterday, 09:08 AM
                12 responses
                44 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by quantismo, 04-17-2024, 05:13 PM
                5 responses
                35 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by proptrade13, Today, 11:06 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                36 views
                0 likes
                Last Post love2code2trade  
                Working...
                X