Limitations of a script.mql5

 

Hi there,


      I would like to write a service (not a expert advisor or something bound to a chart) that uses a AppDialog class. Is there some limitation on using windows and panels objects in services? I was trying to adapt this tutorial putting all I can on OnStart function (as you can see in the snippet below), but I wasn't able to reach to any result. Sometimes MT5 freezes. What do I need to do to create a window in a mql service? I wasn't able to use printf propely too.

#property copyright "."
#property link      "?"
#property version   "1.00"
#property service
#include <Controls\Dialog.mqh>

CAppDialog AppWindow;

int OnStart()
{
   AppWindow.Create(0,"AppWindow",0,20,20,360,324);
   AppWindow.Run();
   return INIT_FAILED;
}
How to create a graphical panel of any complexity level
How to create a graphical panel of any complexity level
  • www.mql5.com
The article features a detailed explanation of how to create a panel on the basis of the CAppDialog class and how to add controls to the panel. It provides the description of the panel structure and a scheme, which shows the inheritance of objects. From this article, you will also learn how events are handled and how they are delivered to dependent controls. Additional examples show how to edit panel parameters, such as the size and the background color.
 
AnarcoPhysic: I would like to write a script (not a expert advisor or something bound to a chart) that uses a AppDialog class. Is there some limitation on using windows and panels objects in scripts? I was trying to adapt this tutorial putting all I can on OnStart function (as you can see in the snippet below), but I wasn't able to reach to any result. Sometimes MT5 freezes. What do I need to do to create a window in a mql script? I wasn't able to use printf propely too.

  1. Scripts are also bound to the Chart, just like Indicators and Expert Advisors.
  2. If you exit or return from your Script, then all and every Class Object will be removed via the destructor method, and that includes the "CAppDialog" objects.
  3. You say you are following the tutorial, but the tutorial mentions Indicators and Expert Advisors for a reason, because Scripts can't handle the "OnChartEvent()" event handler, which is needed for the handling of events for the "CAppDialog" object.
 

Thank you for help, Fernando Carreiro. Your help is appreciable and valuable to me. Yet, I would like to comments some points...

1. Consider this quote: "Service is a program that, unlike indicators, Expert Advisors and scripts, does not require to be bound to a chart to work.". This is the point I want to reach out!

2. Like I supposed :-)

3. Ok... Scripts only work in OnStart event. In the snippet, I didn't add the OnChartEvent "commands" from the tutorial. I've just instantiate a object window, created a window and let it running... and this didn't work as expected. Worse, MetaTrader5 has frozen sometimes!


But, according you've wrote, I can create windows, panels and other friendly user interface elements via script, right? I wil keep trying. Muito obrigado pela tua ajuda!

 
I just realize: the name is not script but service. I'm updating my question. I want to create a separated window by a service in Mql5. Sorry for this mistake.
 
AnarcoPhysic: I just realize: the name is not script but service. I'm updating my question. I want to create a separated window by a service in Mql5. Sorry for this mistake.

Scripts and Services are two different things. Script is bound to Chart and Service is not bound to anything.

However, both of them can't handle Chart Events (ie. OnChartEvent()" event handler does not work on them).

Also, since a "service" is not bound to any Chart, where would the "CAppDialog" appear then?

As far as I know all the standard library panels and dialogs need to be bound to a chart. This is because they are created with Graphic Chart Objects.

Documentation on MQL5: Object Functions
Documentation on MQL5: Object Functions
  • www.mql5.com
Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro:

Scripts and Services are two different things. Script is bound to Chart and Service is not bound to anything.

However, both of them can't handle Chart Events (ie. OnChartEvent()" event handler does not work on them).

Also, since a "service" is not bound to any Chart, where would the "CAppDialog" appear then?

As far as I know all the standard library panels and dialogs need to be bound to a chart. This is because they are created with Graphic Chart Objects.

Ok... I was expecting to be able to create and work on a separated window. This isn't possible, isn't it?

Thank you for you helping!

 
AnarcoPhysic: Ok... I was expecting to be able to create and work on a separated window. This isn't possible, isn't it?

Much like Windows Service, that runs in the background processing data but not actually interacting with the user, here too a MetaTrader 5 Service is for processing data without interacting with the user or displaying visual information.

Reason: