help! include, library, and script! - page 2

 

You might use a script to open an Order to help semi-automate a manual trading strategy, an EA could make it fully automated. I use a script to create a particular type of Fib on a chart . . . it does it's job and finishes.

I have offline charts and they don't get ticks, but if I wan to run an "Indicator"on them I need them to have ticks . . .

I don't use Includes or Libraries . . . but I understand the principle behind them. If you have a standard function that can be used in all the EAs you will ever write then you can make it into an Include or library and rather than adding it directly to each EA you write by copy & paste you just add the link to the Include or Library file . . . it's not necessary but in larger projects it is good practice.

There is some info here you might not have read: https://docs.mql4.com// it has a few words on Script, Library and Included File

 

hi tob2011,

I have to apologize to you, here's the complete one, "script is executed immediately without waiting for a tick and automatically removed from a chart after script finishes its jobs" while EA is "executed with a tick and have to be removed manually from a chart". Since script is not dependent on tick and will be automatically removed, we basically use script for immediate result. For example if we place order manually (by press F9), we have to write in every data manually (lot size, take profit and stop loss level, etc). If we get requote, we may have to start all over again. By using script, script will do all the calculation and input data and handle any error that may occur - and not even showing order window (F9).

There plenty script in MT4. One of them is called trade, why don't you try it on demo account. This script will only open buy for 1 lot and not open sell. After using this 'trade' script, read journal log, it will tell you that MetaTrader has load 'trade' script on to a chart and then remove it (after script finish it's job).


Include and library is a function(s) written in separate file. Got that ?. I'll write that when I have time :(


DLL stands for dynamic link library, it's library but involving programming with Windows OS (click here). Maybe we'll talk about dll later after library in mql4.

:D

 

RaptorUK and onewithzachy,

Thanks for your reply again.

Let me write down what I get from both of you.

1. script is a program intended for a single execution of some actions and is not run tickwise, but on request, so we can use it to perform actions like opening order or draw custom indicator in offline chart.

2. include and library are similar things, library is a set of custom functions containing programs, include are blocks of custom programs. They are used to store frequently used or shared programs which is used by different EA or indicator, right?

therefore:

1. except from script is not run tickwise but include and library are run tickwise, are they both perform similar function? (i.e. to run frequently used or shared programs)

2. if "The use of included files is more preferable than the use of libraries because of additional burden occurring at calling library functions", why and when should we use library instead of include?

3. can both three types of file be used by both indicator and EA?

4. Do "Libraries cannot start execution by itself" and "Scripts are not run tickwise, but on request" also means they cannot be executed by itself? how about include file? can it run by itself?

5. Does "run by itself" means "run independently", like indicator or EA?

6. For instance, if I'm going to code a trading system, and I have entry condition calculation and formula to calculate stop loss, does it means that I should put the entry condition calculation into include or library and put the calculation for stop loss to a script? Does it means that EA no need to run both part of calculation in each tick and therefore it can use lesser time to complete one round of running within a tick? Also, does it means that other programs can use these two calculations stored in script, include and/or library?

7. is it more secure and more difficult for others to decompile if I put codes in these three types of file?

8. I've read from the articles that people run calculations in excel or other programs, like SQL or JAVA, and use ddl to instruct EA to trades. Is it better than I put all codes in EA? What's the good and bad if I use the first method? Is there any difference on computer resources used, like cpu resources? Does calculation performed by MT4 use more resources then outside programs?

9. if these file cannot run by itself, how can they be "requested" to run? use icustom or other function?

10. I find in stdlib.mq4 that there is no init(), deinit() and start(), does it means that it does not run tickwise and cannot run by itself?

11. Also, I saw from some EAs that some codes are put under return(0) of start(), what's that means and why people put codes there? What's the advantage of coding like that?


regards,

tob2011

 
tob2011:

11. Also, I saw from some EAs that some codes are put under return(0) of start(), what's that means and why people put codes there? What's the advantage of coding like that?

It seems you have a lot to learn . . .

11. these are User Defined Functions

Most of what you are asking for is contained within the Book . . . for example, Functions scroll down to User Defined Functions. There is information about using Include files here: Structure of a Normal Program

 

Hi tob2011

EA, Indicator, and Script is MQL4 executable, meaning they can be run/executed. EA and Indicator need tick to run while Script does not need tick and run immediately even on holiday/market close.

Include and library is NOT executable, but they contain function or program that can be run/executed. We need EA or Indicator or Script to run a function/program that reside inside an include/library.

