write to file

 

I am trying to get a simple script to write the values of the technical indicators to a text file but I do not get the right values.  The output file dates are integers


void OnStart()
{
   int file_handle=FileOpen("h1.csv",FILE_READ|FILE_WRITE|FILE_CSV);
   
   double   macd_buff[]; // array of indicator values
   datetime date_buff[]; // array of indicator dates

   ArraySetAsSeries(macd_buff,true);
   int copied=CopyTime(NULL,0,0,1000,date_buff);
   ArrayResize(macd_buff,copied);   
   for(int i=0;i<copied;i++)
   {
      macd_buff[i]=iMACD("GBPUSD",PERIOD_D1,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
      FileWrite(file_handle,date_buff[i]);
      FileWrite(file_handle,macd_buff[i]);
   }
   FileClose(file_handle);
}
 
jshumaker:

The output file dates are integers

Dates will show up as integers unless you convert them to strings.

As per the documentation:

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. This type occupies 8 bytes of memory.
Look at TimeToString() for MQL5 or TimeToStr() for MQL4.


 
jshumaker: but I do not get the right values.  The output file dates are integers
  1. macd_buff[i]=iMACD("GBPUSD",PERIOD_D1,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
    Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. TimeToString

  3.       FileWrite(file_handle,date_buff[i]);
          FileWrite(file_handle,macd_buff[i]);
    You want to create a CSV file, rows of data with two columns. You are currently creating a one column file. Use one FileWrite.