Close_to_File

Download script
Author: Copyright � 2008, MetaQuotes Software Corp.
Close_to_File

This script is designed to automatically extract specific price data from your trading platform and save it into an organized file on your computer. It serves as a data export tool, allowing you to move information from the live market charts into a format that can be easily reviewed outside of the trading software.

How the Logic Works

Data Identification When the script is activated, it first identifies which financial instrument (like a specific currency pair) and which timeframe (such as daily, hourly, or minute-by-minute charts) you are currently viewing. It maps out the history of the price movements for that specific selection.

File Generation The tool then creates a new comma-separated values (CSV) file. The name of this file is automatically generated based on the asset and timeframe you are trading, ensuring that your data remains organized and doesn't overwrite other exports.

Data Extraction Process Once the file is created, the script performs the following steps:

  • It scans through the entire history of price bars available for the chosen period.
  • It specifically isolates the Closing Price—the final price at which a candle or bar finished during that specific timeframe.
  • It captures these prices in chronological order.

Saving and Finalizing The script writes every individual closing price into its own row within the generated file. Once every piece of data has been successfully recorded, it securely closes the file to ensure that all information is saved correctly and the file is ready for you to open in a spreadsheet program like Excel.

Summary of Use

In simple terms, this script acts as an automated "Copy-Paste" assistant. Instead of you having to manually record every closing price from your chart into a spreadsheet, the script reads that history for you and saves it into a clean, usable file in one click.

Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Uses files from the file systemIt writes information to file
12 Views
0 Downloads
0 Favorites
Close_to_File
//+------------------------------------------------------------------+
//|                                                Close_to_File.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


void Close_output(string SymbolName,int PeriodMinutes)
   {
   int size=iBars(SymbolName,PeriodMinutes);
//----
   if (size==0) return;
   int handle=FileOpen(SymbolName+PeriodMinutes+"_Close.csv",FILE_WRITE|FILE_CSV);
   if (handle<0) return;
  // FileWrite(handle,"Time seconds;Time;Open;Low;High;Close;Volume;RSI");
   for (int i=size-1;i>=0;i--)
      {
//      FileWrite(handle,iTime(SymbolName,PeriodMinutes,i),TimeToStr(iTime(SymbolName,PeriodMinutes,i))
//         ,iOpen(SymbolName,PeriodMinutes,i),iLow(SymbolName,PeriodMinutes,i),iHigh(SymbolName,PeriodMinutes,i)
//         ,iClose(SymbolName,PeriodMinutes,i),iVolume(SymbolName,PeriodMinutes,i),iCustom(SymbolName,PeriodMinutes,"RSI",0,i));
//      FileWrite(handle,iCustom(SymbolName,PeriodMinutes,"RSI",0,i));
FileWrite(handle,iClose(SymbolName,PeriodMinutes,i));
      }
   FileClose(handle);      
//----
   return;
   }
int PeriodNumber(int number)
   {
   int per_min;
   switch (number)
      {
      case 0: per_min=PERIOD_M1;break;
      case 1: per_min=PERIOD_M5;break;
      case 2: per_min=PERIOD_M15;break;
      case 3: per_min=PERIOD_M30;break;
      case 4: per_min=PERIOD_H1;break;
      case 5: per_min=PERIOD_H4;break;
      default: per_min=PERIOD_D1;break;
      }
   return(per_min);   
   }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
  Close_output(Symbol(),PeriodNumber(6)); 
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments