Download MetaTrader 5
MQL5 ReferenceFile FunctionsFileIsLineEnding 


Defines the line end in a text file in the process of reading.

bool  FileIsLineEnding(
   int  file_handle      // File handle



[in]  File descriptor returned by FileOpen().

Return Value

Returns true if in the process of reading txt or csv-file reached the end of the line (the characters CR-LF).

Example (the file obtained during the execution of an example for FileWriteString function is used here)

//|                                        Demo_FileIsLineEnding.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                     |
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   1
//---- plot Label1
#property indicator_label1  "Overbought & Oversold"
#property indicator_type1   DRAW_COLOR_BARS
#property indicator_color1  clrRedclrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- parameters for data reading
input string InpFileName="RSI.csv";   // file name
input string InpDirectoryName="Data"// directory name
//--- indicator buffers
double   open_buff[];
double   high_buff[];
double   low_buff[];
double   close_buff[];
double   color_buff[];
//--- overbought variables
int      ovb_ind=0;
int      ovb_size=0;
datetime ovb_time[];
//--- oversold variables
int      ovs_ind=0;
int      ovs_size=0;
datetime ovs_time[];
//| Custom indicator initialization function                         |
int OnInit()
//--- variables of array sizes by default
   int ovb_def_size=100;
   int ovs_def_size=100;
//--- allocate memory for arrays
//--- open the file
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_CSV|FILE_ANSI);
      PrintFormat("%s file is available for reading",InpFileName);
      PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      double value;
      //--- read data from file
         //--- read the first value in the string
         //--- read to different arrays according to the function result
      //--- close the file
      PrintFormat("Data is written, %s file is closed",InpFileName);
      PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
//--- binding the arrays
//---- set the indicator values that will not be visible on the chart
//| Read the file's string data                                      |
void ReadData(const int file_handle,datetime &arr[],int &size,int &def_size)
   bool flag=false;
//--- read till the end of the string or of the file is reached
   while(!FileIsLineEnding(file_handle) && !FileIsEnding(file_handle))
      //--- shift the position by reading the number
      //--- store the current date
      //--- increase the array size if necessary
      //--- slip past the first iteration
//| Custom indicator iteration function                              |
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[])
//--- the loop for the bars that have not been handled yet
   for(int i=prev_calculated;i<rates_total;i++)
      //--- 0 by default
      //--- check if any data is still present
         for(int j=ovb_ind;j<ovb_size;j++)
            //--- if the dates coincide, the bar is in the overbought area
               //--- 0 - red color
               //--- increase the counter
      //--- check if any data still exists
         for(int j=ovs_ind;j<ovs_size;j++)
            //--- if the dates coincide, the bar is in the oversold area
               //--- 1 - blue color
               //--- increase the counter
//--- return value of prev_calculated for next call
//| ChartEvent event handler                                         |
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam
//--- change the indicator width according to the scale

See also


Updated: 2015.12.03