offline chart values

To add comments, please log in or register
jshumaker
608
jshumaker  

I am trying to download historical indicator data and open/high/low/close values to a .csv file.  When I run the following code on an offline GBPUSD 5 minute chart (see screen shot) I am not getting the values I see in the chart.  


Here is the last line in the .csv file which matches the datetime of the last candle in the offline chart but the values do not match 

2018.02.09 16:05|1.46655881|1.44998119|0.00154370|0.00033107|100.00000000|87.36694678|1.46378289|1.4605


//+------------------------------------------------------------------+
//|                                                  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()
{
   int file_handle=FileOpen("m5.csv",FILE_READ|FILE_WRITE|FILE_CSV);
   
   double   boll_top[]; 
   double   boll_bot[]; 
   double   macd_main[]; 
   double   macd_sign[]; 
   double   stoc_main[]; 
   double   stoc_sign[]; 
   double   ma1O[]; 
   double   ma1H[]; 
   double   ma1L[]; 
   double   ma1C[]; 
   double   ma5[]; 
   double   ma8[]; 
   double   ma21[]; 
   double   ma55[]; 
   double   ma200[]; 
   datetime date_buff[]; 
   string   line;
   
   int copied=CopyTime(GBPUSD,PERIOD_M5,D'2009.01.01 01:01:01',D'2019.01.01 01:01:01',date_buff);
   ArrayResize(boll_top,copied);   
   ArrayResize(boll_bot,copied);
   ArrayResize(macd_main,copied);   
   ArrayResize(macd_sign,copied);   
   ArrayResize(stoc_main,copied);   
   ArrayResize(stoc_sign,copied);   
   ArrayResize(ma1O,copied);   
   ArrayResize(ma1H,copied);   
   ArrayResize(ma1L,copied);   
   ArrayResize(ma1C,copied);   
   ArrayResize(ma5,copied);   
   ArrayResize(ma8,copied);   
   ArrayResize(ma21,copied);   
   ArrayResize(ma55,copied);
   ArrayResize(ma200,copied);   
   for(int i=0;i<copied;i++)
   {
      boll_top[i]=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i);
      boll_bot[i]=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,i);
      macd_main[i]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
      macd_sign[i]=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);
      stoc_main[i]=iStochastic(NULL,0,5,3,3,MODE_SMA,1,MODE_MAIN,i);
      stoc_sign[i]=iStochastic(NULL,0,5,3,3,MODE_SMA,1,MODE_SIGNAL,i);
      ma1O[i]   =Open[i];
      ma1H[i]   =High[i];
      ma1L[i]   =Low[i];
      ma1C[i]   =Close[i];
      ma5[i]   =iMA(NULL,0,  5,0,MODE_EMA,PRICE_CLOSE,i);
      ma8[i]   =iMA(NULL,0,  8,0,MODE_SMA,PRICE_CLOSE,i);
      ma21[i]  =iMA(NULL,0, 21,0,MODE_EMA,PRICE_CLOSE,i);
      ma55[i]  =iMA(NULL,0, 55,0,MODE_EMA,PRICE_CLOSE,i);
      ma200[i] =iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,i);
      line=TimeToString(date_buff[i])
         +"|"+DoubleToString(boll_top[i])+"|"+DoubleToString(boll_bot[i])
         +"|"+DoubleToString(macd_main[i])+"|"+DoubleToString(macd_sign[i])
         +"|"+DoubleToString(stoc_main[i])+"|"+DoubleToString(stoc_sign[i])
         +"|"+DoubleToString(ma5[i])
         +"|"+DoubleToString(ma8[i])
         +"|"+DoubleToString(ma21[i])
         +"|"+DoubleToString(ma55[i])
         +"|"+DoubleToString(ma200[i])
         +"|"+DoubleToString(ma1O[i])
         +"|"+DoubleToString(ma1H[i])
         +"|"+DoubleToString(ma1L[i])
         +"|"+DoubleToString(ma1C[i]);
      FileWrite(file_handle,line);
   }
   FileClose(file_handle);
}


gbpusd

To add comments, please log in or register