MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Buy Latest Technical Indicators in MetaTrader Market

MQH File

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
130
Brygada 2010.04.06 10:37
 

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.

 
MetaTrader 4 on Linux

MetaTrader 4 on Linux

Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. Many home PC users prefer it to MS Windows series. Linux systems are widely used in smartphones and server hardware. In this article, you will find out how to work in MetaTrader 4 via one of the Linux versions - Ubuntu.

avatar
Moderator
2029
gordon 2010.04.06 10:58 #
 
File > New > select 'Include (*.MQH)' > Next > name the file > Finish.

For your last example (http://forum.mql4.com/31046), 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).
 
avatar
130
Brygada 2010.04.06 22:25 #
 
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?
avatar
2551
Roger 2010.04.06 22:59 #
 

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

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

 
avatar
130
Brygada 2010.04.06 23:23 #
 
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.
 
avatar
2551
Roger 2010.04.06 23:37 #
 
avatar
118
kennyhubbard 2010.04.06 23:41 #
 

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.

 
avatar
130
Brygada 2010.04.07 00:46 #
 
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.
avatar
130
Brygada 2010.04.07 03:17 #
 
Anybody can help, please?
avatar
Moderator
2029
gordon 2010.04.07 04:38 #
 
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 (http://docs.mql4.com/check/GetLastError). The error codes are defined in stderror.mqh, or u can see them here -> http://docs.mql4.com/constants/errors.

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

 
avatar
Moderator
2029
gordon 2010.04.07 04:42 #
 
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.

 
Back to topics list   | 1 2  

To add comments, please log in or register