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

GetAccountValue(AccountItem.CashValue): No Accurate Results

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

    GetAccountValue(AccountItem.CashValue): No Accurate Results

    Hi there,

    I am trading unmanaged. Account information is crucial to enter and exit trades. Without it my strategy can not calculate it's numbers of positions to trade or when to exit on margin requirements etc.

    I use Rithmic as order and price feeds. The account tab in Ninjatrader shows the Cash Value as send by Rithmic. This value is in sync with my real account size. But when retrieving this value with GetAccountValue(AccountItem.CashValue), it is always off by about 300 to 400 USD on the lower side. This is also the case when having no open positions, thus no unrealized PnL that could cause the difference.

    Rithmic states they solely send the account data to Ninjatrader but they can't say or guerantee anything about the handling by Ninjatrader of this data. So the issue has to be figured out Ninjatrader side.

    I have tried several things, but the retrieved Cash Value is never spot on. Any idea where to look at?

    Cheers,
    Francis

    #2
    Hello Francis,

    Are you finding that the strategy calling GetAccountValue does not match the cash value in the Accounts tab of the Control Center?

    Are you finding that the Accounts tab of the Control Center is matching the strategy but does not match the account value being reported by your brokerage?

    I've made a video and a strategy to test the account value.

    http://screencast.com/t/KFEIStTgP

    Can I have you test this example script on your end and let me know if you are finding this strategy does not have the account value on the chart match the account value on the Accounts tab of the Control Center?
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for your swift reply and very clear video.

      The calling of the GetAccountValue does not give the same value as stated in the account tab, where the value in the account tab does match the real account size of my brokerage. That is why I was quite confused. If the calling does not match the stated value in the account tab, but it does return a value, there should be a third value stored somewhere. Which seems not very logical as GetAccountValue can only retrieve from one single source.

      I do know the value is only updated after a change in position. On historical bars and without a new position the value retrieves zero. That is why I coded a value offset on starting the strategy before any position is entered or exited. I need the account value to base the number of positions on. Although I still do not know why the offset is correct until there is a change in position, there is logic to have my offset value replaced with new and firstly updated value from 0 to real value after updating a first position, instead of altering this offset value mathematically.

      I will run your added test strategy after the market is closed and I can disable current active strategies. I will let you know, but I think you helped me already with the OnPositionUpdate.

      Thanks again!

      Comment


        #4
        I was able to alter some parts in my code based on your suggestions. It works. I do have a clean and accurate cash value starting point on enabling a strategy or rolling it over at a session end. So even without a position update there is a value, which updates fine now after updating positions or when having a running position (mathematically updated on new last tick).

        Thanks again Chelsea!

        Comment


          #5
          Hi Chelsea,

          This is very old stuff now, but for years I divided the CashValue of my account by an optimized divisor to get the number of contracts for my entry orders. This worked perfectly with live trading, and of course worked perfectly with Market Replay data -- otherwise I would not have commited real money to live trades.

          Now, after updating to NT7 ....38 and recompiling my strategies, nothing works as before. With Replay input data, GetAccountValue(AccountItem.CashValue returns zero, whatever the account that is specified. Apparently, replay data is treated as historical data now, which was not the case before this magnificent updated version of NT.

          Under these circumstances, why would I put my faith into trusting live trading to get CashValue right? I look forward to some reassurance.

          Comment


            #6
            Hello Xenophon99,

            I am not able to reproduce this behavior using the latest version of NinjaTrader 7 (7.0.1000.38).

            Below is a link to a video that demonstrates the CashValue is printing from a strategy that is enabled while in Market Replay playback.



            Attached is the script I have tested.

            Using the steps in the video and the script I have supplied are you getting different behavior than what is shown in the video?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Get Account Value

              Hello Chelsea,

              As with the earlier Cash Value Test script, I get what is expected when I test with Continuum live data but get zeroes when I test with Market Replay input data. The latest GetAccountValue test could not be simpler. It just returns without doing anything for me because the "If Historical" test is evaluated as true when I am accessing Replay data. So how is it that for you that test is evaluated as false? This does not make sense. I look forward to some enlightenment.

              Xenophon99

              Comment


                #8
                Hello Xenophon99,

                In the video I have tested using the Market Replay and I am not able to reproduce this behavior.

                To confirm, as new real-time bars close, the Historical bool property is true?

                Can you provide a video to demonstrate that the Historical property is true as real-time bars close?

                Jing by Techsmith is 3rd party software you can use to record short videos.

                Below is a publicly available link.
                TechSmith Capture is a simple, free way to create basic screenshots and screen recordings and share them with others.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NRITV, Today, 01:15 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by maybeimnotrader, Yesterday, 05:46 PM
                5 responses
                24 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by quantismo, Yesterday, 05:13 PM
                2 responses
                16 views
                0 likes
                Last Post quantismo  
                Started by frankthearm, Today, 09:08 AM
                6 responses
                27 views
                0 likes
                Last Post frankthearm  
                Started by adeelshahzad, Today, 03:54 AM
                5 responses
                33 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X