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 judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        22 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X