Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Lessons
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-23-2005, 01:26 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Wink Lesson 4 - MQL4 Operations & Expressions

Hi folks,

I hope you enjoyed my last 3 lessons.

I didn't hear questions from you yet.
I don't think that everything 100% understood in my lessons.
so, Where are the questions?

I hope to hear you soon.

Download this lesson & Enjoy it.
Attached Images
File Type: pdf Lesson4.pdf (100.8 KB, 4078 views)
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm

Last edited by forexts : 11-07-2005 at 08:42 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-30-2005, 08:30 PM
newdigital newdigital is online now
Administrator
 
Join Date: Sep 2005
Posts: 15,164
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
I want to ask about arithmetical operators.

1. It is written the following:
A = B + C, with description that add A to B and assign the result to C.
Is it mistake?
The same with A = B - C.

2. And I do not understand A = A % C, with description: A is remider of division of B on C(ex: 10%2 will produce 0).
I simple do not understand 10 % 2 = 0 and 10 % 3 = 1.
May you explain? :confused:

3. It was mentioned that we can not write as:
A=(B++)*5
we must write: :confused:
A++;
B=A*5


May be the following:
B++;
A=B*5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-30-2005, 08:41 PM
newdigital newdigital is online now
Administrator
 
Join Date: Sep 2005
Posts: 15,164
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
And the other 3 questions.

1. May you explain
A %= B;
Because I do not understand A = A % B
as well.

2. And
A >>= B
Is it
A is greater or equal B ?

3. A += B
it is A = A + B
isn't it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-31-2005, 01:59 AM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
The remainder operator

Quote:
Originally Posted by newdigital
I want to ask about arithmetical operators.

1. It is written the following:
A = B + C, with description that add A to B and assign the result to C.
Is it mistake?
The same with A = B - C.
It’s a mistake. It would be:
A = B + C; "Add B to C and assign the result to A."
A = B - C; "Subtract C from B and assign the result to A."
I have updated the lesson , please donwload it



Quote:
Originally Posted by newdigital
2. And I do not understand A = A % C, with description: A is remider of division of B on C(ex: 10%2 will produce 0).

May you explain? :confused:
The remainder operator works by dividing the first number by the second number for the first integer results and then returns the remaining number.

For example:
10%5=0
This is because if you divide 10 by 5 you will get 2 and there no remaining value, so the remainder is 0.
10%8=2
This is because if you divide 10 by 8 you will get 1 (1*8=8), so the remainder is (10-8 = 2).
100%15=10
This is because if you divide 100 by 15 you will get 6 (6*15=90), so the remainder is (100-90=10).
What about 6%8?
It will be 6 because if you divide 6 by 8 you will get 0 (8*0=0), so the remainder is (6-0=6).

Quote:
Originally Posted by newdigital
3. It was mentioned that we can not write as:
A=(B++)*5
we must write: :confused:
A++;
B=A*5


May be the following:
B++;
A=B*5
The rule is "You can’t combine the increment and decrement operator with other expressions.".

So you can't write:
A=(B++)*5;
or
B=(A++)*5;

But you can write:
A++;
B=A*5;

And
B++;
A=B*5;


How is it work?
Let’s take a live example:
int A=1; //set A to 1
int B;
A++; //increase A by 1, now A=2
B=A*5 //which means B=2*5
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-31-2005, 02:06 AM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow Answers

Quote:
Originally Posted by newdigital
And the other 3 questions.

1. May you explain
A %= B;
Because I do not understand A = A % B
as well.
A %= B; means A = A % B;
Let’s assume that A = 10 and B = 4 then
A=10%4; //which will produce 2, so now A=2.


Quote:
Originally Posted by newdigital
2. And
A >>= B
Is it
A is greater or equal B ?
No, ">>=" is the Left Shift Assignment operator which shifts the bits of the left hand value left by the number of bits specified in the right hand value. (You will rarely use this operator).

The Greater Than or Equal operator is ">=" (only one Angle bracket).


Quote:
Originally Posted by newdigital
3. A += B
it is A = A + B
isn't it?
Yes, A += B; is equal to: A = A + B; and means Add B to A and assign the result to A.
For example if we assumed A=5 and B=10 then:
A+=B will equal to A=10+5 then A=15 now.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-31-2005, 06:54 AM
forexts's Avatar
forexts forexts is offline
Administrator
 
