Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Account Value during Back Testing

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

    Account Value during Back Testing

    I wrote a NT strategy where the quantity passed to EnterLong() and EnterShort() depend upon the current account value. While backtesting, GetAccountValue(AccountItem.CashValue) always returns 0 and AccountSize is never updated from its initial value. I want to give my strategy a starting account value and have it update that value as trades take place. How do I do this?

    Thank you,
    Matt Horvay

    #2
    Hello Matt,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Correct, the GetAccountValue() method will return 0 on historical bars which are the bars used in backtesting.

    When using the Strategy Analyzer you can set Order Properties to Set Order Quantity = By Account Size and Account Size = your desired amount.

    For information on the Strategy Analyzer please visit the following link: http://www.ninjatrader.com/support/h...y_analyzer.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      I have a similar question, so please let me add it to this thread.

      The previous reply is interesting for what it does not say. If in the backtesting parapmeters I set Order Quantity by Account Size and set an Account Size, will GetAccountValue then return the accoutn size and track it as orders are entered?

      Related question: I am writing a multi-instrument strategy. Which means all my orders have to be entered with
      ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)

      It seems that specifying the quantity in this call overrides the backtesting parameters for order quantity. Is this correct? I assume, then, that my strategy has to do the order quantity calculations, yes?

      Thanks,
      ++PLS

      Comment


        #4
        Hello pls2000,

        Thank you for your post.

        The GetAccountValue() will always return 0 on historical bars, backtesting is done on historical bars.

        Even though you need to set a order quantity in the syntax referenced the SetOrderQuantity parameter will override this if you choose ByDefaultQuantity or ByAccountSize.

        Please let me know if I may be of further assistance.

        Comment


          #5
          Is there a way in backtesting to set the account value and then for the account value to change based on the running p/l

          Comment


            #6
            Thank you.

            Since setting Order Size = By Account doesn't affect GetAccountValue, what exactly does this setting do? It doesn't seem to make any difference at all.

            ++PLS

            Comment


              #7
              Hello fiddy,

              Thank you for your response.

              You would need to create your own internal calculation to track an Account Size variable of you own as the SetOrderQuantity = ByAccountSize does not update in the backtest run by the the profit and loss.

              Please let me know if you have any questions.

              Comment


                #8
                Hello pls2000,

                Thank you for your response.

                GetAccountValue() is to be used in real-time trading to access the account value. On historical bars the account value is unknown.

                The SetOrderQuantity = ByAccountSize allows you to set a starting Account Size to base order quantity on.

                Please let me know if you have any questions.

                Comment


                  #9
                  When you set Order Quantity to Account Size, how does the strategy get the account size?

                  I think having GetAccountSize not work in backtesting is a major failing. In effect it means I can't backtest the same strategy I intend to run. I need to have two versions of each strategy, one which tracks its own account value and one which relies on GetAccountValue.

                  One the puzzles me. As I understand it, the purpose of running the strategy over historical bars is to get the strategy into the state it would have been in had it been running real-time over that period. If the strategy generates trades that depend on account value, how does this ever work?

                  Thanks,
                  ++PLS

                  Comment


                    #10
                    Hello pls2000,

                    Thank you for your response.

                    The GetAccountValue() will pull from the account the strategy is applied to in real-time. On historical bars there is no way to tell what the account was. In backtesting there is not an account that the strategy is placed on but rather the historical bars are used to calculate what trades would have been taken.

                    You are correct in that a strategy designed with GetAccounValue() in mind would not work as desired without your own custom logic to track the profit and loss for a variable of your own.

                    Please let me know if I may be of further assistance.
                    Last edited by NinjaTrader_PatrickH; 09-17-2013, 07:10 AM.

                    Comment


                      #11
                      Thank you.

                      Now, I've rewritten my strategy to track its own account value, using OnExecution to get the value of the (price * quantity) and update the account value.

                      This fails. The IExecution interface passed to OnExecution provides price and quantity, but not wheter the order is a buy or sell. That information is in the IOrder that IExecution provides.

                      Except that in backtesting, the IOrder is always null.

                      The parent object of the order provides Entry and Exit indicators, but those are not available to me.

                      So, how do I get the value of an execution (price * quantity * direction) in OnExecution to update my account value?

                      Thanks,
                      ++PLS

                      Comment


                        #12
                        Hello pls2000,

                        Thank you for your response.

                        IOrder objects are not always null in backtesting. Why can't you access the IOrder object in OnExecution() in backtesting?

                        Are you assigning your orders to IOrder objects?

                        For information on on IOrder please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

                        I look forward to your response.

                        Comment


                          #13
                          Please read my previous message again.

                          The code is

                          protectedoverridevoid OnExecution(IExecution execution)
                          {
                          OrderAction action = execution.Order.OrderAction;

                          This fails because execution.Order is null.

                          I know the help file says that not all executions will contain an order object, giving the example of ExitOnClose. If I have to track my own acount size, I need to be able to determe the effect on account value of every order.

                          Is there another way to get the order type? I giess I can tell that an order cam from ExitOnClose by the null Order reference, but how can I tell if this order is a buy ot sell?

                          If you might pass a suggetion on to the developers, the IExecution interface provides price and quantity. I think it should provide order action too.

                          Thanks
                          ++PLS

                          Comment


                            #14
                            Hello pls2000,

                            Thank you for your response.

                            Please make sure to check for null before accessing the OrderAction:
                            execution.Order != null
                            For information on IExecution please visit the following link: http://www.ninjatrader.com/support/h...iexecution.htm

                            For information on IOrder please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

                            Please let me know if you have any questions.

                            Comment


                              #15
                              Of course I can check or null.

                              Once again, when the Order object is null, how do I know whether the execution being reported in OnExecution is a buy or a sell?

                              ++PLS

                              Comment

                              Latest Posts

                              Collapse

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