Discussion of article "Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#"

 

New article Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C# has been published:

The article presents a simple and fast method of creating graphical windows using Visual Studio with subsequent integration into the Expert Advisor's MQL code. The article is meant for non-specialist audiences and does not require any knowledge of C# and .Net technology.

MetaTrader 5 strategy tester has a number of features that should be considered by MQL GUI developers. The main one is the fact that the OnChartEvent graphic event processing function is not called at all. This feature is logical since the graphic form involves working with a user in real time. However, it would be extremely interesting to implement a certain type of panels in the tester. These are the so-called trading players allowing users to manually test their trading strategies. For example, the strategy tester generates the current market prices in fast forward, while a user clicks the Buy and Sell buttons simulating trading operations on history. TradePanel that we have developed is exactly this type of panels. Despite its simplicity, it may well be a plain trading player with the most necessary functionality. 

But let's think about how our panel will work in the MetaTrader 5 strategy tester. TradePanel's graphical window exists as an independent Net assembly. Therefore, it does not depend on the current MetaTrader 5 environment or even the terminal itself. Strictly speaking, it can be run from any other program, while even users themselves can launch assemblies located in the exe container.

Thus, our program does not need to call OnChartEvent. Moreover, it is possible to update data in the window and receive new orders from users in any event handling function regularly launched in the strategy tester. OnTick and OnTimer are such functions. The panel works through them. Therefore, although designed for real-time operation, our panel will also work well in the strategy tester. No changes are required for that. Let's check this statement by launching our panel in the tester and performing several deals:

Author: Vasiliy Sokolov

 

This picture

you can clearly see what you have to do to see the balance/equity chart when trading visually.


ZY What are those two additional buttons in the top-right corner of each window?

 
fxsaber:

In this picture.

you can clearly see what you have to do to see the balance/equity chart when trading visually.

For those who have two monitors it is very convenient actually. I have two, but had to do this layout for the picture.

fxsaber:

What are those two additional buttons in the top-right corner of each window?

It's an additional utility for convenient work with two monitors. In this case it shouldn't be in the gif, but you can't see everything.

 
Найдите скомпилированный файл MtGuiController.dll в папке MtGuiController\bin\debug и скопируйте его в каталог библиотек MetaTrader 5
Isn't this the debug version?
 
The first line tells the compiler that calls to открытым статическим методам класса, располагающимся в MtGuiController.dll will be used. Note that it is not necessary to specify which methods we will call in this assembly. The compiler will do this work for us in automatic mode.
Is it possible to get the list of these methods in the editor mode?
 

good article, but for some reason I think that the level is not for beginners, although as an instruction what and how is very detailed, thanks!

ZY: a form with buttons and without third-party dll ( GuiController.dll ) user can create a form with buttons using VS2017 tools literally in 2 clicks: create project - Net class library and then project - add Windows form.

in the first window "Class Library" we write a code that starts a graphical form in a few lines, approximately like this:

using System;
using System.Threading; 
public class MainForm
    {
        static Form1 mainform;
        static Thread threadmainform;
        
public static void Init()
        {
            if (mainform == null)
            {
                threadmainform = new Thread(NewForm);
                threadmainform.Start();
            }
        }

public static void DeInit(int reason)
		{
            if (reason == 3 || reason == 5) return;
            if (mainform!=null) {mainform.Close(); Thread.Sleep(1000);}
			if(threadmainform!=null) threadmainform.Join();
			mainform=null;
			threadmainform=null;
		}

private static void NewForm()   {   mainform = new Form1();   mainform.ShowDialog();   }
}

if you compile this ten lines in VS2017, then in MT5 you can already create a graphical form (all elements that will be added to the form will be "clickable" ) and you can delete it(DeInit () ), it remains only to establish data exchange between the form - which "spins" in a separate thread and MT5 itself

with MT4 everything is much sadder, but you can still get a dll written in .Net to run.


 

Thanks for the example from github. Is the same principle possible with MT5?