Join Date: Sep 2005
Posts: 290
forexts has disabled reputation
Quote:
Originally Posted by codersguru
A %= B; means A = A % B;
Let’s assume that A = 10 and B = 4 then
A=10%4; //which will produce 2, so now A=2.




No, ">>=" is the Left Shift Assignment operator which shifts the bits of the left hand value left by the number of bits specified in the right hand value. (You will rarely use this operator).

The Greater Than or Equal operator is ">=" (only one Angle bracket).




Yes, A += B; is equal to: A = A + B; and means Add B to A and assign the result to A.
For example if we assumed A=5 and B=10 then:
A+=B will equal to A=10+5 then A=15 now.

Left shift is not a very interesting operation for traders.

It's a binary operation used for system computing.

For example if you have 32 (In binary = 00100000), and Left Shift it ... you get 00010000 (Move the numbers an item to the left). So ... you would get 16.

As binary is a power of 2.

Left Shift .... is very similar to divide a number by 2
Rigth Shift is very similar to multiply a number by 2.

I tell 'very similar' because according to the way of store numbers and store the sign of the number ... it's not exactly the same.

Anyway, you will never use it.

Last edited by forexts : 10-31-2005 at 06:56 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-31-2005, 06:59 AM
forexts's Avatar
forexts forexts is offline
Administrator
 
Join Date: Sep 2005
Posts: 290
forexts has disabled reputation
Operator %

Operator % = Remainder

Description taken from wikipedia.
The remainder for natural numbers

If a and d are natural numbers, with d non-zero, it can be proved that there exist unique integers q and r, such that a = qd + r and 0 ≤ r < d. The number q is called the quotient, while r is called the remainder. The division algorithm provides a proof of this result and also an algorithm describing how to calculate the remainder.



Examples
  • When dividing 13 by 10, 1 is the quotient and 3 is the remainder, because 13=1×10+3.
  • When dividing 26 by 4, 6 is the quotient and 2 is the remainder, because 26=6×4+2.
  • When dividing 56 by 7, 8 is the quotient and 0 is the remainder, because 56=7×8+0.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-31-2005, 10:37 AM
newdigital newdigital is online now
Administrator
 
Join Date: Sep 2005
Posts: 15,164
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Ok. Now I understand.
We can not use our simple arithmetical knowledge.

A += B
is the A increasing on B.

A -= B
is A decreasing on B.

A = B%C
is the remainder from dividing B by C.

And I think A /= B
is
A = A / B.

And A = A + B
is valid because it is not arithmetic.
It is logic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 10-31-2005, 10:58 AM
forexts's Avatar
forexts forexts is offline
Administrator
 
Join Date: Sep 2005
Posts: 290
forexts has disabled reputation
Quote:
Originally Posted by newdigital
And A = A + B
is valid because it is not arithmetic.
It is logic.
It's arithmetic.

int A=12;
int B=6;

A = A + B; // --> A = 12 +6;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 10-31-2005, 11:18 AM
newdigital newdigital is online now
Administrator
 
Join Date: Sep 2005
Posts: 15,164
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
It is arithmetical operations but it is logic.
In arithmetic if
A + B so it should be C already.
It should not be the same A (the same value).

Because if we are increasing A on B assigning the result to A so
A will be increasing on B all the time. Every second A will be increasing on B without any stopping. It means A plus B is equal A (the same A?) so plus B once again (because of A plus B) is equal A (an other A) which should be added to B and so on.

May be during the coding everything will be clear.

But I have a question.
In Relational operators A == Bi;
It means true if A equal B else false.

Is it necessary to have i after B?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 3 - MQL4 Data types codersguru Lessons 20 05-18-2007 03:55 AM
mql4 tutorial - Where is Lesson 1, etc.? ftsdPadawan Metatrader 4 mql 4 - Development course 2 01-15-2007 08:36 PM
Lesson 8 - Variables in MQL4 codersguru Lessons 11 09-15-2006 01:06 PM
Lesson 9 - Preprocessors codersguru Lessons 7 05-18-2006 08:26 PM
Lesson 7 - Functions codersguru Lessons 2 11-02-2005 03:32 PM


All times are GMT. The time now is 08:18 AM.