Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAccountValue on Sim101

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

    GetAccountValue on Sim101

    Does the Sim101 account support GetAccountValue?

    I have this in my code in OnStartUp():

    PHP Code:
    if (GetAccountValue(AccountItem.CashValue) < 5000)
    {
    Log("ERROR: Strategy myStrat on " + Instrument.FullName+ " Account balance insufficient to trade this strategy.", LogLevel.Error);
    Print(Time[0] + " ERROR: Strategy myStrat on Instrument " + Instrument.FullName+ " Account balance insufficient to trade this strategy. Current cash balance is: " +
    GetAccountValue(AccountItem.CashValue) );
    return; 
    } 
    
    It is printing the account value at 0.

    Thanks!

    #2
    MXASJ,

    Works on Sim101 here. I suggest you just remove your filter condition and just add a really simple print statement. Also, please try resetting your Sim101 account.

    Code:
    Print("OnStartUp: Buying Power: " + GetAccountValue(AccountItem.BuyingPower) + " CashValue: " + GetAccountValue(AccountItem.CashValue) + " Realized PnL: " + GetAccountValue(AccountItem.RealizedProfitLoss));
    OnStartUp: Buying Power: 17995959.16 CashValue: 8997979.58 Realized PnL: -16.6
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh,

      Hmmm. Reset Sim101 account, Repaired the DB, changed the code to yours and I get:

      OnStartUp: Buying Power: 0 CashValue: 0 Realized PnL: 0

      Anything other than a fresh install I should try?

      NT7b14 connected to Zen/IQFeed.

      Thanks.

      Comment


        #4
        More information: I did an in-place upgrade from b14 to b15, and moded the SampleMACrossOver strategy to include the Print() statments mentioned. It still returns:

        OnStartUp: Buying Power: 0 CashValue: 0 Realized PnL: 0

        Is there anything I should check before doing a clean install of b15?

        Thanks
        Attached Files

        Comment


          #5
          More info: The in-place upgrade process included a restore from backup.
          I just did a clean install on my XP VM, did not restore anything, created a Yahoo connection, and then tested the SampleMACrossOverTest strategy on daily AAPL data.

          Same problem... Sim101 all showing zeros.

          Open to test anything you guys can throw at me .

          Comment


            #6
            Where are you doing this from? Are you connected to a data provider? Running the strategy from a chart?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              My primary workspace has no charts at all, though there is one with charts running in background I can access with Shift-F3. I launch the strategy on the Strategy tab of Control Center, right click, New Strategy, Enabled. Typically I would never launch a strategy from a chart for what I do.

              I'm not trading cash on this install and can do pretty much anything you want me to. The only other ticket I have open is 30924.

              EDIT: My data providers are Zen, IQFeed, and for the clean install/no restore, Yahoo.

              Comment


                #8
                Thanks. Looking into it.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Clarified with development. GetAccountValue() would only work in real-time so you would need to filter for Historical checks.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, Josh. Moved from OnStartUp() to OnBarUpdate() and it now works as advertised. Have a good weekend.

                    Comment


                      #11
                      Strategy Analyzer - GetAccountValue(): Filter for historical checks

                      Hello:

                      How does one filter historical bars to keep track of the cash value in Sim101 account as trades are registered in Strategy Analyzer? I wish to access this change in cash during optimization via the output window. I have used the print function and all I am getting is zeroes. Thanks.

                      Tony

                      Comment


                        #12
                        tonyh, in order to filter out the historical bars, you can do this:
                        Code:
                        if (Historical)
                        {
                           // these bars are not realtime, so skip them
                           return;
                        }
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Filter Out Historical Bars - Test Money Management part of a strategy

                          Hello Ausin:

                          I understand this concept so that position is flat before trading day begins. I am trying to test the process of GetAccountValue() in a Strategy using Strategy Analyzer before going live. This doesn't appear possible. Is there any way to access the Initial Cash value set up in NT7 for Sim101 under Tools-Options-Simulator tab? How can one test a strategy with Money Management techniques within Strategy Analyzer without access to BuyingPower, CashValue, and RealizedProfitLoss?

                          Thanks.

                          Tony

                          Comment


                            #14
                            Tony, you can set and then update the variable called AccountSize:
                            Code:
                            protected override void Initialize()
                            [LEFT] {
                                 AccountSize = 10000;
                            }
                            [/LEFT]
                            It is only set once at the beginning of the strategy run, but after that you will have to keep it updated yourself with the trade results. You can use the Performance class to access trade data. In addition, there is a reference sample that deals with using trade performance for money management.
                            AustinNinjaTrader Customer Service

                            Comment


                              #15
                              Strategy Analyzer Code verses Real-Time

                              Thanks Ausin. I will review these again. I guess my assumption is correct that the code will have to be different for testing verses real-time.

                              Tony

                              Comment

                              Latest Posts

                              Collapse

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