Download MetaTrader 5

How to show a datetime in Data Window for my custom indicator?

To add comments, please log in or register
Rodrigo Pandini
560
Rodrigo Pandini 2016.08.13 17:41 
Is possible to show a value different from a double type in the Data Window?
I would like to show a value of type datetime for my custom indicator.
Files:
Ernst Van Der Merwe
4797
Ernst Van Der Merwe 2016.08.13 20:57  
double _Date[];
double _Time[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,_Date);
   SetIndexLabel(0,"Date");
   SetIndexBuffer(1,_Time);
   SetIndexLabel(1,"Time");
   IndicatorDigits(2);
//---
   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[])
  {
//---
   for(int i=rates_total-1;i>=0;i--)
     {
      int month=TimeMonth(time[i]);
      int day=TimeDay(time[i]);
      _Date[i]=month+day/100.0;
      int hour=TimeHour(time[i]);
      int minute=TimeMinute(time[i]);
      _Time[i]=hour+minute/100.0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }

MqlDateTime dt;
double _Date[];
double _Time[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,_Date);
   PlotIndexSetString(0,PLOT_LABEL,"Date");
   SetIndexBuffer(1,_Time);
   PlotIndexSetString(1,PLOT_LABEL,"Time");
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//---
   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[])
  {
//---
   for(int i=rates_total-1;i>=0;i--)
     {
      TimeToStruct(time[i],dt);
      _Date[i]=dt.mon+dt.day/100.0;
      _Time[i]=dt.hour+dt.min/100.0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
To add comments, please log in or register