Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1294

 
ANDREY:

Good day to all!

I am trying to mql4 to mql5.

Question: Why is mql5 calculating and displaying some unknown for me expression, like for example 2.99999999 - (minus) 05 instead of the difference between current price and value of Hay variable, which should be <1 (like in mql4)?

How can I make mql5 correctly calculate the difference between these values? I normalize all values using NormalizeDouble(), but the above values

values are displayed unchanged. This is strange to me as both values are of doble type

Thank you all for your help.


2.9999999999 -(minus)05= 2.9999999999 / 100000 = 0.0000299999999. That's how it's done in mathematics.

-(minus)05 is to divide by 10 to the fifth power.

 
IndependentMK:

Hello again.
Please pay attention to a newbie's question.
I need to point out errors in the code, because in the tester, the Expert Advisor does not open orders...
The compiler shows no errors or warnings and the same thing in the journal, there are no errors...

It doesn't open because one of the conditions is not met.

It's

while(MA_Smoth_B > MA_Smoth_S)

or this

if(MA_Simpl_B_Op < MA_Simpl_S_Op && MA_Simpl_B_Cl > MA_Simpl_S_Cl)

Comment out the two flashes // and you will see which one. That's how you will find the error.

 
Александр:

2.9999999999 -(minus)05= 2.9999999999 / 100000 = 0.000029999999999. That's how it's done in maths.

-(minus)05 is to divide by 10 to the fifth power.

Thanks for the answer, but why does the program not calculate the difference between the price 1.33671 and Hay 1.33664 instead of the expression, which should be 0.00007, but instead outputs the expression?

At the same time, when I replace the Hay variable with 1.33664 with constant 1.33664( SymbolInfoDouble(Symbol(),SYMBOL_BID) - 1.33664 ), the program calculates the real difference between these values, that is 0.00007. In fact, the Hay variable in the code takes the opening price value of the order on the previous tick, which is a double value of 1.33664.

Thank you in advance for your help.

 
ANDREY:

Thanks for the reply, but why doesn't the program calculate the difference between the price value 1.33671 and Hay 1.33664 instead of the expression, which should be 0.00007, but instead outputs the expression?

Thanks in advance for the tip.

DoubleToString(). It's not MQL5, it's a wrong output of real values in the log. This is equally true for MQL4.

Документация по MQL5: Преобразование данных / DoubleToString
Документация по MQL5: Преобразование данных / DoubleToString
  • www.mql5.com
[in]  Формат точности. Если значение digits лежит в диапазоне от 0 до 16, то будет получено строковое представление числа с указанным количество знаков после запятой. Если значение digits лежит в диапазоне от -1 до -16, то...
 
Artyom Trishkin:

DoubleToString(). And it's not about MQL5, it's about your incorrect output of real values in the log. This also applies to MQL4 to exactly the same extent.

Got it. Thank you. I have never faced such problems before. Now I will know.

I am not quite sure what the precision format means in relation to my code. It seems to me to be the number of decimal places.
But in MT4, in exactly the same code( except for OrderSend), if I remember correctly, the Print function always outputs the real value of the difference between two price values, namely, the number less than 1 (0.00000) with 5 decimal places after 0.

 
ANDREY:

Got it. Thank you. I've never come across this before. Now I'll know.

I'm not quite sure what the accuracy format means in relation to my code yet. It seems to me to be the number of decimal places.
But in MT4, in exactly the same code( except for OrderSend), if I remember correctly, the Print function always outputs the real value of the difference between two price values, namely, the number less than 1 (0.00000) with 5 decimal places after 0.

The real data values are printed everywhere. It is just different format of real numbers representation. If the terminal does not specify output format, it decides by itself which format is more convenient. Naturally, this assumes that you know all the formats of number representation.

It's all in the help.

 
Artyom Trishkin:

Real data values are displayed everywhere. It is just a different format for representing real numbers. If the terminal is not told which format to output, it decides which format is more convenient. Naturally, this assumes that you know all the number formats.

Everything is in the help.

So, MT4 and MT5 have different formats for representation of real numbers?
What should I read in mql5 Help to deal with this question?

Thanks for the help.

 
Michail_David:
Hello, fellow experts. I need your help in correcting the indicator. The essence of the indicator is as follows. Calculate the magnitude of price increase relative to the previous bar. For zero takes a star bar. That is, the opening price is equal to the closing price. When compiling no errors, but when testing an error on the line 80 20 characters. The signal line is also incorrectly drawn. But I think this is the reason for incorrect calculation of the main buffer. Please help me to fix it.

Okay. Looks like only a select few get help around here.

 
Michail_David:

Okay. Looks like only a select few get help around here.

Try this.

//--- typical price and its moving average
   for(i=0; i<rates_total-1; i++)
     {
      ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2);
 
Vitaly Muzichenko:

Try this.

Thank you, Vitaly. But still I get an error in line ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2); on element [i}.

Reason: