Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AccountItem.CashValue returning inconsistent values in real-time vs backtests

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

    AccountItem.CashValue returning inconsistent values in real-time vs backtests

    Hello,

    I am using AccountItem.CashValue to get the cash value of my account. For testing purposes this is a Sim101 account with $100,000 in fake money. During backtests with data gathered from TDA, the cash amount is ALWYAS correct.

    I then calculate the number of shares to buy or short from getting the cash value. Please assume "PercentOfAccForPosition" is a constant like 50 because I want half the cash value.The code is simply this:
    Code:
    lock (Account.All)
    {
    ThisAcc = Account.All.FirstOrDefault(a => a.Name == "Sim101");
    }
    shareQuantity = (int)Math.Floor((ThisAcc.Get(AccountItem.CashValue , Currency.UsDollar) * (PercentOfAccForPosition / 100)) / Bars.GetClose(CurrentBar));
    In backtests I have no problems. During real time runs, the cash value is all over the place. Why is this?
    Image:
    Click image for larger version  Name:	asdasfasdw.png Views:	4 Size:	146.2 KB ID:	1154025
    Thank you
    Last edited by eoinf; 04-29-2021, 07:26 PM. Reason: Edited tags

    #2
    damn this looks like a problem i might run into. bump

    Comment


      #3
      Hello eoinf,

      Thanks for your post.

      Where exactly in your script is the code that you have shown located?

      In the Strategy Analyzer or on the historical portion of the chart, it would not be expected to change because the actual account cash is not changing. The strategy analyzer does not have an account that it uses.

      On a live chart, it would be expected to change with changes to the PNL.

      Comment


        #4
        Originally posted by NinjaTrader_PaulH View Post
        Hello eoinf,

        Thanks for your post.

        Where exactly in your script is the code that you have shown located?

        In the Strategy Analyzer or on the historical portion of the chart, it would not be expected to change because the actual account cash is not changing. The strategy analyzer does not have an account that it uses.

        On a live chart, it would be expected to change with changes to the PNL.
        Hello,

        I managed to solve this. Apparently the cash value will change if your account is not flat. E.g. you buy 50k with a 100k account the cash value becomes 150k then starts updating in real-time based on P/L. There was a bug in my strategy where the share quantity function call was being called before the account was completely flat, causing that larger cash value to be returned instead of the flat cash value.

        Thanks!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        30 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X