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 Hwop38, 05-04-2026, 07:02 PM
            0 responses
            164 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            319 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            246 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            350 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X