Download MetaTrader 5

MQL4: exporting data from CVS to indicator

To add comments, please log in or register
Publish the program in the Market and sell it to millions of traders!
antonm
28
antonm 2014.02.10 22:42 

Hello,

I have a problem with exporting from cvs to mt4. Iam a begginer in programming so i cant solve it :(.

I just got data in CSV and i need do a indicator from them. But problem is that i dont know how to assign date to values. So it will be harmonized with chart.

Thanks for help :)

Example:

http://leteckaposta.cz/396024107 -> CSV firs value is date in format month/day/year, second is value of indicator

oneoleguy
102
oneoleguy 2014.02.11 01:26  

I had used this before. It had worked last time I used it:

extern string File = "20090605.txt";

int init()

{

handle = FileOpen( File, FILE_CSV|FILE_WRITE,"," ); // These are column titles for the output files

FileWrite (handle, "Date","Currency","H1-O","H1-H","H1-L","H1-C","M30-O","M30-H","M30-L","M30-C",

"M1-O","M15-H","M15-L","M15-C","M5-O","M5-H","M5-L","M5-C",

"M1-O","M1-H","M1-L","M1-C","Tick");

}

else

{ FileClose(handle); }

//----

return(0);

And this is how it was used in the body of the program:

// Debugmain is a Boolean

if (debugmain) FileWrite (handle, " Current Datetime ===> " + iTime(Currency[i] + SymbolSuffix, Timeframes[j], 0) +

" Last Datetime ===> " + LastSellCheckTime[i,j] + " i = " + i + " j = " + j + " Currency Pair = " + Currency[i] +

" Timeframe = " + Timeframes[j]);

On second thought, it looks like I was in the middle of a change and the field list here is different than that in the Init() section.

Good luck.

antonm
28
antonm 2014.02.11 11:10  

Hi,

it will not help me or iam wrong? I dont want to filewrite but export data from csv. There is my actual code.

http://pastebin.com/nZT1UcF7

Simon Gniadkowski
Moderator
18000
Simon Gniadkowski 2014.02.11 11:14  
AntonM:

Hi,

i There is my actual code.

#property indicator_separate_window
#property  indicator_buffers 1
 
double histo[];
 
extern string FileName = "cot.csv";
extern string index = "INDEX small";
 
//=============== FUNCTION init
 
int init()
  {
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID,1,Red);
   SetIndexBuffer(0, histo);
   SetIndexLabel(0, index);  
   IndicatorShortName("NAME: "+FileName);
   makeHisto();
 
   return(0);
  }
 
void makeHisto()
{
 
   int handle;
   handle=FileOpen(FileName,FILE_CSV|FILE_READ,',');
   if(handle<1)
    {
     Print("File not found: ", GetLastError());
     return(false);
    }
   int i= 0;
   while(!FileIsEnding(handle))
   {
      string cur=FileReadString(handle); // Currency
      string dt=FileReadString(handle); // Currency
      string val=FileReadString(handle); // Currency
      int value = StrToDouble(val);
      histo[i]=value;
      i++;
   }
}
Simon Gniadkowski
Moderator
18000
Simon Gniadkowski 2014.02.11 11:16  
AntonM:

Hi,

it will not help me or iam wrong? I dont want to filewrite but export data from csv. There is my actual code.

Where is your start() function ? where do you close the file ?
antonm
28
antonm 2014.02.11 11:24  
#property indicator_separate_window
#property  indicator_buffers 1

double histo[];

extern string FileName = "jedna.csv";
extern string index = "INDEX small";

//=============== FUNCTION init

int init()
  {
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID,1,Red);
   SetIndexBuffer(0, histo);
   SetIndexLabel(0, index);  
   IndicatorShortName("NAME: "+FileName);
   makeHisto();

   return(0);
  }
//=============== FUNCTION deinit
int deinit()
  {
   return(0);
  }
  
//=============== FUNCTION start
int start()
  {
   makeHisto();
//----
   
//----
   return(0);
  }
  
//=============== Make Histogram

void makeHisto()
{
 
   int handle;
   handle=FileOpen(FileName,FILE_CSV|FILE_READ,',');
   if(handle<1)
    {
     Print("File was not found: ", GetLastError());
     return(false);
    }
   int i= 0;
   while(!FileIsEnding(handle))
   {
      string cur=FileReadString(handle); // Currency
      string dt=FileReadString(handle); // Currency
      string val=FileReadString(handle); // Currency
      int value = StrToDouble(val);
      histo[i]=value;
      i++;
   }
}


sorry wrong one. There is start() func.
whroeder1
14489
whroeder1 2014.02.11 14:33  
AntonM:
sorry wrong one. There is start() func.
  1. Don't post comments inside the SRC block
  2. And the answer to the RaptorUK's second question is?
antonm
28
antonm 2014.02.11 15:06  

1.ok

2. in the midle of the code (my last post)

int start()
  {
   makeHisto();
//----
   
//----
   return(0);
  }
Simon Gniadkowski
Moderator
18000
Simon Gniadkowski 2014.02.11 17:33  
AntonM:

1.ok

2. in the midle of the code (my last post)

You open the file, FileOpen() . . . where do you close it ? FileClose()
Ex Ovo Omnia
3148
Ex Ovo Omnia 2014.02.11 21:46  
Interesting, I just searched for some CVS-related topics and the result brought me mostly to mistyped CSV posts.
To add comments, please log in or register