0% found this document useful (0 votes)
5 views4 pages

MQL5 Language Basics Arithmetic Operators

The document provides an overview of arithmetic operations in MQL5, including addition, subtraction, multiplication, and division. It explains the use of increment and decrement operations on variables, highlighting the difference between prefix and postfix forms. Additionally, it includes code examples demonstrating these operations and their outputs.

Uploaded by

Abu Rashel Moni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

MQL5 Language Basics Arithmetic Operators

The document provides an overview of arithmetic operations in MQL5, including addition, subtraction, multiplication, and division. It explains the use of increment and decrement operations on variables, highlighting the difference between prefix and postfix forms. Additionally, it includes code examples demonstrating these operations and their outputs.

Uploaded by

Abu Rashel Moni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MQL5 Language Basics

/*

ARITHMETIC OPERATIONS

Arithme c opera ons include addive and mul plica ve opera ons

Arithme cs = is the mathema cs of numbers (integers, ra onal numbers,

real numbers, complex numbers) under the opera ons of

arithme c symbols (+,-,*,/)

Examples:

// k = variable

// 5 = constant

sum of variables = i = j + 5;

difference of variables = i = j - k;

changing of sign = x = -x;

product of variable z = x * y;

divisions quo ent i = x / y;

divisions reminder t = x % y; minutes = me % 60;

addi on of 1 to the variable value i++;

addi on of 1 to the variable value ++i;

subtrac ng of 1 to the variable value i--;

subtrac ng of 1 to the variable value --i;

NB: >>> increment and decrement opera ons are applied only to variables, they

cannot be applied to constants, eg. 5++;

>>> The prefix increment (++i) and decrement (--i) are applied to the
the variable right before this variable is used in an expression

>>> The post incerement (i++) and decrement (i--) are applied to the

variable right a er this variable is used in an expression.

*/

//EXAMPLES

double x = 100;

double a = x + 100;

double b = -x;

double c = x / 20;

double d = 108 % 20;

// double e = x++; // invalid expression

// x++; x--;

double f = ++x;

//+------------------------------------------------------------------+

//| Arithme c Opera ons.mq5 |


//| Copyright 2023, MetaQuotes Ltd. |

//| h ps://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2023, MetaQuotes Ltd."

#property link "h ps://www.mql5.com"

#property version "1.00"

//+------------------------------------------------------------------+

//| Expert ini aliza on func on |

//+------------------------------------------------------------------+

int OnInit()

//---

Print("sum of variables: ", a);

Print("change of signs: ", b);

Print("divisions quo ent: ", c);

Print("divisions reminder: ", d);

Print("ADD 1 to variable value: (post-increment) ", x++);

Print("ADD 1 to variable value: (prefix-increment) ", f);

//---

return(INIT_SUCCEEDED);

//+------------------------------------------------------------------+

//| Expert deini aliza on func on |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

//---

}
//+------------------------------------------------------------------+

//| Expert ck func on |

//+------------------------------------------------------------------+

void OnTick()

//---

//+------------------------------------------------------------------+

You might also like