How to update you values live on ChartTrader UI

The task was to get selected chart trader account pnl and print its values out on a chart trader. The numeric value at the bottom of this custom chart trader reads the live pnl and also updates when it changes. 

In order for the value to get updated you have to additionally inherit the strategy class from INotifyPropertyChanged interface. Once you do that you also have to implement it like this:

	private double _accountPnl;
        public double AccountPnl
            get { return _accountPnl; }
                if (_accountPnl != value)
                    _accountPnl = value;
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
            if (PropertyChanged != null) {
             PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); }

So once that is done and assuming you also need to get the selected account itself. I do it inside OnMarketDataUpdateEvent. like this:

        private void GetSelectedAccount()
            ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                //You have to put the stuff below within this ChartControl.Dispatcher.InvokeAsync((Action)(() =>,
                //because you are trying to access something on a different thread.
                _accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as 
                var realized = _accountSelector.SelectedAccount
                    .GetAccountItem(AccountItem.RealizedProfitLoss, Currency.UsDollar).Value;
                var unrealized = _accountSelector.SelectedAccount
                    .GetAccountItem(AccountItem.UnrealizedProfitLoss, Currency.UsDollar).Value;
                AccountPnl = realized + unrealized;

Now finally you will need to implement the label itself like this:

                var label = new Label();
                //label.Content = "PNL: " + _accountPnl;
                label.DataContext = this;
                label.SetBinding(ContentControl.ContentProperty, new System.Windows.Data.Binding("AccountPnl"));
                label.FontSize = 14;
                label.FontWeight = FontWeights.Bold;
                label.HorizontalAlignment = HorizontalAlignment.Center;
                Grid.SetColumn(label, 1);

Have fun!)