FileReadBool

CSV 유형 문자열 파일을 현재 위치에서 구분 기호(또는 텍스트 줄 끝까지)로 읽고 읽기 문자열을 부울 유형 값으로 변환합니다.

bool  FileReadBool(
   int  file_handle    // 파일 핸들
   );

Parameters

file_handle

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

반환 값

줄 읽기는 "true", "false" 또는 정수 "0" 또는 "1"의 심볼 표시로 설정할 수 있습니다. 0이 아닌 값은 논리적 참으로 변환됩니다. 함수는 변환된 값을 반환합니다.

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

//+------------------------------------------------------------------+
//|                                            Demo_FileReadBool.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 2
#property indicator_plots   2
//---- plot Label1
#property indicator_label1  "UpSignal"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  4
//---- plot Label2
#property indicator_label2  "DownSignal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  4
//--- 데이터 읽기를 위한 파라미터
input string InpFileName="MACD.csv";  // 파일명
input string InpDirectoryName="Data"// 디렉토리명
//--- 글로벌 변수
int      ind=0;       // 인덱스
double   upbuff[];    // 위쪽 화살표의 지표 버퍼
double   downbuff[];  // 아래쪽 화살표의 지표 버퍼
bool     sign_buff[]; // 시그널 배열 (true - 매수, false - 매도)
datetime time_buff[]; // 시그널 도착 시간 배열
int      size=0;      // 시그널 배열의 크기
//+------------------------------------------------------------------+
//| 커스텀 지표 초기화 기능                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- 파일 열기
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_CSV);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s 파일이 읽기용으로 열렸습니다",InpFileName);
      //--- 첫째, 신호 수를 읽기
      size=(int)FileReadNumber(file_handle);
      //--- 배열용 메모리 할당
      ArrayResize(sign_buff,size);
      ArrayResize(time_buff,size);
      //--- 파일에서 데이터 읽기
      for(int i=0;i<size;i++)
        {
         //--- 시그널 시간
         time_buff[i]=FileReadDatetime(file_handle);
         //--- 시그널 값
         sign_buff[i]=FileReadBool(file_handle);
        }
      //--- 파일 닫기
      FileClose(file_handle);
     }
   else
     {
      PrintFormat("%s 파일 열기 실패, 에러 코드 = %d",InpFileName,GetLastError());
      return(INIT_FAILED);
     }
//--- 배열 바인딩
   SetIndexBuffer(0,upbuff,INDICATOR_DATA);
   SetIndexBuffer(1,downbuff,INDICATOR_DATA);
//--- PLOT_ARROW에 그리기 위한 심볼 코드를 설정합니다.
   PlotIndexSetInteger(0,PLOT_ARROW,241);
   PlotIndexSetInteger(1,PLOT_ARROW,242);
//---- 차트에 표시되지 않는 지표 값을 설정
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   PlotIndexSetDouble(1,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);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(high,false);
//--- 아직 다루지 않은 막대의 루프
   for(int i=prev_calculated;i<rates_total;i++)
     {
      //--- 디폴트로 0
      upbuff[i]=0;
      downbuff[i]=0;
      //--- 데이터가 아직 있는지 확인
      if(ind<size)
        {
         for(int j=ind;j<size;j++)
           {
            //--- 날짜가 일치하는 경우 파일의 값을 사용
            if(time[i]==time_buff[j])
              {
               //--- 시그널에 따라 화살표를 그림
               if(sign_buff[j])
                  upbuff[i]=high[i];
               else
                  downbuff[i]=low[i];
               //--- 카운터 증가
               ind=j+1;
               break;
              }
           }
        }
     }
//--- 다음 호출을 위한 prev_calculated의 반환 값
   return(rates_total);
  }

더 보기

Type bool, FileWrite