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

 
Artyom Trishkin:

IndicatorDigits(5)

Thank you!
 

Let me ask another question. Based on the same indicator. Let us assume that we attach the indicator to the chart. We obtain the first value of Bid1. Then we obtain the second value of Bid2. And we need to compare these two values. From the second one we subtract the first one and obtain the number that we add to the first Bid1.

Bid1=1.11133

Bid2=1.11135

Bid2-Bid1=0.00002

Bid1+0.00002=1.11135

I understand that the result is the same as in the original indicator.

I just want to see the implementation and understand the logic of the code.

 
Alexey Viktorov:

You have to unlock it in the file properties.

Thank you! :)
 
jaffer wilson :

Two statements:

Print: 22.33

И

Print: 2.00000

Why are there different outputs? In C / C ++ the above statement works fine.

Does anyone have any ideas about this problem?

 

Help me understand the price arrays in mt5. It's not clear in the indicator. I output prices, which are in OnCalculate:

  for(int i=10; i>=0; i--)
         PrintFormat("s- open[%d] = %d",i,open[i]);

I get strange prices:

2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[10] = 1597040639
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[9] = -523642413
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[8] = 1691873517
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[7] = 590987500
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[6] = 1583296744
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[5] = 115448721
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[4] = 360090058
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[3] = -1597040639
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[2] = -856244680
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[1] = 366962006
2020.01.15 20:09:51.517 ZZ_And_Moving_Averages (EURUSD,H1)      s- open[0] = -1209462791

I do it the other way around, I create an array and copy it (I look for it by trying, it's not clear to me):

double Open[];//глобальная
CopyOpen(NULL,0,0,Bars_To_Process*2,Open); //OnCalculate
 for(int i=10; i>=0; i--)
         PrintFormat("Open[%d] = %d",i,Open[i]);//OnCalculate

And I get similar results:

2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[10] = 1356522471
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[9] = -1708366192
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[8] = -729800843
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[7] = 1499458982
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[6] = 167675523
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[5] = -90709709
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[4] = -321607151
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[3] = -314735203
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[2] = -314735203
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[1] = 1663011337
2020.01.15 20:10:11.557 ZZ_And_Moving_Averages (EURUSD,H1)      Open[0] = -1408749273

It's even more interesting with dates. I print dates that are in OnCalculate:

for(int i=10; i>=0; i--)
         PrintFormat("s- time[%d] = %s",i,TimeToString(time[i]));

I get this:

2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[10] = 2015.12.02 10:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[9] = 2015.12.02 09:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[8] = 2015.12.02 08:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[7] = 2015.12.02 07:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[6] = 2015.12.02 06:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[5] = 2015.12.02 05:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[4] = 2015.12.02 04:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[3] = 2015.12.02 03:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[2] = 2015.12.02 02:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[1] = 2015.12.02 01:00
2020.01.15 20:17:04.421 ZZ_And_Moving_Averages (EURUSD,H1)      s- time[0] = 2015.12.02 00:00

And when I copy it:

datetime Time[];
CopyTime(NULL,0,0,Bars_To_Process*2,Time);
for(int i=10; i>=0; i--)
         PrintFormat("Time[%d] = %s",i,TimeToString(Time[i]));

It prints out fine:

2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[10] = 2020.01.15 10:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[9] = 2020.01.15 11:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[8] = 2020.01.15 12:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[7] = 2020.01.15 13:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[6] = 2020.01.15 14:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[5] = 2020.01.15 15:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[4] = 2020.01.15 16:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[3] = 2020.01.15 17:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[2] = 2020.01.15 18:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[1] = 2020.01.15 19:00
2020.01.15 20:20:37.686 ZZ_And_Moving_Averages (EURUSD,H1)      Time[0] = 2020.01.15 20:00

But you can't get far on dates alone. Help me understand. How do I get the correct opening and closing prices?

 
Yevhenii Levchenko:

Help me deal with price arrays in mt5. It's not clear in the indicator. I output the prices that are in OnCalculate:

for(int i=10; i>=0; i--)
         PrintFormat("s- open[%d] = %d",i,open[i]);

Make it like this:

for(int i=10; i>=0; i--)
{
   Print("s- open[",i,"] = ",open[i]);
}

You used wrong type specification in the formatted output

 
Igor Makanu:

do this:

You used the wrong type specification in the formatted output

Aaaaahhhh, shit! Thank you very much, Igor!

I should have put %f... I've got it wrong... I also need to put ArraySetAsSeries everywhere. It's a little weird...

 
Igor Makanu:

please

I would not advise to use ArraySetAsSeries() if you write the indicator code from scratch (if you port it from MQL4 - another matter),

use rates_total as the number of the right-most bar - 1, you will get used to the indicator logic in MQL5 quicker

Thank you!

Not writing from scratch... I'm transferring the mt4 indicator to mt5
 
Oleg Bondarev:

Let me ask you another question. Based on the same indicator. Let us assume that we attach the indicator to the chart. We obtain the first value of Bid1. Then we obtain the second value of Bid2. And we need to compare these two values. From the second one we subtract the first one and obtain the number that we add to the first Bid1.

Bid1=1.11133

Bid2=1.11135

Bid2-Bid1=0.00002

Bid1+0.00002=1.11135

I understand that the result is the same as in the original indicator.

I just want to see the implementation and understand the logic of the code.

Help me. I can't get anything working on my own. I make 2 buffers x[ ] to compare Bid values and y[ ] to plot. And nothing.

 
Oleg Bondarev:

I need your help. I can't get anything working on my own. I make 2 buffers x[ ] to compare Bid values and y[ ] to plot. And nothing.

Try asking the question differently, your question is probably not clear

Reason: