FileReadDouble

이진 파일의 현재 위치에서 이중 정밀 부동 소수점 번호(double)를 읽습니다.

double  FileReadDouble(
   int  file_handle    // 파일 핸들
   );

Parameters

file_handle

[in] FileOpen()에서 반환된 파일 설명자.

반환 값

double 타입의 값.

참고

오류에 대한 더 많은 정보에 대해선, GetLastError()을 호출하십시오.

(FileWriteDouble 함수에 대한 예제를 실행한 후 얻은 파일이 여기에 사용됩니다)

//+------------------------------------------------------------------+
//|                                          Demo_FileReadDouble.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot Label1
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
#property indicator_separate_window
//--- 데이터 읽기 매개 변수
input string InpFileName="MA.csv";    // file name
input string InpDirectoryName="Data"// 디렉토리명
//--- 글로벌 변수
int      ind=0;
int      size=0;
double   ma_buff[];
datetime time_buff[];
//--- 지표 버퍼
double   buff[];
//+------------------------------------------------------------------+
//| 커스텀 지표 초기화 기능                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- 파일 열기
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_BIN);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s 파일을 읽을 수 있습니다",InpFileName);
      PrintFormat("파일 경로: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      //--- 먼저, 파일의 데이터 양을 읽습니다
      size=(int)FileReadDouble(file_handle);
      //--- 배열용 메모리 할당
      ArrayResize(ma_buff,size);
      ArrayResize(time_buff,size);
      //--- 파일에서 데이터 읽기
      for(int i=0;i<size;i++)
        {
         time_buff[i]=(datetime)FileReadDouble(file_handle);
         ma_buff[i]=FileReadDouble(file_handle);
        }
      //--- 파일 닫기
      FileClose(file_handle);
      PrintFormat("데이터가 작성됐습니다, %s 파일이 닫힙니다",InpFileName);
     }
   else
     {
      PrintFormat("%s 파일 열기 실패, 에러 코드 = %d",InpFileName,GetLastError());
      return(INIT_FAILED);
     }
//--- 인덱스가 0인 지표 버퍼에 배열 바인딩
   SetIndexBuffer(0,buff,INDICATOR_DATA);
//---- 차트에 표시되지 않는 지표 값을 설정
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,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[])
  {
   ArraySetAsSeries(time,false);
//--- 아직 다루지 않은 막대의 루프
   for(int i=prev_calculated;i<rates_total;i++)
     {
      //--- 디폴트로 0
      buff[i]=0;
      //--- 데이터가 여전히 존재하는지 확인
      if(ind<size)
        {
         for(int j=ind;j<size;j++)
           {
            //--- 날짜가 일치하면 파일의 값이 사용됩니다
            if(time[i]==time_buff[j])
              {
               buff[i]=ma_buff[j];
               //--- 카운터 증가
               ind=j+1;
               break;
              }
           }
        }
     }
//--- 다음 호출을 위한 prev_calculated의 반환 값
   return(rates_total);
  }

더 보기

Real types (double, float), StringToDouble, DoubleToString, FileWriteDouble