Accessing balances and application info  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
SysInv
Posts: 28
Joined: 25 Nov 2012
Has thanked: 1 time
Been thanked: 1 time

Accessing balances and application info

Postby SysInv » 05 May 2013

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?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Accessing balances and application info  [SOLVED]

Postby Henry MultiСharts » 06 May 2013

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?
Hello SysInv,

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
Similar question for accessing backtesting balance – Is there a simpler way to access portfolio balance or do I have to take InitialCapital+Portfolio.NetProfit?
There is no simpler way, your approach is correct.
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?
This issue has been confirmed. It will be fixed in the next version of MultiCharts .Net.


Return to “MultiCharts .NET”