#include <Include.mqh> // ShareProject path

When ME automatically synchronises mqh file by prescribed comment in path?

 

Thanks for the article! Everything is chewed up. I didn't read only about the guts of C#. But you really don't need to know it to create a form.


Thoughts on application

  • From the application it is possible to stop execution of a single pass even not in visualisation mode. For example, a looped MO-learning is running in OnTester. With the form it is convenient to stop it when you see fit.
  • It is well seen that it is very easy to write a full-fledged trading API for C#. Then write all Expert Advisors in C# and run them in Terminal/Tester. And based on this API you can create alternative Terminals with custom skins, for example. Huge opportunities for applications aimed at ordinary users. You can collect their wishes and implement them: tick charts, testers, etc.
  • It is possible to easily embed the panel into your EA as an addition to manual trading in the Visualiser. This allows you to emulate stressful situations for the algo-advisor (deleted its order, placed your own, etc.). But what is even more pleasant is that all manual actions can be easily recorded and played back without the form and, accordingly, without pressing buttons. Which allows you to debug the EA in debug mode for stability of manual intervention.


How will the interaction work if several such form-advisors are run?

 
fxsaber:

Thanks for the example from github. Is the same principle possible with MT5?

#include <Include.mqh> // ShareProject path

When ME automatically synchronises the mqh-file according to the comment in the path?

What you described could be a very interesting and cool feature for ME, but of course it doesn't work that way.

However, MQL4 and MQL5 are directly supported by GitHub.

There are also utilities, primarily Git Bash, that allow you to do everything that VisualStudio has and more. They work perfectly with MQL projects. What to say if whole books are written with the help of github.

In fact, the development of MQL projects on github has been supported for a long time and at a high level.

 
Vasiliy Sokolov:

What you described could be a very interesting and cool feature for ME, but of course it doesn't work that way.

However, MQL4 and MQL5 are directly supported by GitHub.

There are also utilities, primarily Git Bash, that allow you to do everything that VisualStudio has and more. They work perfectly with MQL projects. What to say if entire books are written with the help of github.

In fact, the development of MQL projects on github has been supported for a long time and at a high level.

Unfortunately, it's all a dark forest for nerds like me. Your article shows a cool application of github. It's probably only 1% of its capabilities, but it's seen useful.

I haven't understood how it can help in MQL5 from the given links. Probably it is a must-have for programmers, but there are those who are far from programming, as I am myself.

If there was an article on this topic for MQL5, it would be useful.

 
fxsaber:

Thanks for the article! Everything is chewed up. I didn't read only about the guts of C#. But you really don't need to know it to create a form.

Thoughts on application

  • 1) From the application it is possible to stop execution of a single pass even not in visualisation mode. For example, a looped MO-learning is running in OnTester. With the form it is convenient to stop it when you see fit.
  • 2) It is well seen that it is very easy to write a full-fledged trading API for C#. Then write all Expert Advisors in C# and run them in Terminal/Tester. And based on this API you can create alternative Terminals with custom skins, for example. Huge opportunities for applications aimed at ordinary users. You can collect their wishes and implement them: tick charts, testers, etc.
  • 3) It is possible to easily embed the panel into your EA as an addition to manual trading in the Visualiser. This allows you to emulate stressful situations for the algo-advisor (deleted its order, placed your own, etc.). But what is even more pleasant is that all manual actions can be easily recorded and played back without the form and, accordingly, without pressing buttons. Which allows you to debug the EA in debug mode for stability of manual intervention.

4) How will the interaction work if several such form-advisors are run?

1) Yes, absolutely. The external application chip allows you to do all these things.

2) It is indeed possible to write it. But it is a bad idea to cram the whole trading environment into C#. It is better to write Expert Advisors in pure MQL, but it is possible to equip them with the necessary "trimmings" in c#.

3) Yes, it can be done.

4) It can be configured in different ways. It is made so that you need to specify the name of the form and the assembly in which it is located. I.e. now you can run one, two or five forms. There are no restrictions.