Please help me find the bug in 5 lines of MQL4 code

MQL4 Indicadores Scripts

Trabalho concluído

Tempo de execução 2 horas
Comentário do cliente
John knows his programming! And he did more than was expected. I can strongly recommend him to anyone who is looking for a programmer.
Comentário do desenvolvedor
Great customer, prompt communication, clear specs, recommended+

Termos de Referência

I need help with a small piece of code that calculates the moving average of the Williams Percent Range indicator.

Here is the code:

         ArrayResize(WPRArray, WPR_MAPeriod);

         for (int j = 0; j < WPR_MAPeriod; j++)
         {
            WPRArray[j] = iWPR(symbol, WPR_Timeframe, WPR_Period, j);
         }
         double WPR_Average = iMAOnArray(WPRArray, 0, WPR_MAPeriod, 0, WPR_MAMethod, 0);
         
         WPR = DoubleToString(WPR_Average, 0);

It gives different values on the indicator on the chart and the value in the variable calculated for WPR, e.g.
Here the value on the indicator is -52,4541 where the value in the Variable WPR = -73 (rounded off)



And here is another example:
Value of the indicator = -63.5457 but the variable has the value -41(rounded off)

I have researched the issue and found that there is a 12 hour difference where the value in the variable lags the value of the indicator. 

Here is a chart over 20 hours of the values of the indi and the var to illustrate:


 



Respondido

1
Desenvolvedor 1
Classificação
(630)
Projetos
995
47%
Arbitragem
33
36% / 36%
Expirado
98
10%
Trabalhando
Publicou: 6 códigos
2
Desenvolvedor 2
Classificação
(90)
Projetos
136
14%
Arbitragem
43
21% / 28%
Expirado
14
10%
Livre
Publicou: 2 códigos
3
Desenvolvedor 3
Classificação
(115)
Projetos
129
18%
Arbitragem
11
27% / 55%
Expirado
4
3%
Livre
4
Desenvolvedor 4
Classificação
(163)
Projetos
236
32%
Arbitragem
30
27% / 30%
Expirado
26
11%
Livre
5
Desenvolvedor 5
Classificação
(45)
Projetos
58
33%
Arbitragem
12
42% / 42%
Expirado
7
12%
Livre
6
Desenvolvedor 6
Classificação
(3)
Projetos
4
0%
Arbitragem
2
0% / 100%
Expirado
1
25%
Livre
7
Desenvolvedor 7
Classificação
(265)
Projetos
280
55%
Arbitragem
0
Expirado
5
2%
Livre
8
Desenvolvedor 8
Classificação
(24)
Projetos
28
32%
Arbitragem
1
0% / 0%
Expirado
0
Livre
Publicou: 1 código
9
Desenvolvedor 9
Classificação
(21)
Projetos
24
17%
Arbitragem
15
20% / 40%
Expirado
6
25%
Livre
10
Desenvolvedor 10
Classificação
(1156)
Projetos
1462
63%
Arbitragem
21
57% / 10%
Expirado
43
3%
Livre
11
Desenvolvedor 11
Classificação
Projetos
0
0%
Arbitragem
0
Expirado
0
Livre
12
Desenvolvedor 12
Classificação
(41)
Projetos
46
28%
Arbitragem
9
0% / 100%
Expirado
7
15%
Livre
13
Desenvolvedor 13
Classificação
(3)
Projetos
4
0%
Arbitragem
1
100% / 0%
Expirado
0
Livre

Informações sobre o projeto

Orçamento
30+ USD
Prazo
para 2 dias