FileWriteFloat

この関数は、ファイルポインタの現在位置から開始して、バイナリファイルに float パラメータの値を書き込みます。

uint  FileWriteFloat(
  int    file_handle,    // ファイルハンドル
  float  value            // 書かれる値
  );

パラメータ

file_handle

[in] FileOpen() から戻されたファイル記述子

value

[in] float 型の値

戻り値

成功の場合、書かれたバイト数(sizeof(float)=4)。ファイルポインタは、書かれたバイト数によって動きます。

例:

//+------------------------------------------------------------------+
//|                                          Demo_FileWriteFloat.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 script_show_inputs
//--- 端末からデータを受け取るパラメータ
input string         InpSymbolName="EURUSD";           // 通貨ペア
input ENUM_TIMEFRAMES InpSymbolPeriod=PERIOD_M15;       // 時間軸
input datetime       InpDateStart=D'2013.01.01 00:00'; // データコピー開始日
//--- データをファイルに書くパラメータ
input string         InpFileName="Close.bin";         // ファイル名
input string         InpDirectoryName="Data";         // ディレクトリ名
//+------------------------------------------------------------------+
//| スクリプトプログラムを開始する関数                                          |
//+------------------------------------------------------------------+
void OnStart()
 {
  datetime date_finish=TimeCurrent();
  double   close_buff[];
  datetime time_buff[];
  int      size;
//--- エラー値をリセットする
  ResetLastError();
//--- バーに終値を複製する
  if(CopyClose(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,close_buff)==-1)
    {
    PrintFormat("Failed to copy close price values. Error code = %d",GetLastError());
    return;
    }
//--- バーに時間を複製する
  if(CopyTime(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,time_buff)==-1)
    {
    PrintFormat("Failed to copy the time values. Error code = %d",GetLastError());
    return;
    }
//--- バッファサイズを受け取る
  size=ArraySize(close_buff);
//--- 値を書き込むためにファイルを開く(ファイルが存在しない場合は自動的に作成される)
  ResetLastError();
  int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_BIN);
  if(file_handle!=INVALID_HANDLE)
    {
    PrintFormat("%s file is open for writing",InpFileName);
    PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
    //--- 終値の時間と値をファイルに書く
    for(int i=0;i<size;i++)
       {
        FileWriteDouble(file_handle,(double)time_buff[i]);
        FileWriteFloat(file_handle,(float)close_buff[i]);
       }
    //--- ファイルを閉じる
    FileClose(file_handle);
    PrintFormat("Data is written, %s file is closed",InpFileName);
    }
  else
    PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
 }

参照

浮動小数点数型(ダブル、フロート)FileWriteDouble