Include Files

 

I just want to clear something up about .mqh Include files.

Once I have compiled an EA that uses an Include .mqh file do I still have to distribute this .mqh file to all computers and MT4 's that use this EA or does the code of the EA now include the code of the .mqh files after compilation.

If the answer is Yes I still have to distribute the .mqh file and install it in the Include folder of all computers and MT4's how can I rather insert that code into the actual EA?

Will appreciate any help!

 

Well you can check it out yourself very easily: Compile the EA, rename the my.mqh and try to apply the EA - doe ist run?

If so it will run elsewhere too.

 
ernest02: does the code of the EA now include the code of the .mqh files after compilation.

Compiling doesn't change your code. Period. It didn't include it before, it doesn't include it after.

Compiling creates your executable. Period. The executable has nothing to do with your code.

 

Thank you for your assistance.

I would like to incorporate the code of the .mqh file rather into the main code of my EA. I have tried but get errors like "function can only be declared in global scope". Can you help me?

Here is the code in the .mqh file

double PipPoint(string Currency)
        {
                int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
                if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
                else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
                return(CalcPoint);
        }


int GetSlippage(string Currency, int SlippagePips)
        {
                int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
                if(CalcDigits == 2 || CalcDigits == 4) double CalcSlippage = SlippagePips;
                else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;
                return(CalcSlippage);
        }

and here is part of the code in my EA that uses that code:

int init()


        {
                UsePoint = PipPoint(Symbol());
                UseSlippage = GetSlippage(Symbol(),Slippage);
           
   }
 
I have tried but get errors like "function can only be declared in global scope". Can you help me?
The function must be put before or after init() not inside it.
 
I put the functions in the start() area but get the same message.
 
ernest02:
I put the functions in the start() area but get the same message.

Function cannot be put inside the start() also.


To be honest, your problem is an easy fix but just need to double check. I usually do like that.

 
If I cannot put the functions in either the init() or start() areas, where do I put it?
 
Just put it outside. Before or after, doesn't matter.
 
ernest02:

Thank you for your assistance.

I would like to incorporate the code of the .mqh file rather into the main code of my EA. I have tried but get errors like "function can only be declared in global scope". Can you help me?

Here is the code in the .mqh file

and here is part of the code in my EA that uses that code:

May be what you are looking for is 1) a compiled .mqh, that export(s) its (some) functions  2) one (several) EA(s) that import(s) the functions it needs.

Look in your reference of export in the index-tap search-field.

 
ernest02: If I cannot put the functions in either the init() or start() areas, where do I put it?
What part of
"function can only be declared in global scope"
was unclear? Global scope is outside of every function.