//+——————————————————————+ //| Demo_FileReadLong.mq5 | //| Copyright 2013, MetaQuotes Software Corp. | //| https://www.mql5.com | //+——————————————————————+ #propertycopyright“Copyright 2013, MetaQuotes Software Corp.” #propertylink“https://www.mql5.com” #propertyversion“1.00” #propertyindicator_buffers 1 //—- plot Label1 #propertyindicator_label1“Volume” #propertyindicator_type1DRAW_LINE #propertyindicator_color1clrYellow #propertyindicator_style1STYLE_SOLID #propertyindicator_width1 2 #propertyindicator_separate_window //— parameters for data reading inputstringInpFileName=“Volume.bin”; // file name inputstringInpDirectoryName=“Data”; // directory name //— global variables int ind=0; int size=0; long volume_buff[]; datetime time_buff[]; //— indicator buffers double buff[]; //+——————————————————————+ //| Custom indicator initialization function | //+——————————————————————+ intOnInit() { //— open the file ResetLastError(); int file_handle=FileOpen(InpDirectoryName+“//”+InpFileName,FILE_READ|FILE_BIN); if(file_handle!=INVALID_HANDLE) { PrintFormat(“%s file is open for writing”,InpFileName); PrintFormat(“File path: %s\\Files\\”,TerminalInfoString(TERMINAL_DATA_PATH)); //— first, read the amount of data in the file size=(int)FileReadLong(file_handle); //— allocate memory for the arrays ArrayResize(volume_buff,size); ArrayResize(time_buff,size); //— read data from the file for(int i=0;i<size;i++) { time_buff[i]=(datetime)FileReadLong(file_handle); volume_buff[i]=FileReadLong(file_handle); } //— close the file FileClose(file_handle); PrintFormat(“Data is read, %s file is closed”,InpFileName); } else { PrintFormat(“Failed to open %s file, Error code = %d”,InpFileName,GetLastError()); return(INIT_FAILED); } //— bind the array to the indicator buffer with 0 index SetIndexBuffer(0,buff,INDICATOR_DATA); //—- set the indicator values that will be visible on the chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); //— return(INIT_SUCCEEDED); } //+——————————————————————+ //| Custom indicator iteration function | //+——————————————————————+ intOnCalculate(constint rates_total, constint prev_calculated, constdatetime &time[], constdouble &open[], constdouble &high[], constdouble &low[], constdouble &close[], constlong &tick_volume[], constlong &volume[], constint &spread[]) { ArraySetAsSeries(time,false); //— the loop for the bars that have not been handled yet for(int i=prev_calculated;i<rates_total;i++) { //— 0 by default buff[i]=0; //— check if any data is still present if(ind<size) { for(int j=ind;j<size;j++) { //— if dates coincide, the value from the file is used if(time[i]==time_buff[j]) { buff[i]=(double)volume_buff[j]; ind=j+1; break; } } } } //— return value of prev_calculated for next call return(rates_total); }