When include/library is used in EA, or Indicator, include/library run tickwise. When include/library is used in Script, include/library is executed immediately.

So in many ways, include and library is different with EA, Indicator, or Script.

Would you please answer this coz this is important, do you know what user defined function is ?

:D

tob2011:

RaptorUK and onewithzachy,

Thanks for your reply again.

Let me write down what I get from both of you.

1. script is a program intended for a single execution of some actions and is not run tickwise, but on request, so we can use it to perform actions like - but not limited to - opening order or draw custom indicator in offline chart. Yes

2. include and library are similar things, library is a set of custom functions containing programs, include are blocks of custom programs. They are used to store frequently used or shared programs which is used by different EA or indicator or script, right? Correct

therefore:

1. except from script is not run tickwise but include and library are run tickwise, are they both perform similar function? (i.e. to run frequently used or shared programs) Read my reply above

2. if "The use of included files is more preferable than the use of libraries because of additional burden occurring at calling library functions", why and when should we use library instead of include? Portability, we can change the content of library without the need to re-compile the EA, Indicator or Script that use that library. If we change the content of include, we must re-compile the EA, indicator, or Sript that use that include so the change in that include has an effect.

3. can both three types of file be used by both indicator and EA? Script can not be used by Indicator or EA. Read my reply above

4. Do "Libraries cannot start execution by itself" and "Scripts are not run tickwise, but on request" also means they cannot be executed by itself? how about include file? can it run by itself? Read my reply above

5. Does "run by itself" means "run independently", like indicator or EA? Run by itself means no tick needed.

6. For instance, if I'm going to code a trading system, and I have entry condition calculation and formula to calculate stop loss, does it means that I should put the entry condition calculation into include or library and put the calculation for stop loss to a script? Does it means that EA no need to run both part of calculation in each tick and therefore it can use lesser time to complete one round of running within a tick? Also, does it means that other programs can use these two calculations stored in script, include and/or library? We can write any calculation in include and/or library, and other program (EA, Indicator, and Script) and use those calculation we made in include and/or library.

7. is it more secure and more difficult for others to decompile if I put codes in these three types of file? Nope.

8. I've read from the articles that people run calculations in excel or other programs, like SQL or JAVA, and use ddl dll to instruct EA to trades. Is it better than I put all codes in EA? What's the good and bad if I use the first method? Is there any difference on computer resources used, like cpu resources? Does calculation performed by MT4 use more resources then outside programs? By using program outside MT to execute trading in MT, more resource is needed (processor, memory, etc), people do that because 1] they don't know how to create an mql4 program - so they use excel. 2] Converting other trading program not written in mql to execute trade in MT by using dll.

9. if these file cannot run by itself, how can they be "requested" to run? use icustom or other function?

For include, inside an EA, indicator or Script, we must have this code on top of the EA, indicator, or Script code

#include <This is my include program.mqh>

For library, inside an EA, indicator or Script, we must have this code on top of the EA, indicator, or Script code

#import "This is my library.ex4"
    string Function_Number_One (string data_1, string& data_2[]);

#import "user32.dll"
   int    MessageBoxA(int hWnd, string lpText, string lpCaption, int uType);

And inside a library, we also must have this on top of the code

#property library

And then we can use it's function that reside in include/library.

10. I find in stdlib.mq4 that there is no init(), deinit() and start(), does it means that it does not run tickwise and cannot run by itself? Read my reply above.

stdlib.mg4 is a library, stdlib.mqh is an include. stdlib.mqh - which is an include - is importing stdlib.ex4 - a compiled stdlib.mq4 - which is a library.

11. Also, I saw from some EAs that some codes are put under return(0) of start(), what's that means and why people put codes there? What's the advantage of coding like that? They are function that defined by user/programmer. They are frequently used programs/function, so instead re-writing the codes all over again, they just create and use that user defined function.

And that user defined function (UDF) is the one that we write in include or library.


regards,

tob2011

 

RaptorUK and onewithzachy,

First of all, let me say thank you again for both of you, especially for onewithzachy, who used lots of time to reply all my questions.

After that, I must say that, it seems most of what I understand before about these three types of files are not correct. Ok, from now on, please allow me to ask new questions again.

1. For what user defined function is, as explained by onewithzachy above, a function that defined by coder. They are put under return of start() for frequent use purpose. For instance:

start()

Profit(1,10,0);

total_profit = buy_profit + sell_profit;

return;

int buy_profit, sell_profit;

Void Profit(int side, int lot, int interest)

{

if( side = 1 )

{ buy_profit = ( bid - orderopenprice() ) * lot + interest; }

if( side = 2 )

{ etc }

}

return(buy_profit, sell_profit);

is that right?

2. is it the same if I put that user defined function under return of start() or put it into a script, library of include file, except that script is not tickwise and library and include are tickwise?

3. for real account trading, we won't trade on holiday or after market closed, so when will we use script?

4. "Script can not be used by Indicator or EA" - what's that means? Does it mean that I can trade with script independently without EA or indicator? I'm so sorry that I really confuse with this point. Please tell me more.

5. if I put open order command in EA, it will be executed tick by tick if needed. If I put it in script, it will be executed immediately if needed, right? By my understanding, quote from broker comes when a new tick comes. Is that means, if I use second method, script will use next quote from broker to open new order, if I use first method, EA will use next next quote from broker to open order? Therefore, I should use script instead of EA to execute an open order action?

6. " If we change the content of include, we must re-compile the EA, indicator, or Sript that use that include so the change in that include has an effect." - why is it important? If I want to re-compile an EA, I just need to open MetaEditor and press F5 once, then it can be done. Why is it important that Metaquote will need to create another type of file, library, to avoid this problem? Does it mean that it is good when there are lots of EAs or indicators to use that program? If yes, what's the advantage of using include? Why don't we just put all programs in library so that we don't need to re-compile every EAs and indicators later?

7. (somewhat is similar to question 5) if library or include is used by EA or indicator, they are tickwise, does it mean that, in this tick, if EA requests library to execute something, library will start to work when next tick comes? otherwise, what's the difference if they are executed by a script?

8. regardless of computer resources, is it faster in running speed that if I put analysis, especially if it includes many and multiple levels of loops in running, outside MT and only perform action, like open/close orders, in MT? in fact, an outside program like excel can be seemed as a "library" file of MT4 EA, script or indicator and is requested by dll, right?

9. "stdlib.mg4 is a library, stdlib.mqh is an include. stdlib.mqh - which is an include - is importing stdlib.ex4 - a compiled stdlib.mq4 - which is a library" - that means I have to prepare an include file in order to import a library file to an EA, script, or indicator?

9. by my understanding, if some people want to de-compile my program, he will need to obtain it first, by hacking to my computer or given by me. It maybe a stupid thought but, is it possible to run EA and its library file in separate computer's MT4 to reduce the chance for others to obtain the whole program by hacking into my computer (according to my IP)?

10. do you know is there a maximum limit of lines, or loops of an single program, or maximum limit on number of EAs, indicators that runs at the same time and computer can still work smoothly? is there a formula for calculation? Also, as MT4 is designed under XP environment, is running MT4 in XP better than in Win7?

regards,

tob2011

 

Hi tob2011,

Obviously you miss read my reply. Here, let me repeat that again. And please read these before continue reading.


1. EA, Indicator, and Script is MQL4 executable, meaning they can be run/executed. EA and Indicator need tick to run while Script does not need tick and run immediately even on holiday/market close.

2. Include and library is NOT executable, but they contain function or program that can be run/executed. We need EA or Indicator or Script to run a function/program that reside inside an include/library.

3. When include/library is used in EA, or Indicator, include/library run tickwise. When include/library is used in Script, include/library is executed immediately.

So in many ways, include and library is different with EA, Indicator, or Script.

- Don't mix script (an executable program) with include/library (a non-executable file) -


Please read this on MQL4 book about EA, Indicator and Script https://book.mql4.com/basics/programms . The book does NOT mention include/library because include/library is NOT executable.

And please also read this about User Defined Function (UDF), here https://book.mql4.com/basics/functions. It's useless explaining include/library if you don't understand UDF.


Please read and remember those before continue reading. coz it's useless asking the same question or explaining the same thing over and over again.

Attached is a sample, please study them. Before you asked any questions, first find the answer your self, they probably already answered

:D

 

Hi tob2011,

Try to answer your questions yourself by experimenting, before asking a questions.

:D

tob2011:

RaptorUK and onewithzachy,

First of all, let me say thank you again for both of you, especially for onewithzachy, who used lots of time to reply all my questions.

After that, I must say that, it seems most of what I understand before about these three types of files are not correct. Ok, from now on, please allow me to ask new questions again.

1. For what user defined function is, as explained by onewithzachy above, a function that defined by coder Exactly. They are put under return of start() - They can also put anywhere, as long as outside init(), start(), deinit() - for frequent use purpose Correct. For instance:

start()

Profit(1,10,0);

total_profit = buy_profit + sell_profit;

return;

