// MQL4

#property indicator_chart_window

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

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[])
  {
    int limit = rates_total - prev_calculated;
   
    if(limit == 0)
       limit = 1;
      
    for(int i = limit - 1; i >= 0; i--)
    { 
      int dt = TimeMinute(time[i]);
 
      Print("dt[", i, "] = ", dt);
    }

   return(rates_total);
  }

 

(一部引用 : http://fx-on.com/education/study/?p=2 )

 

 

// MQL5

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[])
  {
     int limit = rates_total - prev_calculated;
    
     if(limit == 0)
        limit = 1;
       
     ArraySetAsSeries(time, true);  
    
     //???CopyTime(_Symbol, _Period, 0, limit, time); // no one of the overloads can be
                                                      // applied to the function call
       
     for(int i = limit - 1; i >= 0; i--)
     {
        int dt = timeminuteMQL5(time[i]);
       
        Print("dt[", i, "] = ", dt);
      }  
   return(rates_total);
  }
 
int timeminuteMQL5(datetime date)
 {
    MqlDateTime tm;
    TimeToStruct(date, tm);
  
    return(tm.min);
  }
----------------------------------------------
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, true);        Print("time[0] = ", time[0]);
   ArraySetAsSeries(close, true);       Print("close[0] = ", close[0]);
   ArraySetAsSeries(tick_volume, true); Print("tick_volume[0] = ", tick_volume[0]);
   ArraySetAsSeries(volume, true);      Print("volume[0] = ", volume[0]);
   ArraySetAsSeries(spread, true);      Print("spread[0] = ", spread[0]);
 
   return(rates_total);
}