date range of downloaded data

 

I am trying to download historical indicator data.  When I use the CopyTime function with the start bar at 0 I only get the most recent couple hundred bars.  When I try to download older data I don't get any data.

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

void OnStart()
{
   
   double   ma200; 
   datetime date_buff[]; 
   string   line;

   ArraySetAsSeries(date_buff,true);
   //int copied=CopyTime(NULL,PERIOD_H1,D'2018.01.01 01:01:01',D'2018.01.01 01:01:01',date_buff);
   int copied=CopyTime(NULL,PERIOD_H1,0,20000,date_buff);

   int file_handle=FileOpen("h1.txt",FILE_READ|FILE_WRITE|FILE_CSV);
   for(int i=0;i<copied;i++)
   {
      ma200 =iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,i);
      line=TimeToString(date_buff[i])
         +"|"+DoubleToString(ma200);
      FileWrite(file_handle,line);
   }     
   FileClose(file_handle);
}
 
jshumaker:

I am trying to download historical indicator data.  When I use the CopyTime function with the start bar at 0 I only get the most recent couple hundred bars.  When I try to download older data I don't get any data.

It is very likely you don't have more data in the chart. Try to find out by using:

printf("Number of bars: %d",iBars(NULL,PERIOD_H1));