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

MQL4 指标 脚本

工作已完成

执行时间2 小时
客户反馈
John knows his programming! And he did more than was expected. I can strongly recommend him to anyone who is looking for a programmer.
员工反馈
Great customer, prompt communication, clear specs, recommended+

指定

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:


 



反馈

1
开发者 1
等级
(636)
项目
1006
47%
仲裁
33
36% / 36%
逾期
99
10%
工作中
发布者: 6 代码
2
开发者 2
等级
(90)
项目
136
14%
仲裁
43
21% / 28%
逾期
14
10%
空闲
发布者: 2 代码
3
开发者 3
等级
(115)
项目
129
18%
仲裁
11
27% / 55%
逾期
4
3%
空闲
4
开发者 4
等级
(163)
项目
236
32%
仲裁
30
27% / 30%
逾期
26
11%
空闲
5
开发者 5
等级
(45)
项目
58
33%
仲裁
12
42% / 42%
逾期
7
12%
空闲
6
开发者 6
等级
(3)
项目
4
0%
仲裁
2
0% / 100%
逾期
1
25%
空闲
7
开发者 7
等级
(269)
项目
284
55%
仲裁
0
逾期
5
2%
空闲
8
开发者 8
等级
(24)
项目
28
32%
仲裁
1
0% / 0%
逾期
0
空闲
发布者: 1 代码
9
开发者 9
等级
(21)
项目
24
17%
仲裁
15
20% / 40%
逾期
6
25%
空闲
10
开发者 10
等级
(1156)
项目
1462
63%
仲裁
21
57% / 10%
逾期
43
3%
空闲
11
开发者 11
等级
项目
0
0%
仲裁
0
逾期
0
空闲
12
开发者 12
等级
(41)
项目
46
28%
仲裁
9
0% / 100%
逾期
7
15%
空闲
13
开发者 13
等级
(3)
项目
4
0%
仲裁
1
100% / 0%
逾期
0
空闲

项目信息

预算
30+ USD
截止日期
 2 天