Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Equity calculation in backtests

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

    Equity calculation in backtests

    Hello,

    may I ask how the equity can be calculated on historical EOD bars during a backtest since AccountSize and GetAccountValue returns zero ?

    Best Regards

    Thomas

    #2
    Hi Thomas,

    Thanks for the post and welcome to the NinjaTrader forums. You can see here for how all performance statistics are calculated:


    If you're looking for something that isn't on that page, can you please let us know where in NT you are looking?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello Ryan,

      I would like to use the current equity in a strategy during a backtest. How can I calculate it in the ninjascript code on historical bars?

      Thanks

      Thomas

      Comment


        #4
        You would have to custom code any calculations that are not yet provided in the existing trade performance class. Equity seems fairly straightforward. Are you looking for position quantity * share price?

        Code:
        if(Position.MarketPosition != MarketPosition.Flat)
        {
        	double myEquity = Position.Quantity * Close[0];
        	Print(myEquity);
        }
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hello Ryan,

          thank you for the fast answer. For my money management I have to calculate the free amount of money in the account. Normaly that would be delivered by GetAccountValue() during live trading. But how can I get this amount in a backtest on historical data?

          Best Regards

          Thomas

          Comment


            #6
            It needs to be custom coded. Specify an arbitrary starting point for the account in the variables region.

            If you want to deduct trade results from this, can use the built in RealizedPnL.

            Code:
            #region Variables
            private double myAccountValue = 100000;
            #endregion
            
            protected override void OnBarUpdate()
            {	
            double myAccountAfterTrading = myAccountValue - Performance.AllTrades.TradesPerformance.Currency.CumProfit;
            Print(myAccountAfterTrading);
            }
            Last edited by NinjaTrader_RyanM1; 12-06-2011, 10:44 AM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X