We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to access data from MetaTrader to SfChart using TradePlatform.Net in WPF ?

Platform: WPF |
Control: SfChart |
Published Date: August 10, 2017 |
Last Revised Date: June 27, 2019


This article describes how to access data from Metatrader to ItemsSource for chart series using TradePlatform.Net.


The solution can be achieved by adding the data that fetched from the Metatrader into an ObservableCollection, and setting that collection to the ItemsSource for chart series. It has been explained in following steps.

Step 1: Use the following code example as Model class.


   public class Model
            public int OrderTicket { get; set; }
            public double TakeProfit { get; set; }
            public double Profit { get; set; }
            public double OpenPrice { get; set; }
            public double ClosePrice { get; set; }

Step 2: Fetch the data from Metatrader, and add it into a collection.


public partial class MainWindow : Window
     private MetaTrader4 metaTrader4;
     private int OrderCount = 0;
     public ObservableCollection<Model> Collection { get; set; }
     public MainWindow()
         this.DataContext = this;
         Collection = new ObservableCollection<Model>();
    //Corresponding account number and its respective symbol has to be passed, in order to make connection with required account
         metaTrader4 = Bridge.GetTerminal(2088782777,"EURUSD.arm");
         metaTrader4.QuoteRecieved += metaTrader4_QuoteRecieved;
     private void metaTrader4_QuoteRecieved(QuoteListener mql)
         if (OrderCount != mql.OrdersTotal())
              for (int i = mql.OrdersTotal() - 1; i >= 0; i--)
                  if (mql.OrderSelect(i, SELECT_BY.SELECT_BY_POS))
               int orderTicket = mql.OrderTicket();
                       double orderProfit = mql.OrderProfit();
                       double takeProfit = mql.OrderTakeProfit();
                       double openPrice = mql.OrderOpenPrice();
                       double closePrice = mql.OrderClosePrice();
                       var data = new Model
                            OrderTicket = orderTicket,
                            Profit = orderProfit,
                            TakeProfit = takeProfit,
                            ClosePrice = closePrice,
                            OpenPrice = openPrice
      //Corresponding data fetched from MetaTrader is added to Collection and this ObservableCollection is set as ItemsSource for SfChart

Step 3: Bind the corresponding collection (with data fetched from Metatrader) to series’ ItemsSource.


  <chart:SfChart Margin="10" >
            <!--ObservableCollection consists of fetched data from MetaTrader is set as    
                                        ItemsSource for series-->
            <!--Corresponding property field is set as the binding path for series-->
        <chart:CandleSeries ItemsSource="{Binding Collection}"
                                             High="Profit" Low="TakeProfit"
                                            Open="OpenPrice" Close="ClosePrice"/>


Chart rendered by getting data from MetaTrader in WPF

The demo sample is available for download in this link.


2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon