Download MetaTrader 5

Simple Indicator from CSV File

To add comments, please log in or register
Bradford Hall
183
Bradford Hall  

I am struggling to figure this out.

I want the data from my CSV file to coincide in the data window and a separate indicator window as a line.  When I curse over the appropriate day I want the data window to reflect the value, all I am getting is empty.


Let's use a very simple example.

Column One is the Date.

Column Two is the value.

 

EXAMPLE CSV FILE 

DATE "SOME VARIABLE "
9.22.2016
"234987"
 9.23.2016
 "234"
 9.24.2016 "1234"
9.25.2016"86598"

You get the idea.  Obviously I will have "SOME VARIABLE" replaced with something meaningful and the "tdata" with real values.  I'm confused on how to organize the dates and the language here and can not find any suitable examples.
Marco vd Heijden
Moderator
5558
Marco vd Heijden  
Bradford Hall:

I am struggling to figure this out.

I want the data from my CSV file to coincide in the data window and a separate indicator window as a line.  When I curse over the appropriate day I want the data window to reflect the value, all I am getting is empty.


Let's use a very simple example.

Column One is the Date.

Column Two is the value.

 

EXAMPLE CSV FILE 

DATE "SOME VARIABLE "
9.22.2016
"234987"
 9.23.2016
 "234"
 9.24.2016 "1234"
9.25.2016"86598"

You get the idea.  Obviously I will have "SOME VARIABLE" replaced with something meaningful and the "tdata" with real values.  I'm confused on how to organize the dates and the language here and can not find any suitable examples.
What code did you write so far ?
Bradford Hall
183
Bradford Hall  
Marco vd Heijden:
What code did you write so far ?

Well I have made some progress, but I am not out of the woodwork's just yet.  I am having difficulty getting excel to auto-populate a format that can be read by the code.

 The delimiter had to be changed from ";" to "," to write the "Value" into cell b1... gleaning some insight as to how some of this stuff works.  Still confusing, but happy to see that I can just get a histogram on my chart.

Datetime (YEAR.MONTH.DAY HOUR:MINUTE) Value
2016.01.01  0
2016.01.02 1
2016.01.03 2
2016.01.04 3
2016.01.05 4
2016.01.06 5
2016.01.07 6
2016.01.08 7
2016.01.09 8
2016.01.10 9
2016.01.11 10
2016.01.12 11
2016.01.13 12
2016.01.14 13
2016.01.15 14
2016.01.16 15
2016.01.17 16
2016.01.18 17
2016.01.19 18
2016.01.20 19
2016.01.21 20
2016.01.22 21
2016.01.23 22
2016.01.24 23
2016.01.25
2016.01.26
2016.01.27
2016.01.28
2016.01.29
2016.01.30
2016.01.31



I need to be able to quickly populate dates in this format... when I goto excel and try to change or fiddle with it, none of it matches up and then it won't work unless it is in this format.   Adding 00:00 and 01:00 to put marks on smaller time frames breaks the auto-filling to just repeat like this:

Datetime (YEAR.MONTH.DAY HOUR:MINUTE) Value
2016.01.01 01:00 0
2016.01.01 02:00 1
2016.01.01 01:01 2
2016.01.01 02:01 3
2016.01.01 01:02 4
2016.01.01 02:02 5
2016.01.01 01:03 6
2016.01.01 02:03 7
2016.01.01 01:04 8
2016.01.01 02:04 9
2016.01.01 01:05 10
2016.01.01 02:05 11
2016.01.01 01:06 12
2016.01.01 02:06 13
2016.01.01 01:07 14
2016.01.01 02:07 15
2016.01.01 01:08 16
2016.01.01 02:08 17
2016.01.01 01:09 18
2016.01.01 02:09 19
2016.01.01 01:10 20
2016.01.01 02:10 21
2016.01.01 01:11 22
2016.01.01 02:11 23

I really don't want to have to manually fill in minutes: hours... etc..   I have tried custom dates thinking I could make it work as yyyy.m.d h:mm but that doesn't work either..  

Datetime (YEAR.MONTH.DAY HOUR:MINUTE) Value
2016.01.01 01:00 0
2016.01.01 02:00 1
2016.01.01 01:01 2
2016.01.01 02:01 3
2016.01.01 01:02 4
2016.01.01 02:02 5
2016.01.01 01:03 6
2016.01.01 02:03 7
2016.01.01 01:04 8
2016.01.01 02:04 9
2016.01.01 01:05 10
2016.01.01 02:05 11
2016.01.01 01:06 12
2016.01.01 02:06 13
2016.01.01 01:07 14
2016.01.01 02:07 15
2016.01.01 01:08 16
2016.01.01 02:08 17
2016.01.01 01:09 18
2016.01.01 02:09 19
2016.01.01 01:10 20
2016.01.01 02:10 21
2016.01.01 01:11 22
2016.01.01 02:11 23

Any insight to a possible solution ???

#property indicator_separate_window
#property indicator_buffers 1

double ExtMapBuffer[];

int handle;

