Download MetaTrader 5

Help Needed: Hooking an Indicator to a CSV File

To add comments, please log in or register
Forex Trader
114269
Forex Trader  

Is it possible to write an indicator that obtains data from an external text file?


Suppose we have a text file formatted like this:

--

Date1(Tab)Value1(LF)

Date2(Tab)Value2(LF)

...

DateN(Tab)ValueN(EOF)

--

where (Tab) could be actually Tab, or "," or ";" or something else.


How do you make reference to an external file in the source code of your indicator, and how do you make it read the data structured as shown above to show it as a line or bar chart?


Thank you!

Bradford Hall
183
Bradford Hall  
^bump

Did you ever figure it out?  I am trying to do the same thing!
Marco vd Heijden
Moderator
4753
Marco vd Heijden  
Bradford Hall:
^bump

Did you ever figure it out?  I am trying to do the same thing!
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.
Bradford Hall
183
Bradford Hall  
Thank you for the response.  Yes it needs to be in reverse.  It needs to read the csv file, and plot the variable values for the corresponding date/time.   I'll see if I can't muddle through it and get a simple daily test to work.  If it works, when I attach it I should have a moving average in the window with the values for that specific date/time correct?
To add comments, please log in or register