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

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.
      Paul H.NinjaTrader Customer Service

      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 daniel_weber8, Today, 01:21 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by jungsoohuh, Today, 12:07 PM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by SharonSS, Today, 11:54 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by crystalet, Today, 11:20 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by SuperDude123, Today, 09:23 AM
        1 response
        31 views
        0 likes
        Last Post NinjaTrader_JustinD  
        Working...
        X