Download MetaTrader 5

MQL4 Custom Indicator from CSV File - Is this possible?

To add comments, please log in or register
How to use MQL5.community messages editor? Find out in the article!
Bradford Hall
183
Bradford Hall 2016.09.26 00:15 
What I want to create seems very simple in concept, but I am having a difficult time figuring it out looking at tutorials online.

I want to create a Leading indicator that would plot a line for different parameters.

How should I arrange my data to accomplish this?  I have the Year, Month, Weekday, Day#, and other strings, parameters I want to plot.

 YEAR
MONTH Weekday DAY# Variablexyz etc. 

   

   

   

   

   


Any help would be appreciated.  Thank you.
Marco vd Heijden
Moderator
4684
Marco vd Heijden 2016.09.26 00:19  
Bradford Hall:
What I want to create seems very simple in concept, but I am having a difficult time figuring it out looking at tutorials online.

I want to create a Leading indicator that would plot a line for different parameters.

How should I arrange my data to accomplish this?  I have the Year, Month, Weekday, Day#, and other strings, parameters I want to plot.

 YEAR
MONTH Weekday DAY# Variablexyz etc. 

   

   

   

   

   


Any help would be appreciated.  Thank you.
//+------------------------------------------------------------------+
//|                                                  Data_to_CSV.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Inovance"
#property link      "https://www.inovancetech.com/"
#property description "Save OHLCV data to a csv file."
#property version   "1.00"
#property strict
#property indicator_chart_window

   //Filename
input string   FileName = "PriceData.csv";



//+------------------------------------------------------------------+
//| Initialization function                                          |
//+------------------------------------------------------------------+
int OnInit()
  {
  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
      //Define variables
      int limit,i;
      int counted_bars = IndicatorCounted();
      
      //Make sure on most recent bar
      if(counted_bars>0) counted_bars--;
  
      //Set limit
      limit = Bars - counted_bars - 1;
      
      
      //Main loop
      for(i = limit - 1; i>=0; i--)
         {
          
            //Create and Open file
            int handle=FileOpen(FileName,FILE_CSV|FILE_READ|FILE_WRITE,",");
            
            //Name column headers
            FileWrite(handle,"Open Timestamp","Open","High","Low","Close","Volume");
            
            //Go to end of file
            FileSeek(handle,0,SEEK_END);
            
            //Record data
            FileWrite(handle,Time[i],Open[i],High[i],Low[i],Close[i],Volume[i]);
            
            //Close file
            FileClose(handle);    
            
         }
        
      return(0);
  }

Some example.

https://www.mql5.com/en/code/12699

In reverse use FileRead{datatype} () function.

https://www.mql5.com/en/docs/files/filereaddouble

https://www.mql5.com/en/docs/files/filereaddatetime

etc.

https://www.mql5.com/en/docs/files

Market Data to CSV
Market Data to CSV
  • votes: 19
  • 2015.03.24
  • //www.mql5.com/en/users/Inovance">
  • www.mql5.com
Saves all historical bar data (Open timestamp, Open, High, Low, Volume) and every new tick to CSV of your choice.
To add comments, please log in or register