int OnInit(){
   string file_name = "Test.csv";
   if (!FileIsExist(file_name)){
      Alert("This file doesn't exist. It is created now by the indicator. Please, fullfill it. It is in \\MQL4\\Files\\Test.csv");
      handle = FileOpen(file_name,FILE_WRITE|FILE_CSV,",");
      FileWrite(handle,"Datetime (YEAR.MONTH.DAY HOUR:MINUTE)","Value (Number)");
      FileClose(handle);
      return(INIT_FAILED);
   }
   else handle = FileOpen(file_name,FILE_READ|FILE_CSV,",");
   
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,clrRed);
   SetIndexBuffer(0,ExtMapBuffer);
   SetIndexEmptyValue(0,0);

   return(INIT_SUCCEEDED);
}



int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]){
   static int flag = 0;
   if (flag == 0){
      FileSeek(handle,0,SEEK_SET);
      while (!FileIsEnding(handle)){
         datetime t = FileReadDatetime(handle);
         double data = FileReadNumber(handle);
         ExtMapBuffer[iBarShift(Symbol(),Period(),t)] = data;
      }
      flag = 1;
   }
   return(rates_total);
Files:
test.png 32 kb
Bradford Hall
183
Bradford Hall  
Bradford Hall:

Well I have made some progress, but I am not out of the woodwork's just yet.  I am having difficulty getting excel to auto-populate a format that can be read by the code.

 The delimiter had to be changed from ";" to "," to write the "Value" into cell b1... gleaning some insight as to how some of this stuff works.  Still confusing, but happy to see that I can just get a histogram on my chart.

Datetime (YEAR.MONTH.DAY HOUR:MINUTE) Value
2016.01.01  0
2016.01.02 1
2016.01.03 2
2016.01.04 3
2016.01.05 4
2016.01.06 5
2016.01.07 6
2016.01.08 7
2016.01.09 8
2016.01.10 9
2016.01.11 10
2016.01.12 11
2016.01.13 12
2016.01.14 13
2016.01.15 14
2016.01.16 15
2016.01.17 16
2016.01.18 17
2016.01.19 18
2016.01.20 19
2016.01.21 20
2016.01.22 21
2016.01.23 22
2016.01.24 23
2016.01.25
2016.01.26
2016.01.27
2016.01.28
2016.01.29
2016.01.30
2016.01.31



I need to be able to quickly populate dates in this format... when I goto excel and try to change or fiddle with it, none of it matches up and then it won't work unless it is in this format.   Adding 00:00 and 01:00 to put marks on smaller time frames breaks the auto-filling to just repeat like this:

Datetime (YEAR.MONTH.DAY HOUR:MINUTE) Value
2016.01.01 01:00 0
2016.01.01 02:00 1
2016.01.01 01:01 2
2016.01.01 02:01 3
2016.01.01 01:02 4
2016.01.01 02:02 5
2016.01.01 01:03 6
2016.01.01 02:03 7
2016.01.01 01:04 8
2016.01.01 02:04 9
2016.01.01 01:05 10
2016.01.01 02:05 11
2016.01.01 01:06 12
2016.01.01 02:06 13
2016.01.01 01:07 14
2016.01.01 02:07 15
2016.01.01 01:08 16
2016.01.01 02:08 17
2016.01.01 01:09 18
2016.01.01 02:09 19
2016.01.01 01:10 20
2016.01.01 02:10 21
2016.01.01 01:11 22
2016.01.01 02:11 23

I really don't want to have to manually fill in minutes: hours... etc..   I have tried custom dates thinking I could make it work as yyyy.m.d h:mm but that doesn't work either..  

Datetime (YEAR.MONTH.DAY HOUR:MINUTE) Value
2016.01.01 01:00 0
2016.01.01 02:00 1
2016.01.01 01:01 2
2016.01.01 02:01 3
2016.01.01 01:02 4
2016.01.01 02:02 5
2016.01.01 01:03 6
2016.01.01 02:03 7
2016.01.01 01:04 8
2016.01.01 02:04 9
2016.01.01 01:05 10
2016.01.01 02:05 11
2016.01.01 01:06 12
2016.01.01 02:06 13
2016.01.01 01:07 14
2016.01.01 02:07 15
2016.01.01 01:08 16
2016.01.01 02:08 17
2016.01.01 01:09 18
2016.01.01 02:09 19
2016.01.01 01:10 20
2016.01.01 02:10 21
2016.01.01 01:11 22
2016.01.01 02:11 23

Any insight to a possible solution ???

The excel codes and the MQL4 reference have a conflict... there is no MI in excel and both mm and mm might be conflicting with each other... if there is a workaround to this to quickly assemble them together that might work but I haven't the slightest clue where to begin
Marco vd Heijden
Moderator
5558
Marco vd Heijden  
Bradford Hall:
The excel codes and the MQL4 reference have a conflict... there is no MI in excel and both mm and mm might be conflicting with each other... if there is a workaround to this to quickly assemble them together that might work but I haven't the slightest clue where to begin

Can you please provide a example of what exactly you want it to be.

What it needs to look like.

To add comments, please log in or register