無料でロボットをダウンロードする方法を見る
Facebook上で私たちを見つけてください。
私たちのファンページに参加してください
興味深いスクリプト?
それではリンクにそれを投稿してください。-
他の人にそれを評価してもらいます
記事を気に入りましたか?MetaTrader 5ターミナルの中でそれを試してみてください。
スクリプト

Demo_FileWriteDouble - MetaTrader 5のためのスクリプト

ビュー:
690
評価:
(33)
パブリッシュ済み:
2016.09.29 12:22
アップデート済み:
2016.11.22 07:34
このコードに基づいたロボットまたはインジケーターが必要なら、フリーランスでご注文ください フリーランスに移動

このスクリプトは移動平均指標の値を取得してローカル端末フォルダの「Data」サブディレクトリのバイナリファイルに書き込みます。スクリプトの入力パラメータでは、MA指標計算や通貨ペアと時間枠だけではなく指標値計算に使われる日付が指定できます。

MA指標値に加え、時刻の対応値は初めにdouble値にされてファイルにも書き入れられます。

コード:

//--- スクリプト起動時に入力パラメータウィンドウを表示する
#property script_show_inputs
//--- 端末からデータを受け取るパラメータ
input string             InpSymbolName="EURJPY";           // 通貨ペア
input ENUM_TIMEFRAMES    InpSymbolPeriod=PERIOD_M15;       // 時間軸
input int                InpMAPeriod=10;                  // 平滑化期間
input int                InpMAShift=0;                    // 指標のシフト
input ENUM_MA_METHOD     InpMAMethod=MODE_SMA;             // 平滑化の種類
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE;      // 価格の種類
input datetime           InpDateStart=D'2013.01.01 00:00'; // データコピー開始日
//--- データをファイルに書くためのパラメータ
input string             InpFileName="MA.csv";    // ファイル名
input string             InpDirectoryName="Data"; // ディレクトリ名
//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime date_finish=TimeCurrent();
   double   ma_buff[];
   datetime time_buff[];
   int      size;
//--- MA指標ハンドルを受け取る
   ResetLastError();
   int ma_handle=iMA(InpSymbolName,InpSymbolPeriod,InpMAPeriod,InpMAShift,InpMAMethod,InpAppliedPrice);
   if(ma_handle==INVALID_HANDLE)
     {
      //--- 指標ハンドルの受け取りに失敗
      PrintFormat("Error when receiving indicator handle. Error code = %d",GetLastError());
      return;
     }
//--- 全ての指標値が計算されるまでループに留まる
   while(BarsCalculated(ma_handle)==-1)
      Sleep(20); // 指標が全ての値を計算出来るように一時停止する
   PrintFormat("Indicator values starting from %s will be written to the file",TimeToString(InpDateStart));
//--- 指標値を複製する
   ResetLastError();
   if(CopyBuffer(ma_handle,0,InpDateStart,date_finish,ma_buff)==-1)
     {
      PrintFormat("Failed to copy the indicator values. Error code = %d",GetLastError());
      return;
     }
//--- 適切なバーの到着時間を複製する
   ResetLastError();
   if(CopyTime(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,time_buff)==-1)
     {
      PrintFormat("Failed to copy time values. Error code = %d",GetLastError());
      return;
     }
//--- バッファサイズを受け取る
   size=ArraySize(ma_buff);
//--- 指標で使用されたメモリを解放する
   IndicatorRelease(ma_handle);
//--- 指標値を書き込むためにファイルを開く(ファイルが存在しない場合は自動的に作成される)
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_BIN);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s file is available for writing",InpFileName);
      PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      //--- 初めにデータサンプルのサイズを書く
      FileWriteDouble(file_handle,(double)size);
      //--- 指標の時間と値をファイルに書く
      for(int i=0;i<size;i++)
        {
         FileWriteDouble(file_handle,(double)time_buff[i]);
         FileWriteDouble(file_handle,ma_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());
  }

MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: https://www.mql5.com/ru/code/1629

Demo_FileReadDatetime Demo_FileReadDatetime

この指標はFileReadDatetime()関数の使用例を実証します。

Demo_FileWrite Demo_FileWrite

このスクリプトはFileWrite() 関数の使用例を実証します。

Demo_FileReadDouble Demo_FileReadDouble

この指標はFileReadDouble() 関数の使用例を実証します。

Demo_FileSize Demo_FileSize

このスクリプトはFileSize() 関数の使用例を実証します。