current chart

 

I only have 1 chart open GBPUSD H1 when I run the code below, but the value I get for the closing price does not match the chart.  The output file (attached) gives me '2018.01.30 11:00|1.41090000' but the closing price for that 2018-1-30 11:00 is 1.41258 and not 1.4109

#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Averages Convergence/Divergence"
#property strict

void OnStart()
{
   string line;
   datetime date_buff[]; 
   int copied=CopyTime(NULL,PERIOD_H1,0,1,date_buff);

   int file_handle=FileOpen("h1.csv",FILE_READ|FILE_WRITE|FILE_CSV);
   line=TimeToString(date_buff[0])+"|"+DoubleToString(iClose(NULL,PERIOD_H1,0));
      
   FileWrite(file_handle,line);
   FileClose(file_handle);
}

gbpusd

Files:
h1.txt  1 kb
 
jshumaker:

I only have 1 chart open GBPUSD H1 when I run the code below, but the value I get for the closing price does not match the chart.  The output file (attached) gives me '2018.01.30 11:00|1.41090000' but the closing price for that 2018-1-30 11:00 is 1.41258 and not 1.4109


You had to run the script when the price was 1.4109 then the price rose and closed at 1.41258

Your problem is as I mentioned in your another topic yesterday: https://www.mql5.com/en/forum/226189#comment_6444398 that you don't use ArraySetAsSeries(). You should read at least your topics.

Your script might look like this:

void OnStart()
{
   string line;
   datetime date_buff[];
   ArraySetAsSeries(date_buff,true);
   int copied=CopyTime(NULL,PERIOD_H1,0,2,date_buff);

   int file_handle=FileOpen("h1.csv",FILE_READ|FILE_WRITE|FILE_CSV);
   line=TimeToString(date_buff[1])+"|"+DoubleToString(iClose(NULL,PERIOD_H1,1));
      
   FileWrite(file_handle,line);
   FileClose(file_handle);
}
downloaded data does not match chart
downloaded data does not match chart
  • 2018.01.30
  • www.mql5.com
The data I am getting from the iBands, iMacd nor Close() are matching my charts...
 
Petr Nosek:

You had to run the script when the price was 1.4109 then the price rose and closed at 1.41258

Your problem is as I mentioned in your another topic yesterday: https://www.mql5.com/en/forum/226189#comment_6444398 that you don't use ArraySetAsSeries(). You should read at least your topics.

Your script might look like this:

My bad I didn't realize you had already given me my answer.  Thank you

Reason: