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

MQL4 Indicators Scripts

Job finished

Execution time 2 hours
Feedback from customer
John knows his programming! And he did more than was expected. I can strongly recommend him to anyone who is looking for a programmer.
Feedback from employee
Great customer, prompt communication, clear specs, recommended+

Specification

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:


 



Responded

1
Developer 1
Rating
(623)
Projects
977
46%
Arbitration
32
38% / 34%
Overdue
96
10%
Working
Published: 6 codes
2
Developer 2
Rating
(90)
Projects
136
14%
Arbitration
43
21% / 28%
Overdue
14
10%
Free
Published: 2 codes
3
Developer 3
Rating
(115)
Projects
129
18%
Arbitration
11
27% / 55%
Overdue
4
3%
Free
4
Developer 4
Rating
(163)
Projects
236
32%
Arbitration
30
27% / 30%
Overdue
26
11%
Free
5
Developer 5
Rating
(45)
Projects
58
33%
Arbitration
12
42% / 42%
Overdue
7
12%
Free
6
Developer 6
Rating
(3)
Projects
4
0%
Arbitration
2
0% / 100%
Overdue
1
25%
Free
7
Developer 7
Rating
(261)
Projects
276
55%
Arbitration
0
Overdue
5
2%
Free
8
Developer 8
Rating
(24)
Projects
28
32%
Arbitration
1
0% / 0%
Overdue
0
Free
Published: 1 code
9
Developer 9
Rating
(21)
Projects
24
17%
Arbitration
15
20% / 40%
Overdue
6
25%
Free
10
Developer 10
Rating
(1156)
Projects
1462
63%
Arbitration
21
57% / 10%
Overdue
43
3%
Free
11
Developer 11
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
12
Developer 12
Rating
(41)
Projects
46
28%
Arbitration
9
0% / 100%
Overdue
7
15%
Free
13
Developer 13
Rating
(3)
Projects
4
0%
Arbitration
1
100% / 0%
Overdue
0
Free

Project information

Budget
30+ USD
Deadline
to 2 day(s)