Account information is not loaded correctly on MC 8

Questions about MultiCharts .NET and user contributed studies.
Posts: 24
Joined: 06 Apr 2011
Has thanked: 5 times
Been thanked: 2 times

Account information is not loaded correctly on MC 8

Postby felixtjung » 24 Oct 2012


I've been trying to get equity from broker connected to I use following code

Code: Select all

      private double currentEquity {
         get {
            try {
               ITradingProfile active_profile = activeProfile;
               if ((active_profile != null) && (active_profile.Accounts.Length > 0)) {
                  string current_account = active_profile.Accounts[0];
                  Account[] accounts = TradeManager.TradingData.Accounts.Items ?? new Account[0];
                  Account active_account = accounts.FirstOrDefault(acc => acc.Name == current_account);
                  double? balance = active_account.Balance;
                  if (balance.HasValue) {
                     return balance.Value;
            catch (Exception ex) {
               // ignore if there's any error

            if (this.Environment.IsAutoTradingMode) {
               return 0;

            return this.InitialCapital + this.NetProfit;

      private ITradingProfile activeProfile {
         get {
            ITradingProfile[] trading_profiles = this.TradeManager.TradingProfiles ?? new ITradingProfile[0];
            return trading_profiles.FirstOrDefault(prof => prof.Name == this.Profile);

This code works "most" of the times, except there are 2 catches. First, it never get updated at all. Second, it's returning 0 on live trading (which means there's no account loaded) intermittently during start time. My question is this, is there anything that I need to do to make it work correctly, or is this a bug? If it's a bug, is there any workaround that I can apply to fix this problem for the time being?


User avatar
Henry MultiСharts
Posts: 8667
Joined: 25 Aug 2011
Has thanked: 1218 times
Been thanked: 2792 times

Re: Account information is not loaded correctly on MC 8

Postby Henry MultiСharts » 26 Oct 2012

Hello felixtjung,

In order to receive updates you need to call TradeManager.ProcessEvents();
These users thanked the author Henry MultiСharts for the post:

Return to “MultiCharts .NET”