Putting common functions in a library

 

Hi, to make it easier to develop and work with the EA code I want to hide away simple standard functions that are fully finished. In the file I put only the functions, like this:

//+------------------------------------------------------------------+
//|                                                         aaaa.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net"

//-------------------------------
bool SpreadTooHigh()
   {
   RefreshRates();
   if (NormalizeDouble(Ask - Bid, Digits) > SpreadLimit) return(TRUE);
   return(FALSE);
   }
//-------------------------------
//-----------------------------------------------------------
void DrawVline (color Color, datetime time)
   {//Typical Use: DrawVline(Yellow, Time[i]); //DrawVline(Yellow, Time[0]);
   static int cntr;
   static double PrevVlineTime;
   if (time == PrevVlineTime) return(0);//Still on same bar
      ObjectCreate( "UpLine"+cntr, OBJ_VLINE, 0, time, 0);
      ObjectSet("UpLine"+cntr, OBJPROP_COLOR, Color);
      ObjectSet("UpLine"+cntr, OBJPROP_BACK,true);
      cntr++;
      PrevVlineTime = time;//Store bar time of last drawn line
   return(0);
   }     
//----------------------------------------------------------- 

And refer to it in the EA like this:

#include "aaaa.mq4"

//
extern int     TakeProfit = 330;
extern int     StopLoss = 950;

But when compiling the EA I get "'aaaa.mq4' - cannot open the program file C:\......

Dunno how to do this... should I use mq4 or mqh?

Where should the file be saved?

Should it be just saved, or compiled also?

If I try to compile it I get "variable not defined" for all the EA externals...twice for each of'em.

 

Hi DayTrder,

In MetaEditor, create it as .mqh (mq header) in include folder then compiled it, Drag and drop the .mqh from include to your EA. It will automatically will be written like this

#include <aaaa.mqh>

In MetaEditor, create it as .mq4 as a library then compiled it, Drag and Drop the .mq4 from MetaEditor's libraries to your EA. It will automatically will be written like this

#include "..\libraries\aaaa.mq4"

If you still have problem when compiling EA, don't install MT in C:\Program Files for Vista/7, and try again

:D

 

Hmmm. Spoonfeed me!

Tried D&D inside the editor, and between two explorer windows, no luck

 

In metaeditor go to file/new choose include file from the list.

copy paste the code from your existing mq4 file to the new include file then save it. dont bother trying to compile it, include files dont need compliling.

now in your EA do #include <filename.mqh>

Include files are not quite the same thing as libraries but when creating separate files for functions they do what you want to do. According to the documentation, the mql4 developers recommend the use of include files over libraries because libraries are heavier on resources at runtime.

 
DayTrader:

Hmmm. Spoonfeed me!

Tried D&D inside the editor, and between two explorer windows, no luck

This following script which is shipped with MetaEditor has include in it, try to compile it, if you have error when compiling, then you have to install MT4 somewhere else.

rotate_text, period_converter, trade.

:D

 

IMO The UAC issues with MT4 & Vista/Windows7 have been blown out of proportion.

Akthough Those versions of Windows do divert new files created by MT4 (and other installed programs) to a different directory known as "virtual store", Windows maintains a connection from ProgramFiles to that directory.

This means those diverted files are still "seen" by MT4 and can be accessed and used by MT4 as if they were still in the ProgramFiles/MT4 Directory even though they are not.

The only noticable difference is when you look in the Program Files/MT4 folder yourself for a new file created in MT4 and it is not there.

You should then click on the compatability files icon on the toolbar of the folder. Windows will then automatically change the folder being viewed to show the one in the virtual store directory and voila, the missing new file is there.

I have been using MT4 installed the default way in ProgramFiles on Vista for years without a problem.

If you install MT4 or any other program outside of ProgramFiles in an attempt to avoid UAC, not only is that pointless, but you are also losing protection UAC provides which helps prevent attacks on your installed programs by malicious software.

 
SDC:

IMO The UAC issues with MT4 & Vista/Windows7 have been blown out of proportion.

.......................

I'm on Xp...
 
onewithzachy:

This following script which is shipped with MetaEditor has include in it, try to compile it, if you have error when compiling, then you have to install MT4 somewhere else.

rotate_text, period_converter, trade.

:D

Would you please compile these script below in your MetaEditor and please report back if the compiling successful or not :

1. rotate_text.mq4

2. Period_Converter.mq4

3. trade.mq4

:D

 
SDC: IMO The UAC issues with MT4 & Vista/Windows7 have been blown out of proportion.

IMO, they are very real. Many hard to diagnose problems, even when UAC was disabled. Why fight it. Even IBFX installs in C:\InterbankFX_1-Click\

 
Yes but most of those problems, if not all, are due to the user not knowing how to use their operating system properly, if the user understands UAC they wouldnt have a problem.
 

What part of "hard to diagnose problems, even when UAC was disabled" was not understood. If the user understand UAC and runs the terminal properly is irrelevant - people STILL have UAC related problems. Stop fighting it. Mt4 is not completely compatible with UAC.

Reason: