MQH File

 

Can anybody direct me to a link
that teaches how to create mqh file?
Or at least give me some simple example.
I did not find it in mql documentation.
Thanks for any possible help.

 
File > New > select 'Include (*.MQH)' > Next > name the file > Finish.

For your last example (https://www.mql5.com/en/forum/125019), you would have the following in your mqh file:
#import "GBSend.ex4"
   double OutPutBid(double A, double B);
#import 
And then instead of adding that to your main file, you would only need to add a #include statement to this mqh file (the file should be in the 'include' folder).
 
So, as I understand, the library SimpleLibrary.mqh
#property library
double OutPutBid(double A, double B)
{
double C;
C= A+B;
GlobalVariableSet("AAA",C);
return(C);
}
imports to SimpleMQH.mq4
#import "SimpleLibrary.ex4"
double OutPutBid(double A, double B);
#import
);






I do not see the sense why to import library to mqh and then to EA. What is the role of mqh file?
 

In your terminal directory
c:\Program Files\MetaTrader 4\experts\include\stderror.mqh

Someimes you don't need make a library, just a definition.

 
Roger wrote >>

In your terminal directory
c:\Program Files\MetaTrader 4\experts\include\stderror.mqh

Someimes you don't need make a library, just a definition.

So, what is the point of having mqh aside from library.
What is the role of mqh file?
When I start new mqh file, I see it lets
import DLLs and Libraries.
When I use in the EA
#import "stderror.mqh"
#import
How can I see these errors in the EA?
Thanks.
 
 

An MQH file allows you to build your code in modular form. There are many routines that you may wish to use over and over. You can keep them in a separate files and still have it operate as part of you main EA without having to cut and paste it in each time.

I have found that it allows me to be far more organised in my coding. I sometimes have up to 5 MQH files in an EA if it is a complex project. I would have a files for just my variables, another for the bulk of the initialisation functions(4/5 digit brokers/Magic Number assignment, etc) and yet another that detects my trade entry and another that deals with trade execution and another that deals with trade exits and another that contains all the error management.

This is an extreme example, but while building a complex EA, it is sometimes usefull to just click a tab at the top of the Metaeditor and jump straight to the section I wish to deal with rather than scroll up and down through hundreds of lines of code.

I will probably condense most of it into one MQH at the end of the day and have a neat concise EA that simply calls the various routines from the MQH.

 
Thank you, guys.
May i ask you how can i display errors (of stderror.mq4) in this simple EA
#import "stderror.mqh"
#import

int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
  //Condition
  Comment("Error ");
return(0);
}
Thank you.
 
Anybody can help, please?
 
Brygada:
May i ask you how can i display errors (of stderror.mq4) in this simple EA

GetLastError() function returns error code of last occurred error (https://docs.mql4.com/check/GetLastError). The error codes are defined in stderror.mqh, or u can see them here -> https://docs.mql4.com/constants/errors.

You can use ErrorDescription() function from stdlib.mqh to display a description of the error.

 
Brygada:
I do not see the sense why to import library to mqh and then to EA. What is the role of mqh file?

In the example above there is really no point. But imagine u had 20 functions in the library. U use only some of those in your current project, and u have 3 other projects that uses some or all of the functions. Wouldn't it be much easier to add a single #include statement to each project instead of adding the prototypes of 20 functions... It's more convenient.

Reason: