IN OUT like in C#

 

Who knows How can we solve the problem?

//Exist in Header1

void Func1(int& iNum1)

{

iNum1=2;

}

//----------------------

Main Program

start()

{

int var1=5;

Func1(var1);

Alert(var1);

}

//

So how can we solve ? we want 2 but naturally it is 5. also we don't want to use static variable in the header file.

 

"we want 2 but naturally it is 5"

fwiw - Func1() loads by reference as u use int&, so it loads value of 2 into memory of var1.

the Alert will show 2

.

2008.11.02 10:13:07 _quicky EURJPY,M30: 2
2008.11.02 10:13:07 _quicky EURJPY,M30: Alert: 2
.

void Func1(int& iNum1)
{
  iNum1=2;
}
int start()
{
  int var1=5;
  Func1(var1);
  Alert(var1);
  Print(var1);
}

maybe i not understand wat u after...

 
fbj:

"we want 2 but naturally it is 5"

fwiw - Func1() loads by reference as u use int&, so it loads value of 2 into memory of var1.

the Alert will show 2

.

2008.11.02 10:13:07 _quicky EURJPY,M30: 2
2008.11.02 10:13:07 _quicky EURJPY,M30: Alert: 2
.

maybe i not understand wat u after...

Func1(...) exists in the Header file and not on the main program, naturally if I put Func1(..) in the main program, so it is OK. but as a matter of fact my program exceed more than 5000 line of code, and the editor of MT4 is not like visual studio 2005 or 2008, so I have to separate lots of code in DLL and header file for decreasing .

 

"so I have to separate lots of code in DLL and header file for decreasing"

?? do u mean that DLL are NON-MQL4 compiled files?

.

please illuminate me - is below wat u mean?

u talking MQL4 source or 'another language' source...

.

Best 2 u

.

#include

The #include command line can be placed anywhere in the program, but usually all inclusions are placed at the beginning of the source code. Call format:

#include <file_name>
#include "file_name";

Examples:

#include <WinUser32.mqh>
#include "mylib.mqh"

Preprocessor replaces this line with the content of the file WinUser32.mqh. Angle brackets mean that the WinUser32.mqh file will be taken from the default directory (usually terminal_directory\experts\include). The current directory is not searched.

If the file name is enclosed in quotation marks, the search will be performed in the current directory (where the main file of the source code is located). The standard directory is not searched in.

"

.

external functions

"

The type of external functions defined in another component of a program must be explicitly described. The absence of such a definition may result in errors during the compilation, linkage, or execution of the program. While describing an external object, the keyword of #import must be used with the reference to the module.

#import "user32.dll"
  int     MessageBoxA(int hWnd ,string szText,string szCaption,int nType);
  int     SendMessageA(int hWnd,int Msg,int wParam,int lParam);
#import "lib.ex4"
  double  round(double value);
#import

Import can be used to easily describe functions called from external DLLs or compiled EX4 libraries.

Pointers to variables can be passed to imported dll functions. Data of the string type are passed as a pointer to the corresponding memory block (one should keep in mind that internal representation of string data consists of two parts: the memory block length and the memory block pointer). If there is a need to pass data of the int or double type, then the one-dimensional array of the corresponding type should be passed by reference as a parameter.

Example:

#import "some_lib.dll"
  void    PassIntegerByref(int& OneInt[]);
#import
int start()
  {
   int array[1];
//...
   PassIntegerByref(array);
   Print(array[0]);
//...
  }
"

.

.

below is, for all purposes, identical to my first example and produces 2

2 separate source code files. first one contains Func1() and second one contains main body which compiler given.

but... i bet this is not wat u on about is it?

//below is in separate file
//
//Header1.mqh
//
void Func1(int& iNum1)
{
  iNum1=2;
}

//below is in separate file
//
#include <Header1.mqh>

int start()
{
  int var1=5;
  Func1(var1);
  Alert(var1);
  Print(var1);
}

.

i persist with the #include possibilities... ;)

.

.

i got over 12,000 lines shoved into below .mqh's... so wat diff make? can have 1 or 50000 lines, #include is very handy.

below is one of my EA build files. this is top level compile file. this all has + some comments...

.

//
//Build stub -
//
#include <stderror.mqh>
#include <stdlib.mqh>
#include <eaDefines.mqh>
#include <eaVariables.mqh>
#include <eaErrorHandler.mqh>
#include <eaTradeOps.mqh>
#include <eaTools.mqh>
#include <eaStopLoss.mqh>
#include <eaEntryExitDecision.mqh>
#include <eaFiles.mqh>
#include <eaLog.mqh>
#include <eaTrace.mqh>
#include <bodyEA-5.mqh>

 

Dear fbj,
Fisrt of all, special of the most special thanks for your last quick response. and also thats my great proud that a professional programmer is replying me.
What you notice me : [

below is, for all purposes, identical to my first example and produces 2

]
Unfortunately I wrote the code, but the result is not like yours.
//---------------------------------------MyLib1.mq4
#property library
void Func1(int& iNum1)
{
Alert("I am In Func1 and should give you Number Two");
iNum1=2;
}
//------------------------------------------MyHeader.mqh
#import "MyLib1.ex4"
void Func1(int& iNum1);
//-------------------------------------------------TheMain.mq4
#include <MyHeader.mqh>
int start()
{
int var1=5;
Func1(var1);
Alert(var1);
return(0);
}
//-------------------------------

Can you help me that what's wrong with that?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

u nice person... please no that i jus wanna help, not look pro or any stuff - i learn all time and one way i do is by trying to answer posts on forum. i make fool of self all time. i get shouted at too but i also learn and sometimes give ok help too ;)

.

may i say that u making this way too C like...

not need libs and imports and all that stuff if just want to kinda 'data hide' source code because much codes are not really needed to look at all times are they? gets in way of main trading code logics... so u just do as u doing and make many mql4 source code files - BUT must be in ...\experts\include AND be type .mqh

then u not need lib, import and stuff.

.

Please, take look at attached files - i not able show i guess, so u have looksee and having placed in correct dirs, compile TheMain.mq4 and in Terminal expand Scripts in Navigator and do the double clicking on TheMain - i hope this way clearer ;)

1) Header1.mqh ( stored in ...\experts\include )

2) TheMain.mq4 ( stored in ...\experts\scripts ) - but could be in ...\experts\indicators or if an EA then ...\experts

.

2008.11.02 13:50:52 TheMain GBPUSD,M5: uninit reason 0
2008.11.02 13:50:52 TheMain GBPUSD,M5: Alert: 123456
2008.11.02 13:50:52 TheMain GBPUSD,M5: loaded successfully
2008.11.02 13:50:13 Compiling 'TheMain'
.

maybe actual files used is better example - forum input is hard at times - :)

Files:
header1.mqh  1 kb
 

not 'get' how atch >1 file...

edit

oh boy, i just learn how attach >1 file.

see wat mean? i learn doin this forum stuff too :o)

Files:
 

Dear fbj, Thank you .

Unfortunately if we write the code in the .mqh file,

there is two problem [Maybe not be problem for you]
1- All the code in mqh files will be translate uniqulely in the the Main file by metatrader compiler,
so after decompiling the .ex4 it can be more easily cracked. apparently the security will be weaker.
2-May be,some functions has been written in VC6 and changed to dll, so we can not treat them like codes existing on .mqh.[like the example that I show you in the last post.]

but finally, thank you.
 

1 - yes, but all depends if 'public' EA or 'private' EA. security is maybe more important if public program - so u must search this site then. many, many info items on this.

do peoples really waste much energies in reverse engineering? oh well, their path i guess. imho, source code is much more than pure language syntax ;)

i big fan docs... many not. all personal i guess - unless got BIG Boss breath down neck shout "follow in-house standards... or else!" - lol

2 - ok, my final notes can only say following cuz stuff i do is 'private' and i not need (1) consideration and all functunality i need can be hacked by sometimes muchly creative? MQL4 syntax use... :)

MT is no slow coach - and developers of '5' say vast speed increase, so i not see code size as issue. imho -:)

.

ref: MQL4 Reference - Basics - Variables - Formal parameters
"..Parameters can be passed by reference only within one module, such possibility being not provided for libraries..."
.
"..Unlike simple parameters, arrays can be passed by reference into library functions, as well..."
.
i read above that simple scalar actuals only pased 'by value' and that array actuals can be passed 'by ref'
.
above may explain why ur original .ex4 lib,import stuff not mod caller memory. fwiw, i read somewhere that [i think] each .ex4 program/compiled unit/module has own address space so EA global scoped decs only global to a compile unit.
also, arrays, by their nature are diff beasts not least cuz passing array element by element can take time if [manyElements]... so easier pass caller memory address of array.
.
.
ref: MQL4 Reference - Basics - Variables - External functions definition
"..If there is a need to pass data of the int or double type, then the one-dimensional array of the corresponding type should be passed by reference as a parameter.."
.
not sure must do for all scalars or only if wanna emulate scalar actual as 'by ref'.
not use, not take time to play, no need (yet)

good trades ur way many!

 
Hello friends.
I have just registered me. I am a "novice" in trading, as you say, but I took a year studying the issue and create a solid trading system.

I'm learning the automated trading, but I don't know to use well the program yet.

I want to create alerts from MetaEditor, but I can not open it. It appears programing window, but not the editor window alert, in which only need to get the data.

I want to create an alert to notify me when the price reaches a certain value.

how can I do?

A greeting.