Download MetaTrader 5

please i have a probleme "print"

To add comments, please log in or register
georges sleimen
189
georges sleimen  

void OnTick()
  {
  double x;
  x=(1/3);

  Print("value =",x);
   }

the print value is 0. why????

honest_knave
Moderator
2342
honest_knave  

It is the way typecasting works.

Try this:

void OnTick()
 {
  double x;
  x=(1/3.);

  Print("value =",x);
 }

You can read more about it here - https://docs.mql4.com/basis/types/casting

Typecasting - Data Types - Language Basics - MQL4 Reference
Typecasting - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Typecasting - Data Types - Language Basics - MQL4 Reference
georges sleimen
189
georges sleimen  
honest_knave:

It is the way typecasting works.

Try this:

You can read more about it here - https://docs.mql4.com/basis/types/casting

thank you very much
georges sleimen
189
georges sleimen  

can I have one more question please

void OnTick()
  {
char   c1=1,c2=3;
//--- First example
   double d2=c1/c2+0.3;
   Print("resultat = ",d2);

resultat = 0.3

why?

honest_knave
Moderator
2342
honest_knave  

Division happens before addition... https://docs.mql4.com/basis/operations/rules

1/3 = 0

0 + 0.3 = 0.3

Try this:

void OnTick()
  {
   char   c1=1,c2=3;
   //--- First example
   double d2=c1/(c2+0.3);
   Print("resultat = ",d2);
  }
Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
  • docs.mql4.com
Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
georges sleimen
189
georges sleimen  
honest_knave:

Division happens before addition... https://docs.mql4.com/basis/operations/rules

1/3 = 0

0 + 0.3 = 0.3

Try this:

yes I know the basic of math but I solved the prob

can you look please

void OnTick()
  {
   char   c1=1,c2=3;
   //--- First example
   double d2=c1/double(c2)+0.3);
   Print("resultat = ",d2);
  }

now resultat is 0.6333333333333

honest_knave
Moderator
2342
honest_knave  

Your code doesn't compile... what answer are you expecting?

1/3. = 0.333

0.333 + 0.3 = 0.633


georges sleimen
189
georges sleimen  
honest_knave:

Your code doesn't compile... what answer are you expecting?

1/3. = 0.333

0.333 + 0.3 = 0.633


sorry there is a false bracket


double d2=c1/double(c2)+0.3);

yes 0.633

Alain Verleyen
Moderator
35111
Alain Verleyen  
georges sleimen:

sorry there is a false bracket


double d2=c1/double(c2)+0.3);

yes 0.633

It's not bracket, it's parenthesis or ...

Forum on trading, automated trading systems and testing trading strategies

Correct brackets/bracers {}

whroeder1, 2014.09.10 13:44


  1. ...
  2. Be aware of the different uses of the words brackets/braces
    CharacterUS EnglishUK EnglishIndia
    ()ParenthesesBraces, round brackets, curved brackets, oval brackets
    []BracketsSquare Brackets
    {}BracesCurly bracketsflower bracket
    <>Angle brackets (or chevrons)
  3. ...

honest_knave
Moderator
2342
honest_knave  
Alain Verleyen:

It's not bracket, it's parenthesis or ...



Alain Verleyen
Moderator
35111
Alain Verleyen  
honest_knave:

To add comments, please log in or register