Complete MQL Newbie Manual - page 3

 
8284 wrote >>

Oh CB, Oh CB !

You are a tough one. You really dont want to hold my hand through this. This is the same book written in greek, latin and mars speak that I fled from. Granted there is no way one can become proficient at a profession without learning the terminology but.....

You remind me of my logic lecturer Dr Otakpor (by logic I mean under philosophy). You had better never ask him a question if you have no idea of what you were asking. CB, the book on arrays is quite technical to me (it was my first effort at coding). I have a vague idea of what its about but not full understanding. I take this as a challenge however!

Im going to look for that little "..a" that will turn my "ah.." to "aha".

Im going to read up, and write up and then give you what I know on arrays (actually its their applications I need to know most).

The only thing is that this would result in a very long post. There are peices of code that I see arrays being used [] but I dont quite get the logic. I was hoping that if it was explained to me, I wouldnt have so many questions (kind of like a missing peice of the puzzle).

You have challenged me and I think its good for my development, however Id beg you to go just a wee bit softer on me cos Im scientifically disabled. My background is in the arts. When I talk with the ladies, they say I talk like a poet. I only hope I dont code like one!!!

Seriously, no sleep for me today, within 24 hours, Ill be back with my understanding of arrays. I hope you will correct me where Ive gone wrong, and help me understand the application of arrays to programming.

Oh CB, Oh CB !

Just by the way my three best lecturers ever were Dr Otakpor, Barr Richard Idubor, and Barr Bob Osamor !!!

Dr Otakpor (taught Logic and Philosophy ) brought out the best in his students by countering their questions with his own questions designed to make them answer their own questions.

This made the whole thing interactive. If you were stuck, he'd prod you gently, hint, insinuate till you got the answer!

If you had no idea, hmm... different ball game!

 

Is your question more about WHY you'd use an array rather than HOW?

If so, then, from my perspective an array is a neater way of storing a set of instances of the same variable, each instance being able to be found by describing its location.

As an example, if you wrote an application which implemented a very simple cypher where A=1, B=2, C=3 etc, you could store the letters of the alphabet in a 1-dimensional (1x26) string array and locate each letter by substituting in the number. If (as a way-out example) you wrote an EA which stored the Ask and Bid prices as of the first tick subsequent to 3 minutes past each new hour and stored these values on a rolling basis for the last 5 hours, then you could use a 2-dimensional (2x5) double array to accomplish.


CB

 
cloudbreaker wrote >>

Is your question more about WHY you'd use an array rather than HOW?

If so, then, from my perspective an array is a neater way of storing a set of instances of the same variable, each instance being able to be found by describing its location.

As an example, if you wrote an application which implemented a very simple cypher where A=1, B=2, C=3 etc, you could store the letters of the alphabet in a 1-dimensional (1x26) string array and locate each letter by substituting in the number. If (as a way-out example) you wrote an EA which stored the Ask and Bid prices as of the first tick subsequent to 3 minutes past each new hour and stored these values on a rolling basis for the last 5 hours, then you could use a 2-dimensional (2x5) double array to accomplish.

CB

Ok CB, my question is more focussed on the HOW than the WHY. I know why; for convenience. I understand most of what you wrote above but not all!

You went techno on me again, see in order to carry us along you need baby talk and patience. We will definitely make you proud but it will take a while. Bearing in mind that just about 3days back your above post wouldnt have made sense to me, I respectfully ask, what do you mean by "rolling basis"!

Im sure when you explain, Ill feel like hitting myself but now Im confused!

Anyway, I understand the why, but not the how.

Im working on an essay on arrays which Ill present here within the next 24 hours, and if I miss anything, I expect a correction. If not, I will be asking for the hows and whens of arrays!

Thanks a lot,

I appreciate your assistance!

 

Ok CB, Im ready with my essay. Im sure I made an error or two and Ill be glad to have this pointed out to me. For what its worth, I think in some way, I sounded a bit technical ( talking about initializing and declaring and other stuff). Writing this made me see things a bit differently, but then I also learnt from writing it anyway.

Im going to read up on multi dimensional arrays.

I would like your honest (and everybody elses) criticism of this.

If there is any newbie who benefited from this, Id like to hear from you as well.

Maybe Ill do an essay on functions as well, cos writing about these things further ingrain it in me!

 

What is an array?

To define an array may defeat the newbie cause, so it would be better to describe it. Afterwards anybody can look up its technical definition!

An array can be thought of as a group of similar data.
An example.
Population changes every year .

2004 population = 4
2005 population = 5
2006 population = 6
2007 population = 7
2008 population = 8
2009 population = 9 and so on.

If we were programming in mql4, to use this data, we could declare them as variables eg
int 2004pop = 4;
int 2005pop = 5;
int 2006pop = 6;
int 2007pop = 7; and so on till we get to 2009 or infinity

That can work but is pretty cumbersome. This is where arrays come in.
The whole population data is an array.
To use arrays, you must first declare them.
They are declared using these "[ ]"
The first thing you have to do is to tell the program the type of array, whether it is an integer, a double, etc In our example it is an integer.
then you give the array a descriptive name, we will call it yearpop (short for year population)
After the descriptive name comes the brackets [ ], and inside the brackets we disclose what we are working with. In our case we have 6 data, so inside the bracket we put 6. Like this [6]
So far our array declaration looks like this
int yearpop [6];
we can go further to initialize the array by showing the values of the individual years like this

int yearpop [6] = {4,5,6,7,8,9};

Now mql4 starts its count from 0 instead of one. Here we have six values so instead of numbering from 1 to 6, mql4 numbers from 0 to 5. To get the value for the first year you have to use 0. For the second year, you have to use 1 and so on.

Look at this again
int yearpop [6] = {4,5,6,7,8,9} ;
The numbers 4,5,6,7,8,9 are called elements
The way you obtain the value of their elements is through their indexes (I hope Im not mixing things up here).
The indexes start from 0 to whatever (in our case 5)

So if you want to get the value for the first year, you use its index which is 0 like this

yearpop [0] // this would give you the first years population
yearpop [1]// 2nd years population.
In this way you could do lots of calculations conveniently (I guess)
for example
int overpopulation ;
overpopulation = yearpop[0] +yearpop [3] / yearpop [2];

How does this apply to mql4?
All I know so far is that in mql4, the current bar or timeframe or symbol or chart is always 0 or NULL.
Secondly mql4 counts backwards like this
543210 (from right to left).
As an example, on any chart ( sorry I cant do graphics)
the current bar, yet to be formed has the value of 0.
The bar imediately to the left of it has the value of one, and the next one to the left of that has the value of 2, and so on.
Immediately the bar which has the value of 0 is complete, it then takes on the value of 1, while the new forming bar takes 0 as its value and all the others shift accordingly.
Now suppose we had an array of the highest price levels for the bars (which we actually do), we could do something like this
double highlevels [200];// meaning we have 200 bars //worth of data in our array
There is actually a function in mql4 which can tell us the highs and lows of all the bars.
Suppose you wanted to know the difference between the 150th bar and the first bar.
If arrays were not available, you would have to declare, and possibly initialize at least 150 bars which would be very time consuming (CB, this is the why of arrays).
But since we have arrays, all we need to do is refer to them by their index numbers and do the calculation, like so
double difference;

difference = highlevels [0] - highlevels[149] // remember we are //counting from 0
the 0 is the currently forming bar. If we want to use a completed bar for the calculation, we use highlevel [1] instead.

So far, I have spoken only of one dimensional arrays. Its like a table with just one row.

Mql4 allows up to 4 dimensional arrays which is something I havent wrapped my head around yet.

 
Any one seen this yet?
 

Hey guys!

It's beautiful to see there have been posts in this thread after I disappeared. I went into the background working on a strategy with coaching from someone quite exceptional from this forum. Thus realistically speaking I am afraid I will not contribute much to this thread in the near future, at least not as 'in depth' as I did before :)

Meanwhile to all the newbies out there: keep up the passion for trading and remember if you help someone, help will find you when you need it :)

 
hi,

being a newbie I would like to ask if the built-in metastock function: ref() and stochmomentum() are implemented by some functions in metatrader

thnx
 
Huckleberry:

Hey Niko,

It's July 4th. You back from Turkey?

Regards

Huckleberry


For those who need to search through a document to find something in it, here is a PDF version of the entire Documentation...

It was converted to PDF from a Compiled HTML Help file...

 
cloudbreaker:

8284 - Good programmers strive for modularity - ie. creation of reusable building blocks which can be repeatedly plumbed together leaving the bare minimum of new code to be written with each new program. You must appreciate that this approach is suitable for training materials as well. There are many resources available to pick up the programming fundamentals you mention, as they are common across all technologies. Its not efficient to duplicate these learning materials across every programming language.


CB

Hi CB,

a lot has happened since the above. I have become much more proficient than I ever thought I could be in code writing (though there's still a lot of polishing to be done). I find your above quote to be so insightful (something I didn't appreciate at the time) .

I want to say thanks to you for your help (I also learnt from your help to others) and congratulations on your appointment as a moderator (very well deserved I think) !

Congratulations to Gordon and BB as well !