FileReadDatetime

Bu fonksiyon, bir CSV dosyasından, "YYYY.MM.DD HH:MI:SS", "YYYY.MM.DD" veya "HH:MI:SS" biçimlerinden birine sahip bir dizgiyi okur ve ardından datetime tipine çevirir.

datetime  FileReadDatetime(
   int  file_handle    // Dosya tanıtıcısı
   );

Parametreler

file_handle

[in] FileOpen() fonksiyonunun dönüş yaptığı dosya tanımlayıcısı.

Dönüş değeri

datetime tipi değer.

Örnek (burada kullanılan dosya, FileWrite fonksiyonu örneğinden elde edilmiştir)

//+------------------------------------------------------------------+
//|                                        Demo_FileReadDateTime.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_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//---- plot Label1
#property indicator_label1  "UpSignal"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  4
//---- plot Label2
#property indicator_label2  "DownSignal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  4
//--- verinin okunması için gereken parametreler
input string InpFileName="MACD.csv";  // dosya ismi
input string InpDirectoryName="Data"// dizin ismi
//--- global değişkenler
int      ind=0;       // indis
double   upbuff[];    // yukarı yönlü okların gösterge tamponu
double   downbuff[];  // aşağı yönlü okların gösterge tamponu
bool     sign_buff[]; // sinyal dizisi (true - al, false - sat)
datetime time_buff[]; // sinyal geliş zamanının dizisi
int      size=0;      // sinyal dizilerinin boyutu
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- dosyayı aç
   ResetLastError();
   int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_CSV);
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s dosyası okuma için açıldı",InpFileName);
      //--- ilk olarak, sinyallerin sayısını oku
      size=(int)FileReadNumber(file_handle);
      //--- diziler için bellek tahsis et
      ArrayResize(sign_buff,size);
      ArrayResize(time_buff,size);
      //--- dosyadan veriyi oku
      for(int i=0;i<size;i++)
        {
         //--- sinyal zamanı
         time_buff[i]=FileReadDatetime(file_handle);
         //--- sinyal değeri
         sign_buff[i]=FileReadBool(file_handle);
        }
      //--- dosyayı kapat
      FileClose(file_handle);
     }
   else
     {
      PrintFormat("%s dosyası açılamadı, Hata kodu = %d",InpFileName,GetLastError());
      return(INIT_FAILED);
     }
//--- dizilerin bağlanması
   SetIndexBuffer(0,upbuff,INDICATOR_DATA);
   SetIndexBuffer(1,downbuff,INDICATOR_DATA);
//--- PLOT_ARROW içinde kullanılacak sembol kodunu ayarla
   PlotIndexSetInteger(0,PLOT_ARROW,241);
   PlotIndexSetInteger(1,PLOT_ARROW,242);
//---- çizelgede görüntülenmesi istenmeyen gösterge değerlerini ayarla
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   PlotIndexSetDouble(1,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);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(high,false);
//--- hala işlenmemiş çubuklar için döngü
   for(int i=prev_calculated;i<rates_total;i++)
     {
      //--- varsayılan olarak 0
      upbuff[i]=0;
      downbuff[i]=0;
      //--- hala, herhangi bir veri mevcut mu kontrol et
      if(ind<size)
        {
         for(int j=ind;j<size;j++)
           {
            //--- Eğer tarihler örtüşüyorsa, dosyadaki değeri kullan
            if(time[i]==time_buff[j])
              {
               //--- sinyale göre ok çiz
               if(sign_buff[j])
                  upbuff[i]=high[i];
               else
                  downbuff[i]=low[i];
               //--- sayacı artır
               ind=j+1;
               break;
              }
           }
        }
     }
//--- bir sonraki çağrı için prev_calculated değerine dönüş yap
   return(rates_total);
  }

Ayrıca Bakınız

datetime Tipi, StringToTime, TimeToString, FileWrite