당사 팬 페이지에 가입하십시오
- 조회수:
- 4351
- 평가:
- 게시됨:
- 2013.04.10 13:09
- 업데이트됨:
- 2016.11.22 07:32
-
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
The script gets the values of the Moving Average indicator and writes them in the binary file in "Data" subdirectory of the local terminal folder. In script input parameters can be specified parameters for the MA indicator calculation, the name of the currency pair and timeframe, as well as date from which we will calculate the indicator values.
In addition to the MA indicator values the corresponding values of time preliminary led to a double type are also written to the file.
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="EURJPY"; // currency pair input ENUM_TIMEFRAMES InpSymbolPeriod=PERIOD_M15; // timeframe input int InpMAPeriod=10; // smoothing period input int InpMAShift=0; // indicator shift input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // smoothing type input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // price type input datetime InpDateStart=D'2013.01.01 00:00'; // data copying start date //--- parameters for writing data to the file input string InpFileName="MA.csv"; // file name input string InpDirectoryName="Data"; // directory name //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { datetime date_finish=TimeCurrent(); double ma_buff[]; datetime time_buff[]; int size; //--- get MA indicator handle ResetLastError(); int ma_handle=iMA(InpSymbolName,InpSymbolPeriod,InpMAPeriod,InpMAShift,InpMAMethod,InpAppliedPrice); if(ma_handle==INVALID_HANDLE) { //--- failed to get the indicator handle PrintFormat("Error when receiving indicator handle. Error code = %d",GetLastError()); return; } //--- being in the loop until the indicator calculates all its values while(BarsCalculated(ma_handle)==-1) Sleep(20); // a pause to allow the indicator to calculate all its values PrintFormat("Indicator values starting from %s will be written to the file",TimeToString(InpDateStart)); //--- copy the indicator values ResetLastError(); if(CopyBuffer(ma_handle,0,InpDateStart,date_finish,ma_buff)==-1) { PrintFormat("Failed to copy the indicator values. Error code = %d",GetLastError()); return; } //--- copy the time of the appropriate bars' arrival ResetLastError(); if(CopyTime(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,time_buff)==-1) { PrintFormat("Failed to copy time values. Error code = %d",GetLastError()); return; } //--- receive the buffer size size=ArraySize(ma_buff); //--- free the memory occupied by the indicator IndicatorRelease(ma_handle); //--- open the file for writing the indicator 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)); //--- first, write the size of data sample FileWriteDouble(file_handle,(double)size); //--- write the indicator time and value to the file for(int i=0;i<size;i++) { FileWriteDouble(file_handle,(double)time_buff[i]); FileWriteDouble(file_handle,ma_buff[i]); } //--- 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/1629
![Demo_FileReadDatetime](https://c.mql5.com/i/code/indicator.png)
The indicator demonstrates the example of using the FileReadDatetime() function
![Demo_FileWrite](https://c.mql5.com/i/code/script.png)
The script demonstrates the example of using the FileWrite() function
![Demo_FileReadDouble](https://c.mql5.com/i/code/indicator.png)
The indicator demonstrates the example of using the FileReadDouble() function
![Demo_FileSize](https://c.mql5.com/i/code/script.png)
The script demonstrates the example of using the FileSize() function