I’m having problems accessing the account balance via TradeManager. It’s my understanding that this shall be accessible directly, ie via TradeManager.TradingData.Accounts.Items[0].Balance. Debugging it in VS confirms that this information is accessible like this, but MC throws an exception. I’ve looked at the example posted where events for added and changed accounts are used, but in this case I need to listen to the events and store the account balance to make it accessible when I need to use it. Why does MC throw an exception that the index it out of bounds, when VS clearly shows that it finds all accounts with the same command and that there is an account with that specific index? I even check that the items collection has an index larger than 0 before accessing it.
What would the easiest way be to access the current account (selected for autotrading) on the fly in the code?
Similar question for accessing backtesting balance – Is there a simpler way to access portfolio balance or do I have to take InitialCapital+Portfolio.NetProfit?
When using ApplicationCode to identify if it’s a backtest running or on a chart, it keep returning “unknown”. I first create the object with private IApplicationInfo chartInfo;, then in “StartCalc()” assign it with chartInfo = Environment; and finally try to check it each bar with chartInfo.ApplicationCode == EApplicationCode.Portfolio but if I look at it in VS then chartInfo.ApplicationCode has value “unknown”. Am I using it incorrectly?
Accessing balances and application info [SOLVED]
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Accessing balances and application info [SOLVED]
Hello SysInv,I’m having problems accessing the account balance via TradeManager. It’s my understanding that this shall be accessible directly, ie via TradeManager.TradingData.Accounts.Items[0].Balance. Debugging it in VS confirms that this information is accessible like this, but MC throws an exception. I’ve looked at the example posted where events for added and changed accounts are used, but in this case I need to listen to the events and store the account balance to make it accessible when I need to use it. Why does MC throw an exception that the index it out of bounds, when VS clearly shows that it finds all accounts with the same command and that there is an account with that specific index? I even check that the items collection has an index larger than 0 before accessing it.
What would the easiest way be to access the current account (selected for autotrading) on the fly in the code?
We were unable to replicate this behavior in our environment. Please send me the export of the study you are using and the workspace you are using alongside with detailed description how
to replicate this behavior to support@multicharts.com
There is no simpler way, your approach is correct.Similar question for accessing backtesting balance – Is there a simpler way to access portfolio balance or do I have to take InitialCapital+Portfolio.NetProfit?
This issue has been confirmed. It will be fixed in the next version of MultiCharts .Net.When using ApplicationCode to identify if it’s a backtest running or on a chart, it keep returning “unknown”. I first create the object with private IApplicationInfo chartInfo;, then in “StartCalc()” assign it with chartInfo = Environment; and finally try to check it each bar with chartInfo.ApplicationCode == EApplicationCode.Portfolio but if I look at it in VS then chartInfo.ApplicationCode has value “unknown”. Am I using it incorrectly?