Download MetaTrader 5
To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
Joseph Bervell
376
Joseph Bervell 2015.02.14 03:42 
I am trying to trade from an automatically updating CSV file. The file is updated with the newer entries being appended to the bottom of the file about every 15 minutes interval.

The resulting file is a record of several rows of data by date/time and value as shown below. 


// filename: EURUSDxx.CSV

 

// Date/Time      Value

2015.02.13 10:37, 23
2015.02.13 11:07, 23
2015.02.13 11:22, 23
2015.02.13 11:37, 23
2015.02.13 11:52, 23
2015.02.13 12:07, 21
2015.02.13 12:22, 21
2015.02.13 12:37, 21
2015.02.13 13:22, 19
2015.02.13 13:37, 19
2015.02.13 13:52, 19
2015.02.13 14:22, 19
2015.02.13 14:37, 19
2015.02.13 14:52, 17
2015.02.13 15:22, 15
2015.02.13 16:07, 11
2015.02.13 16:37, 11
2015.02.13 18:22, 15
2015.02.13 18:52, 17
2015.02.13 20:08, 17
2015.02.13 20:23, 17
2015.02.13 20:38, 15
2015.02.13 20:53, 15
2015.02.13 21:23, 15
2015.02.13 21:38, 15
2015.02.13 22:09, 13
2015.02.13 22:24, 13
2015.02.13 22:39, 13
2015.02.13 23:09, 13

My goal is to assign the most recent ten values (appended at the bottom) to array variables such that the latest entry at the bottom will have index 0, the entry above it will have index 1 and so on until index 9 (ten entries). My current implementation is resulting in the attached Printout which clearly shows the indexing is the reverse of what I am looking for.  

 

I guess my best shot is to sort the entries using ArraySort function before assigning the variables.  Unfortunately I have reached the end of my tether and my mql4 know-how and need your expert help in this exercise.  I need your help.  You get a FREE limited copy of the resulting amazing EA which will be released very soon. :) .  Wait a minute, I am attaching my latest version here to help me build on.

Thanks 

 

//+------------------------------------------------------------------+
//|                                           Sentimental Arrays.mq4 |
//|                                    Copyright © 2015, SiginvestFX |
//|                                       http://www.SiginvestFX.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Siginvestfx.com"
#property link      "http://www.Siginvestfx.com"
#property version   "1.00"
#property strict

#import "kernel32.dll"
  void OutputDebugStringW(string msg);
#import

extern   string   FileName    = "EURUSDxx.CSV";        

//+------------------------------------------------------------------+
int init()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+  
  
//--- Define variables
string   sentiment_time[10];
string   sentiment_val[10]; 

//+------------------------------------------------------------------+
int start()
 {
//+------------------------------------------------------------------+
  int handle = FileOpen(FileName, FILE_CSV|FILE_READ,',');
  if (handle==0)  { Comment("File "+FileName+" not found.");  return(0); }

    while(!FileIsEnding(handle))
    {
    // First pass loads data from file into arrays  (i.e. date/time, and value)
    for (int i=0; !FileIsEnding(handle) && i<10; i++)  
      {
       //  read date/time string into string type arrays .....  
        sentiment_time[i] = FileReadString(handle);
       //  read value string into string type arrays .....
        sentiment_val[i]  = FileReadString(handle);
       //exit if end of file
        if (FileIsEnding(handle)) break;

       // print results
        Print(i,"   Date/Time:  ", StrToTime(sentiment_time[i]),"   Value:  ", StrToDouble(sentiment_val[i]),"\n");

       // save results
        double SentimentValue0 = StrToDouble(sentiment_val[0]);
        double SentimentValue1 = StrToDouble(sentiment_val[1]);
        double SentimentValue2 = StrToDouble(sentiment_val[2]);
        double SentimentValue3 = StrToDouble(sentiment_val[3]);
        double SentimentValue4 = StrToDouble(sentiment_val[4]);
        double SentimentValue5 = StrToDouble(sentiment_val[5]);
        double SentimentValue6 = StrToDouble(sentiment_val[6]);
        double SentimentValue7 = StrToDouble(sentiment_val[7]);
        double SentimentValue8 = StrToDouble(sentiment_val[8]);
        double SentimentValue9 = StrToDouble(sentiment_val[9]);
        
        Comment( "0     Date/Time:  ", StrToTime(sentiment_time[0]),"   Value:  ", StrToDouble(sentiment_val[0]),"\n",
                 "1     Date/Time:  ", StrToTime(sentiment_time[1]),"   Value:  ", StrToDouble(sentiment_val[1]),"\n",
                 "2     Date/Time:  ", StrToTime(sentiment_time[2]),"   Value:  ", StrToDouble(sentiment_val[2]),"\n",
                 "3     Date/Time:  ", StrToTime(sentiment_time[3]),"   Value:  ", StrToDouble(sentiment_val[3]),"\n",
                 "4     Date/Time:  ", StrToTime(sentiment_time[4]),"   Value:  ", StrToDouble(sentiment_val[4]),"\n",
                 "5     Date/Time:  ", StrToTime(sentiment_time[5]),"   Value:  ", StrToDouble(sentiment_val[5]),"\n",
                 "6     Date/Time:  ", StrToTime(sentiment_time[6]),"   Value:  ", StrToDouble(sentiment_val[6]),"\n",
                 "7     Date/Time:  ", StrToTime(sentiment_time[7]),"   Value:  ", StrToDouble(sentiment_val[7]),"\n",
                 "8     Date/Time:  ", StrToTime(sentiment_time[8]),"   Value:  ", StrToDouble(sentiment_val[8]),"\n",
                 "9     Date/Time:  ", StrToTime(sentiment_time[9]),"   Value:  ", StrToDouble(sentiment_val[9]),
                  "\n");

      }
    }
    FileClose(handle);

 return(0);
// ============================================================================
 }

/
To add comments, please log in or register