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:
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));
Image:
Thank you
Comment