int buy_profit, sell_profit;

Void Profit(int side, int lot, int interest)

{

if( side = 1 )

{ buy_profit = ( bid - orderopenprice() ) * lot + interest; }

if( side = 2 )

{ etc }

}

return(buy_profit, sell_profit);

is that right? See my attached example above.

2. is it the same if I put that user defined function under return of start() or put it into a script, library of include file, except that script is not tickwise and library and include are tickwise? They are not the same !, read my previous reply.

3. for real account trading, we won't trade on holiday or after market closed, so when will we use script? Anytime you want, including being offline.

4. "Script can not be used by Indicator or EA" - what's that means? Does it mean that I can trade with script independently without EA or indicator? I'm so sorry that I really confuse with this point. Please tell me more. Please re-read my previous reply and read the link I gave you above.

5. if I put open order command in EA, it will be executed tick by tick if needed. If I put it in script, it will be executed immediately if needed, right? Correct By my understanding, quote from broker comes when a new tick comes. Is that means, if I use second method, script will use next quote from broker to open new order Wrong, it will use last quote not new one. New quote come with new tick, script does NOT waiting for new tick, no new tick = no new quote. Script use last quote., if I use first method, EA will use next next quote from broker to open order? Therefore, I should use script instead of EA to execute an open order action? Use script for manual trading, use EA for automatic trading.

6. " If we change the content of include, we must re-compile the EA, indicator, or Script that use that include so the change in that include has an effect." - why is it important? Same reason like when you change some code in your EA, CI or Script If I want to re-compile an EA, I just need to open MetaEditor and press F5 once, then it can be done. Why is it important that Metaquote will need to create another type of file, library, to avoid this problem? Does it mean that it is good when there are lots of EAs or indicators to use that program? If yes, what's the advantage of using include? you've said this yourself "for frequent use purpose" Why don't we just put all programs in library so that we don't need to re-compile every EAs and indicators later? Yes that can be done, however, read 7bit explanation in forexfactory - I could not find an easy ways to explain that.

7. (somewhat is similar to question 5) if library or include is used by EA or indicator, they are tickwise, does it mean that, in this tick, if EA requests library to execute something, library will start to work when next tick comes? Correct otherwise, what's the difference if they are executed by a script? If being called it will executed immediately without waiting any tick.

8. regardless of computer resources, is it faster in running speed that if I put analysis, especially if it includes many and multiple levels of loops in running, outside MT and only perform action, like open/close orders, in MT? It depend on how fast this outside analysis program. In the end MT does the order executing in fact, an outside program like excel can be seemed as a "library" file of MT4 EA, script or indicator and is requested by dll, right? Not 100 % correct, a program is not a library. Excel is not an executable program.

9. "stdlib.mg4 is a library, stdlib.mqh is an include. stdlib.mqh - which is an include - is importing stdlib.ex4 - a compiled stdlib.mq4 - which is a library" - that means I have to prepare an include file in order to import a library file to an EA, script, or indicator? My apologize if you confuse with this. no need include to import library, read my previous reply on how to use include and library and see my attached example above.

9. by my understanding, if some people want to de-compile my program, he will need to obtain it first, by hacking to my computer or given by me. It maybe a stupid thought but, is it possible to run EA and its library file in separate computer's MT4 to reduce the chance for others to obtain the whole program by hacking into my computer (according to my IP)? Yes, you can send order via network to another EA and this EA send order to broker, it's similar to MT4 copy trader concept, google that.

10. do you know is there a maximum limit of lines, or loops of an single program, or maximum limit on number of EAs, indicators that runs at the same time and computer can still work smoothly? is there a formula for calculation? Number of EA depend on number of chart, there's discussion about maximum number of chart in this forum. Dunno for indy Also, as MT4 is designed under XP environment, is running MT4 in XP better than in Win7? Nopes. Smooth or not depend on calculation inside EA and Indy. Heavy calculation cost a lot. Use GetTickCount() to count how speedy your programs.

regards,

tob2011

 

Hi,

I'm now re-reading the book in MQL4. Would you please tell me:


If I put user defined function in library, when a new tick comes, how the priority is decided if several EAs request to execute it?

Thanks for your help.

tob2011

 

also,


Book explains that both EA and script are allowed to execute Trade action. On the other hand, if EA is able to execute Trade action, why and when will we use script to do it? just because script only do it once? Also, script will not wait for another tick to come in, if it is used to open order, which quote will it use? last quote or next quote?

If I have some codes to analysis the market, what's the best place I should put it in? indicator, EA or script?

Reason: