//+------------------------------------------------------------------+ //| Demo_FileReadLong.mq5 | //| Copyright 2013, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_buffers 1 #property indicator_plots 1 //---- plot Label1 #property indicator_label1 "Volume" #property indicator_type1 DRAW_LINE #property indicator_color1 clrYellow #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_separate_window //--- verinin okunması için gereken parametreler input string InpFileName="Volume.bin"; // dosya ismi input string InpDirectoryName="Data"; // dizin ismi //--- global değişkenler int ind=0; int size=0; long volume_buff[]; datetime time_buff[]; //--- gösterge tamponları double buff[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- dosyayı aç ResetLastError(); int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_BIN); if(file_handle!=INVALID_HANDLE) { PrintFormat("%s dosyası, yazma amacıyla açıldı",InpFileName); PrintFormat("Dosya yolu: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH)); //--- ilk önce, dosyada bulunan veri miktarını oku size=(int)FileReadLong(file_handle); //--- diziler için bellek tahsis et ArrayResize(volume_buff,size); ArrayResize(time_buff,size); //--- dosyadan veriyi oku for(int i=0;i<size;i++) { time_buff[i]=(datetime)FileReadLong(file_handle); volume_buff[i]=FileReadLong(file_handle); } //--- dosyayı kapat FileClose(file_handle); PrintFormat("Veriler okundu, %s dosyası kapatıldı",InpFileName); } else { PrintFormat("%s dosyası açılamadı, Hata kodu = %d",InpFileName,GetLastError()); return(INIT_FAILED); } //--- diziyi, 0 indisli gösterge tamponuna bağla SetIndexBuffer(0,buff,INDICATOR_DATA); //---- çizelgede görüntülenecek gösterge değerlerini ayarla PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { ArraySetAsSeries(time,false); //--- hala işlenmemiş çubuklar için döngü for(int i=prev_calculated;i<rates_total;i++) { //--- varsayılan olarak 0 buff[i]=0; //--- hala, herhangi bir veri mevcut mu kontrol et if(ind<size) { for(int j=ind;j<size;j++) { //--- tarihler örtüşüyorsa dosyadaki değeri kullan if(time[i]==time_buff[j]) { buff[i]=(double)volume_buff[j]; ind=j+1; break; } } } } //--- bir sonraki çağrı için prev_calculated değerine dönüş yap return(rates_total); } |