MODIFY DATA POINTER TO DOWNLOAD M1 and M5

 
Files:
 

Play video
Please edit your post.
For large amounts of code, attach it.
 
Sorry, I'm new here and I'm not familiar yet. Now I stand corrected.

thank you very much

My question is the same as above. As might be modified to also be able to download data from M1 and M5??

//+------------------------------------------------------------------+
//|                                              HISTORYDATA-MTP.mq4 |
//|                        Copyright © 2008, Muhammad Hamizi Jaminan |
//|                                         http://www.fxsentral.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Muhammad Hamizi Jaminan."
#property link      "http://www.fxsentral.com"
#property indicator_chart_window

/*
Filename: HISTORYDATA-MTP.mq4
Description: Export history data
Author: Muhammad Hamizi Jaminan aka hymns

Version History
***************
Version 1.0.5
- add string time frame on file instead of minute numbers.

Version 1.0.4
- add new frequency update for reduce memory usage on writing.

Version 1.0.3
- fixed exausting memory usage on writing for all pair (19 pair 5 timeframe).

Version 1.0.2
- add completed bar parameter
- add debug mode parameter
- add timeframe 60, 30 & 15 minute data 

Version 1.0.1
- add custom extension for filename
- add custom bar numbers

Version 1.0.0
- Enjoy my first release
- Export D1 & H4 chart history
*/

//external input
extern int frequency_update = 60;
extern string file_extension = ".csv";

//bar input
extern int number_bars  = 2000;
extern int from_year    = 1978;
extern bool completed_bar = false;
extern bool enable_debug = false;

//period input
extern bool period_weekly = true;
extern bool period_daily = true;
extern bool period_4hour = false;
extern bool period_1hour = false;
extern bool period_30min = false;
extern bool period_15min = false;

//writing permissions
bool writedata = false;

//file handler
int handler, cnt, shift;
int current_time = 0;
   
//string handle
string strline, filename;

//start function
int start()
{                    
   //timer controller
   if (current_time == 0 || current_time  < StrToTime(TimeToStr(TimeCurrent(), TIME_MINUTES)))
   {
      current_time = StrToTime(TimeToStr(TimeCurrent()+frequency_update, TIME_MINUTES)); 
      writedata = true;
   }
   
   //check writing permissions
   if (writedata == false)
   {
      return(0); 
   }

   //check complete bar
   if (completed_bar)
   {
      shift = 1;
   }
   else
   {
      shift = 0;
   }

   //weekly period
   if (period_weekly)
   {      
      write_history(PERIOD_W1);
   }

   //24 hour period
   if (period_daily)
   {      
      write_history(PERIOD_D1);
   }

   //4 hour period
   if (period_4hour)
   {      
      write_history(PERIOD_H4);
   }

   //1 hour period
   if (period_1hour)
   {      
      write_history(PERIOD_H1);
   }

   //30 minute period
   if (period_30min)
   {      
      write_history(PERIOD_M30);
   }

   //15 minute period
   if (period_15min)
   {      
      write_history(PERIOD_M15);
   }

   //reset permission back         
   writedata = false;

   return(0);
}

//write history data
void write_history(int period)
{    
   //switch period string   
   string period_string;

   switch(period)
   {
      case 10080 :
      period_string = "W1";
      break;

      case 1440 :
      period_string = "D1";
      break;

      case 240 :
      period_string = "H4";
      break;

      case 60 :
      period_string = "H1";
      break;

      case 30 :
      period_string = "M30";
      break;

      case 15 :
      period_string = "M15";
      break;
   }

   //filename 
   filename = Symbol() + "_" + period_string + file_extension;

   //debug : open file
   if (enable_debug)
   {
      Print("Debug: Accessing file ",filename,"...");
   }

   //open file : assign handler
   handler = FileOpen(filename, FILE_CSV|FILE_WRITE, "\t");

   //failed create handle
   if(handler < 1)
   {
      //debug : file open failed
      if (enable_debug)
      {
         Print("Debug: Cannot open file ", filename," : error_",GetLastError());
      }
      return(0);
   }

   //debug : file open
   if (enable_debug)
   {
      Print("Debug: Success accessing file ",filename,"...");
   }

   //reset string
   strline = "";
   
   //read existing bars
   for (cnt = number_bars; cnt >= shift; cnt--)
   {
      //check year
      if (from_year < TimeYear(iTime(Symbol(), period, cnt)) )
      {
         //assign contents
         strline = TimeToStr(iTime(Symbol(), period, cnt),TIME_DATE|TIME_SECONDS);
         strline = StringSubstr(strline, 0, 4) + StringSubstr(strline, 5, 2) + StringSubstr(strline, 8, 2) + "," + StringSubstr(strline, 11, 5);
         strline = strline + "," + DoubleToStr(iOpen(Symbol(), period, cnt), 4) + "," + DoubleToStr(iHigh(Symbol(), period, cnt),4) + "," + DoubleToStr(iLow(Symbol(), period, cnt),4) + "," + DoubleToStr(iClose(Symbol(), period, cnt),4) + "," + DoubleToStr(iVolume(Symbol(), period, cnt),0);
         
         //writing contents
         FileWrite(handler, strline);
       }
   }

   //debug : complete
   if (enable_debug)
   {
      Print("Debug: Writing file ",filename," completed!");
   }
   
   //close handler
   FileClose(handler);

   //debug : closing
   if (enable_debug)
   {
      Print("Debug: Closing file ",filename,"...");
   }
   
   return(0);
}

 
burnssss:
Sorry, I'm new here and I'm not familiar yet. Now I stand corrected.

thank you very much

My question is the same as above. As might be modified to also be able to download data from M1 and M5??


Why didn't you EDIT your first post ?
 
burnssss:

My question is the same as above. As might be modified to also be able to download data from M1 and M5?

First:

extern bool period_15min = false;

// After the above line, add:
extern bool period_5min  = false;
extern bool period_1min  = false;

Second:

//15 minute period
if (period_15min)
{      
   write_history(PERIOD_M15);
}

// After the above IF statement, add the following two IF statements:
//5 minute period
if (period_5min)
{      
   write_history(PERIOD_M5);
}
   
//1 minute period
if (period_1min)
{      
   write_history(PERIOD_M1);
}

Third:

   case 15 :
   period_string = "M15";
   break;

// After the above CASE statement, add the following CASE statements:
   case 5 :
   period_string = "M5";
   break;
      
   case 1 :
   period_string = "M1";
   break;
 
Thank you very much, it worked. But now I get to open the data folder with excel and I did not find it in the directory folder of metatrader files. This data would automatically and export each matlab certain frequency, but for some casual no csv I get the data.

Thank you very much again
 
RaptorUK:

Why didn't you EDIT your first post ?

??
 
I advise to write a new post??
sorry
 
You already added the attachment so to appease the powers that be, you could just remove the source code that is pasted in the first post and keep the attachment, instead of replying to this thread but not editing the post as requested ?
 
burnssss:
I advise to write a new post??
sorry
You were asked to edit your post, I'm just curios why you haven't ? is it because you can't ? you don't want to ? or because you don't know how ?
 
The truth is I do not know how to do it, I'm a little lost on the page.
thank you very much
Reason: