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

  • eoinf
    replied
    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!

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    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.

    Leave a comment:


  • jjaffa
    replied
    damn this looks like a problem i might run into. bump

    Leave a comment:


  • 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, 06:26 PM. Reason: Edited tags

Latest Posts

Collapse

Topics Statistics Last Post
Started by SpikeLGWG, Today, 12:00 PM
1 response
7 views
0 likes
Last Post NinjaTrader_Jim  
Started by NichUK, Today, 10:51 AM
0 responses
9 views
0 likes
Last Post NichUK
by NichUK
 
Started by caseymour127, Today, 09:46 AM
2 responses
22 views
0 likes
Last Post caseymour127  
Started by Apo84, Today, 09:37 AM
2 responses
30 views
0 likes
Last Post Apo84
by Apo84
 
Started by skblack1911, Today, 09:41 AM
1 response
4 views
0 likes
Last Post NinjaTrader_RyanS  
Working...
X