Lesson 8 - Variables in MQL4

 

Hi folks!

I want to thank you all for your kind comments.

This is the eighth lesson. it's about MQL4 Variables, I hope you enjoy it.

And I hope to be a useful for all of you GREAT TRADERS.

Files:
lesson8.pdf  69 kb
 

I have a question.

What are the Ask, Bid, Bars, Close, Open, High, Low, Time and Volume?

Variables?

It was not mentioned in your lessons. May you describe about that?

What is the difference between Ask - Bid and other above mentioned variables?

Current bar is Bars = 0. Right?

And previous bar is Bars = 1.

And what is Bars = -1. Is it 10 or Is it the future bar?

 

What are the GlobalVariableCheck, GlobalVariableSet, GlobalVariableGet, GlobalVariableDel and GlobalVariableDeleteAll.

In which cases we are using that?

 

Some people using g for global variables only like

this:

int g_Lots;

void Function1 (int param1)

Is it still usable?

 
 
newdigital:
What are the GlobalVariableCheck, GlobalVariableSet, GlobalVariableGet, GlobalVariableDel and GlobalVariableDeleteAll. In which cases we are using that?

GlobalVariables are a special kind of variables which accessed in the MetaTrader client terminal level, so they are different form the global variables which you declare them in your code at the functions level (review the Scope section in Variables lesson).

I'll give you example of using GlobalVariables , Assume you have 2 EAs running in your client terminal and both of them want to Send Order (OrderSend() function), if they called the OrderSend() at the same time MetaTrader will raise an error, to solve this situation , you may write in your EAs a code like that:

while (GlobalVariableCheck("InTrade")) {

Sleep(1000);

}

GlobalVariableSet("InTrade", 1); // set lock indicator

res= OrderSend(....);

GlobalVariableDel("InTrade"); // clear lock indicator

Here the OrderSend() function will work only if the GlobalVariable InTradehas been set.

Note: You have to write this code in the both of the 2 EAs which are trading at the same time.

This is something called semaphoreand it's an example of using GlobalVariables.

 
newdigital:
Some people using g for global variables only like

this:

int g_Lots;

void Function1 (int param1)

Is it still usable?

Yes, this is a good programming practice, and it called Hungarian notation.

Hungarian notation is a naming convention in programming, in which the name of a variable (or function) indicates its type or intended use.

You prefixed every variable name with the first letter of the variable type, and that's what Hungarian notation mean.

 

codersguru,

I'd like to thank you for your efforts with the programming manual. I've worked on my own EA with the help of another and am taking an online class for programming and reading (when time permits). I've been able to see more of the overall pricture with your manual and get a better understanding of the EA programming method. This is really helping me to rewrite what I want to do next in my EA and has given me a better overall view of the programming method.

Thanks

cs

 

You're welcome!

traden4x:
codersguru,

I'd like to thank you for your efforts with the programming manual. I've worked on my own EA with the help of another and am taking an online class for programming and reading (when time permits). I've been able to see more of the overall pricture with your manual and get a better understanding of the EA programming method. This is really helping me to rewrite what I want to do next in my EA and has given me a better overall view of the programming method.

Thanks

cs

cs,

You're welcome!

I'm so happy to see my lessons help you (and the others).

I hope you find the the coming ones as good as the previous.

And the ebook that gathering all the lessons is on the road to you all.

 

hi codersguru,

one problem ( for me, not for you I hope)

How can I integrate an indicator which gives out a global variable

name of the global varaiable : "trend".

If Value = +1 should be possible a buy action

If Value = -1 should be possible a sell action

If value = 0 nothing should appear

How have I to define the global variable? ( like an indicator??)

And what have I to write in the long entry signal condition???

 

This lesson material is positively phenomenal! Many many thanks to the author.