Show all relevant code including where the values for the print comes from.
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
input int WPR_MAPeriod = 35; //MA Period for WPR input int WPR_Period = 35; //WPR Period ArrayResize(WPRArray,WPR_Period); for(int j = 0; j < WPR_Period; j++) { WPRArray[j] = iWPR(NULL,PERIOD_H1, WPR_Period, j); } WPR_Average = iMAOnArray(WPRArray, 0, WPR_MAPeriod, 0, MODE_LWMA, 0); WPR = DoubleToString(WPR_Average, 0); Print("WPR_Average is ", WPR_Average, " WPR is ",WPR, " WPRBuytrade is ", WPRBuytrade, " WPRSelltrade is ", WPRSelltrade);
Your array probably does not contain the right amount of data to calculate the MA correctly. Try
ArrayResize(WPRArray,WPR_MAPeriod); for(int j = 0; j < WPR_MAPeriod; j++)
Show the code that you are using.
WPR = DoubleToString(WPR_Average, 0);
would print as 46, not 46.0 as it does in your earlier posted image.
Also why are you using the average here?
Maybe it should be
WPR = DoubleToString(WPRArray[0], 0);
Your array probably does not contain the right amount of data to calculate the MA correctly. Try
As @lippmaje suggested you have a fundamental error in the loop and the array .
if you want the average of the last 100 WPR(35)'s you need to keep the last 100 in the array (instead of 35). [100 would be WPR_MAPeriod,35 would be WPR_Period]
Since this is an indicator though you can take advantage of certain things :
Assign a buffer the task of storing these WPR's
No j loop, just call the WPR filler and the averaging function within the indicators oncalculate loop
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I calculate a certain value with the code as shown below. The problem is that the value in the Journal and that on the indicator representing this differs completely - which causes my EA to not work correctly.
I take the Williams Percent Range (WPR) indicator and feed that into a Moving Average - both with periods at 35 and the MA method set at Linear Weighted to draw the line you see on the chart. But the value on the indicatore (which is correct when i look at the value of the WPR indicator) does not agree with the value in the Journal/EA so it does not do what it is supposed to do.
In the attached chart you can see the indicator is touching -80 but the Journal gives the value at that time as -46 which is completely incorrect and therefore the EA does not work correctly.
Please help!