exoticwave
Download scriptThis script functions as an automated data logging tool designed to export historical price information from your trading platform into a structured external file. Instead of analyzing market trends for live trading, its primary purpose is to "snapshot" and save historical data for later review or use in other applications.
How the Process Works
1. Data Identification The script automatically identifies the specific financial instrument (symbol) and the timeframe you are currently viewing on your chart. It uses this information to generate a unique filename, ensuring that data from different assets or timeframes is saved separately.
2. Initialization and Cooling Period To prevent the software from overwhelming your computer's resources, the script includes a built-in "waiting period." When you first load the indicator, it remains idle for a specified number of market ticks (user-defined). This ensures the platform is stable before it begins the heavy task of writing files.
3. Data Extraction Loop Once the waiting period has passed, the script performs a comprehensive backward scan of your chart history. It starts from a specific point in the past (determined by the user's settings) and moves forward one bar at a time. For every single bar it encounters, it captures the following information:
- Date and Time: Broken down into Year, Month, Day, Hour, Minute, and Second.
- Price Action: The Opening, High, Low, and Closing prices.
- Trading Volume: The amount of activity during that specific bar.
4. File Generation and Formatting As the script scans the history, it organizes this data into a clean, comma-separated format (CSV). It creates a new file every time it runs, effectively refreshing the data to include the most recent market movements.
5. User Feedback Throughout the process, the script provides visual updates on your trading chart. You will see a status comment appearing on the screen, confirming the progress of the save operation and notifying you once the data has been successfully exported to your storage.
//+------------------------------------------------------------------+
//| Copyright © 2005, FX Waves :)
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Sprrite&Lemon"
#property link "wladimir447@yandex.ru"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- input parameters
extern int Bar=1900;
extern int LastBar=0;
extern int cnttik = 3 ;
double ExtMapBuffer1[];
// ??????? ???? ? ?? ?????? N-? ??? ????????? ???? ?????????
int tick = 0 ;
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
string sName="",ss1=" ",ss2=" ";
int file=0, NumBar=0, shift=0;
int Ye=0,Mo=0,Da=0,Ho=0,Mi=0,Se=0,Ti=0;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
// ??????? ???? ;
tick++;
if ( tick <= cnttik )
{
Print(" Tick = ", tick);
Comment( tick ,"/", cnttik ," | " , Bars);
// ????? ???? ! - ?????????
return(0) ;
}
else
{
tick = 0 ;
// ??????? ??????????? ????
//int rfile = FileOpen("sprrite.csv",FILE_CSV|FILE_WRITE,",");
//FileWrite(rfile,"yes");
//FileClose(rfile);
}
//int filesh = FileOpen("zag.csv",FILE_CSV|FILE_READ);
// string sh = FileReadString(filesh);
// FileClose( filesh );
//----
if ( 1 == 1)
{
// ???
sName=Symbol()+Period()+".csv";
// ??????? ??????????
FileDelete(sName);
file =FileOpen(sName,FILE_CSV|FILE_WRITE,",");
// FileWrite(file,sh);
shift=Bar+LastBar-1;
while(shift>=0)
{
Ti=Time[shift];
Ye=TimeYear(Ti);
Mo=TimeMonth(Ti);
Da=TimeDay(Ti);
Ho=TimeHour(Ti);
Mi=TimeMinute(Ti);
if ( Ho == 0 && Mi == 0 ) Mi = 1 ;
Se=TimeSeconds(Ti);
ss1=Ye;
if (Mo<10) ss1=ss1+"0"+Mo; else ss1=ss1+Mo;
if (Da<10) ss1=ss1+"0"+Da; else ss1=ss1+Da;
if (Ho<10) ss2="0"+Ho; else ss2=Ho;
if (Mi<10) ss2=ss2+"0"+Mi; else ss2=ss2+Mi;
FileWrite(file,ss1,ss2,Open[shift],High[shift],Low[shift],Close[shift],Volume[shift]);
shift--;
}
Comment( " Save of "+ss1+" "+ss2+" is ok" , " === " , Bars);
NumBar=counted_bars;
FileClose(file);
Print(" ???????? " , Bars);
}
//----
return(0);
}
Comments