거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
스크립트

Demo_FileWriteInteger - MetaTrader 5용 스크립트

조회수:
4944
평가:
(34)
게시됨:
2013.04.15 08:41
업데이트됨:
2016.11.22 07:32
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

The script gets prices from the specified symbol, analyzes them and writes price movement data in the binary file in certain periods of time. The FileWriteInteger() function is used for writing all data.

Date value will be preliminary converted to the string, split to the uchar type array and then written in the file using the function.

Code:

//--- show the window of input parameters when launching the script
#property script_show_inputs
//--- parameters for receiving data from the terminal
input string             InpSymbolName="EURUSD";           // currency pair
input ENUM_TIMEFRAMES    InpSymbolPeriod=PERIOD_H1;        // timeframe
input datetime           InpDateStart=D'2013.01.01 00:00'; // data copying start date
//--- parameters for writing data to the file
input string             InpFileName="Trend.bin"; // file name
input string             InpDirectoryName="Data"; // directory name
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime date_finish=TimeCurrent();
   double   close_buff[];
   datetime time_buff[];
   int      size;
//--- reset the error value
   ResetLastError();
//--- copy the close price for each bar
   if(CopyClose(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,close_buff)==-1)
     {
      PrintFormat("Failed to copy the values of close prices. Error code = %d",GetLastError());
      return;
     }
//--- copy the close price for each bar
   if(CopyTime(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,time_buff)==-1)
     {
      PrintFormat("Failed to copy the values of close prices. Error code = %d",GetLastError());
      return;
     }
//--- receive the buffer size
   size=ArraySize(close_buff);
//--- open the file for writing the values (if the file is absent, it will be created automatically)
   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));
      //--- 
      int   up_down=0; // trend flag
      int   arr_size;  // arr array size
      uchar arr[];     // uchar type array
      //--- write time values to the file
      for(int i=0;i<size-1;i++)
        {
         //--- compare close prices of the current and next bars
         if(close_buff[i]<=close_buff[i+1])
           {
            if(up_down!=1)
              {
               //--- write date value to the file using FileWriteInteger
               StringToCharArray(TimeToString(time_buff[i]),arr);
               arr_size=ArraySize(arr);
               //--- first, write the number of symbols in the array
               FileWriteInteger(file_handle,arr_size,INT_VALUE);
               //--- write the symbols
               for(int j=0;j<arr_size;j++)
                  FileWriteInteger(file_handle,arr[j],CHAR_VALUE);
               //--- change the trend flag
               up_down=1;
              }
           }
         else
           {
            if(up_down!=-1)
              {
               //--- write the date value to the file using FileWriteInteger
               StringToCharArray(TimeToString(time_buff[i]),arr);
               arr_size=ArraySize(arr);
               //--- first, write the number of symbols in the array
               FileWriteInteger(file_handle,arr_size,INT_VALUE);
               //--- write the symbols
               for(int j=0;j<arr_size;j++)
                  FileWriteInteger(file_handle,arr[j],CHAR_VALUE);
               //--- change the trend flag
               up_down=-1;
              }
           }
        }
      //--- close the file
      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/1635

Demo_FileTell Demo_FileTell

The script demonstrates the example of using the FileTell() function

Demo_FileSize Demo_FileSize

The script demonstrates the example of using the FileSize() function

Demo_FileReadInteger Demo_FileReadInteger

The indicator demonstrates the example of using the FileReadInteger() function

Profit Loss Calculator Profit Loss Calculator

Calculator-panel to calculate profit/loss. Data is calculated either when moving lines, or changing the parameters in input fields of the entry price, lot, profit or loss in pips or in deposit currency