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

Recommended Way to Get Live Account Balance History

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

    Recommended Way to Get Live Account Balance History

    I have added some functionality to size down on an automated strategy based on current drawdown. This is straightforward in backtesting because I keep track of the account balance by adding NetProfit to some default starting balance and then can do intraday and end of day drawdown calculations using that balance.

    What is the best/recommended way to do something similar for live/real-time trading? Is there a way to programmatically get a running history of the account balance? I can probably get the cumulative net profit in similar fashion using SystemPerformance.RealTimeTrades.TradesPerformance .NetProfit, but for that to work I need to know the original starting balance and I don't see how to do that.

    I should also mention that this is an intraday strategy and I tend to restart each morning, so keeping track of this in the runtime process like the backtest affords isn't a viable solution.

    Code:
                    if (State == State.Historical)
                    {
                        if (SystemPerformance.AllTrades.Count > 0)
                        {
                            double netProfit = SystemPerformance.AllTrades.TradesPerformance.NetProfit;
                            AccountBalance = 100000 + netProfit;
                            PeakAccountBalance = Math.Max(PeakAccountBalance, AccountBalance);
                            Drawdown = AccountBalance - PeakAccountBalance;
                            DrawdownPct = Drawdown / PeakAccountBalance;
                            if (USE_COMPOUNDING == false)
                            {
                                DrawdownPct = Drawdown / 100000;
                            }
                            MaxDrawdown = Math.Min(Drawdown, MaxDrawdown);
                            MaxDrawdownPct = Math.Min(DrawdownPct, MaxDrawdownPct);
    
                            if (Bars.IsLastBarOfSession)
                            {
                                MaxClosingDrawdown = Math.Min(Drawdown, MaxClosingDrawdown);
                                MaxClosingDrawdownPct = Math.Min(DrawdownPct, MaxClosingDrawdownPct);
                            }
                        }
                    }​

    #2
    Hello garth,

    Thanks for your notes.

    Unfortunately, there is no historical account information available to access in NinjaScript so you would not be able to get the balance history of an account.

    If you would like, I could submit a feature request to the Development team on your behalf to request this feature which they might implement as they see fit.

    Please let me know if you would like me to submit this feature request for you.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon,

      I do think it would be a good feature so submitting a feature request probably makes sense. I do understand that such features can take time and/or not get picked up so do you have any workaround suggestions? I know this information is available via account.ninjatrader.com so is there some API external to the NinjaTrader platform that I could hit to get the account history? Other thoughts I had were:

      1. Hard coding my starting balance and then roughly calculating the balance history by iterating over SystemPerformance.RealTimeTrades.TradesPerformance .NetProfit.
      2. Adding a manual toggle to go into "safe mode" if I see the account is in drawdown past the threshold (seems super hacky to need to do that).

      The backtesting metrics are so robust that it really is disappointing something as simple as a live account balance history isn't available, especially when real money is on the line. I'm open to any ideas you or others might have to work around this.

      Thanks,
      Garth

      Comment


        #4
        Hello garth,

        Thanks for your notes.

        I have submitted your feature request to the Development team to take into consideration. This request is being tracked under the number SFT-6042.

        As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.

        Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

        That said, there is unfortunately no supported workaround available that I am aware of at this time because there is no NinjaScript access to historical account information. This means there are no methods or functions available to get historical account information such as the balance.

        This forum thread will be open for other community members to share their insights on possible workarounds for this.

        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kujista, Yesterday, 12:39 AM
        2 responses
        14 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by Austiner87, Yesterday, 11:24 AM
        2 responses
        12 views
        0 likes
        Last Post brucerobinson  
        Started by Rogers101, 05-05-2024, 11:30 AM
        3 responses
        21 views
        0 likes
        Last Post Rogers101  
        Started by nightstalker, 05-04-2024, 02:05 PM
        5 responses
        55 views
        1 like
        Last Post nightstalker  
        Started by MSerag, Yesterday, 11:52 PM
        0 responses
        11 views
        0 likes
        Last Post MSerag
        by MSerag
         
        Working...
        X