A sub-workshop to fill in the FAQ (frequently asked questions). Let's help comrades! - page 5

 

I promised, I'll start with the simplest one)

Question: DoesMQL do arithmetic operations incorrectly? Why does dividing one number by another result in 0?

Answer:

Most likely, you've written an expression like

c = a/b;  // (1)

declaring variables a and b as integers:

int a,b;

In that case the MQL compiler interprets the "slash" sign as an "integer division" operation. Thus, even if before (1) appears in the code, the a and b are assigned any values, even noninteger ones, the variable c will still contain the answer " b fits into the number a so many integer times". This means that if before calculating (1) a was smaller than b, the result will be zero, regardless of the type of the variable c (it can be double in this example).

The described error is often the reason of the "incorrect" program behavior in the client terminal - " divide by zero " message in Expert Advisors' logs, non-displaying of one or more indicator lines in the terminal window, etc.

The solution to the problem:

Correct data type in variable declaration to the one corresponding to operations to be used:

double a,b;
 
Question: Why is 3 divided by 2 equal to 1 and not 1.5?

Alert(3/2);

Answer: The numbers 3 and 2 in this expression are integers. An integer is not divisible without a remainder. In order to get the result 1.5 you have to specify that the divisor is a floating point number:

Alert(3.0/2);

* * *

Question: Why does the expression not calculate correctly?

  double price=1.0; // Цена
  double point=0.0001; // Величина пункта
  double level=272.0; // Уровень в пунктах от цены
  double levelprice; // Значение цены уровня
   
  levelprice=price+point*level; // должно быть 1.0272
   
  if(levelprice==1.0272){
  Alert("Правильно");
  }
  else{
  Alert("Неправильно");
  }

A: Floating point variables have a limited number of decimal places. Because of this, values can get slightly distorted in the process of calculation. After calculating the expression, before comparing floating point numbers, they should be normalized to the required level of accuracy:

  levelprice=NormalizeDouble(levelprice,4);

  if(levelprice==1.0272){
  Alert("Правильно");
  }
  else{
  Alert("Неправильно");
  }

* * *

Question: How can I get the value of a custom indicator in my Expert Advisor?

Answer: For this purpose we have the iCustom() function.

* * *

Question: Where do I start learning MQL4?

Answer: There is a very detailed help guide builtinto MetaEditor (Open MetaEditor - Main Menu - View - Navigator - Dictionary).
The terminal comes with two Expert Advisors - MACD Sample and Moving Average, you can start with the analysis of their code.
In addition, on mql4.com there is a tutorial, a large number of articles and all kinds of code.
 
Q: Why is the value 0 even though it is definitely not 0?

  double point=0.00001; // Величина пункта
  Print(point);

A: Print() and Alert() only output four decimal places. If you need more, you should convert number double into string using DoubleToStr().
Print(DoubleToStr(point,5));
 

Q: The EA outputs a large number of messages with Print(), but more than half of the messages are missing somewhere in the tester.

A: During testing, if the output frequency is high, a part of messages is not printed to the "Log" tab, but all messages can be seen in the tester log file after testing. The file is in the tester/logs folder.

 
Thank you all, write again.
I will put together a FAQ only in the evening when I get there.
 

A suggestion to moderators, and those willing to provide minimal help.

You will agree that the forum is not enough for a structured presentation of the information, processing and search. I see the only way out is to create the most complete CHM manual, which can then be used to create a whole section on the forum.

To begin with, I have created a help structure.
It is divided into 3 large sections .

1) HOW. This section describes proactive answers to possible questions. For example, how to obtain indicator data, how to close all orders, etc. Also, this section contains a large systematized database of functions (Kim's function analogues). And most importantly - examples of completed primitive TOR with a detailed explanation of the code and comments. This is a very complex section, as it requires increased systematization of knowledge and analysis. Will be filled in the last place.

2) WHY. this section describes frequent questions of newbies (their examples were nicely demonstrated by alsu and integer in this thread)

3) WHERE. This section is mainly a link to where to look or where to find something. I won't describe it, see for yourself.
I'm attaching the archive of ready-made chm-structure (download at the bottom of the post)


1. Manual structure


2. Demonstrations - go to "Where: Useful Links -> MQL4 Tutorial".

Files:
mql4_4.zip  53 kb
 


The way forward is as follows:

1. Freelance contributors are needed to fill in the subsections. That is, in essence, they need thoughtful questions and detailed answers with a detailed explanation, a set of cross-references, etc. (the post template that is suggested on the first page of the FAQ topic. (according to that post template offered on the first page of the FAQ topic).

2. All questions created for a subsection are collected by the curator for that subsection (1-2 people). They handle them, bring them into a common style and form a cross-reference as appropriate This will have each subsection of the owner, and will not mess up the database will be one style and answer pattern.
For example, the Where section is divided into 4 subsections: Questions on the tester, the terminal, the forum, and useful links . There would be enough 1 person for each subsection. They will be fully engaged in sorting out the incoming knowledge base from freelancers, which they deem necessary, as well as all suggestions that may come from other members of neighboring sections. And of course they themselves should actively participate in filling the database and creating questions.

3. As filling subsections - they are transferred to the collector (such as me). It is necessary to collect them in one file chm and keep them all in one style. Create additional cross-references, index, add keywords for search queries.

Sub-sections can be re-sorted or expanded upon the suggestion of the curator and agreement of the new structure with the assembler.

Bottom line:
Participants: Welcome to our hut. :) If you'd like to be a sub-section curator and those who already have something to contribute, feel free to post-answers here.
Moderators: There will be a lot of material. Please do not allow discussion and distracted, empty posts in this thread. It will also be necessary to delete participants' posts after the post has been moved to the common base, to facilitate the work of the section.
Curators: The help file is created in WinCHM 4.17 (for those who need it, contact me). Requirements for file names and location:
- folder structure must exactly repeat the structure of help
- all names of files/folders must be given only in English in meaningful phrases
- example of current base, which "compiles" WinCHM in archive

Files:
chm4_2.zip  19 kb
 

sergeev:

...


1) HOW. This section describes anticipatory answers to possible questions. For example, how to obtain indicator data, how to close all orders, etc. This section also contains a large systematised database of functions (Kima, etc.). And most importantly - examples of ready made primitive TOR with a detailed explanation of the code and comments. This is a very complex section, as it requires increased systematization of knowledge and analysis. Will be filled in the last.

...

Alexey, all of Kim's order functions are very questionable in terms of reliability and accuracy. Are you riveting EAs on them too?

 
Integer:

Alexey, all of Kim's order functions are very questionable in terms of reliability and accuracy. Do you rivet EAs on them too?

No. I'll use my own, realistically tested. :)

To be honest, I haven't seen the Kim's practically anywhere except in the recommendations on this forum. I only gave them in the section description as an example, so that you know what we're talking about. And I'm not sure that kim's will make it into the manual in its code. Only the idea will be taken and worked out in general style.

The HOW section is the most serious. It should be handled by a maximum of 2-3 people, since all the HOW sections are a lead-in to the last section - "Examples of TOR and their implementation", which will show all possible options and use combinations of all previous section functions.

 

Question: How do I compare two real numbers of type "double" ?


Answer:

double A;
double B;

if(NormalizeDouble(MathAbs(A-B),Digits)<0.1*Point)return(true);
else return(false);