How does the iClose() function work? In other words when I look on my chart and identify a bar 0, shouldn't this function pick up the value of the close for that particular bar? In putting together an EA, I was able to tie-out bar 1 and bar 2 close values from the iClose() function with the previous bar's close value on the chart as well as the bar prior to this. What I noted was that my iClose() function for bar 0 is not picking up the last tick value for the last tick in the data.
I noted a similar situation with a different broker. What I noted was that the iClose() of bar 0 did not tie out with the chart close for bar 0. When you go back one bar, to bar 1, the iClose() ties out with the close of one bar ago. This is the case for bar 2 as well. I was expecting to see the last tick of bar 0 to become the close for bar 0. Does anyone out there know bar 0 is different?
The last tick for bar 0 should be the same as what is returned for Close. It seems that you are assuming from your log file or printing that the last value displayed is the last tick. I do not think this is the case. If you look at your one log file for example, the last price posted in your log was at 1.44010 which is circled on the right but the next entry for the open of 7:00 was at 1.44240. This is a big gap. So this first price (open of 7:00) would be a match to the close of the 6:00 of 1.44240 that you have circled on the left. When you are back testing and printing values then it will not print every tick. It will skip over a lot if I am not mistaken. The next thing is the iClose should be used for importing data from another chart symbol or time frame. If you are using the same chart and time frame then a Close array could be used instead. If you are not importing right then this could also give you different results.
Thank you for your reply. Since reading your response, I tried to change the iClose to Close. This did not help the problem. I am confused why the last tick of a bar is not the close price of that bar. I have been trying to get onto the MQL4 website over the course of this weekend but have not been able to get on the site as the site must have went down.
How are you judging what the last tick is though? From the last printing to the log file for that bar? If so, this may be the problem. For example, in the last example I gave, the last printing in the log file for the 6:00 to the very next printing for the 7:00 there was a big gap. I think you are assuming the last printing for the 6:00 is the last tick of that bar. The first printing for the 7:00 would be closer to what you want. The open of the 7:00 would be the same as the close of the 6:00. Anyways, I do not think you can assume that the last printing is the last tick. Hope I make sense.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.