after Mq4 to mq5 --- Code not working

 

Hi guys,


I've converted mq4 to mq5, here is the code, however,

I'm not able to make it work 

here is the final result, vertical lines indicating each hour.



here is the original code


//+------------------------------------------------------------------+
//|                                                      Time_H1.mq4 |
//|                                                     Yuriy Tokman |
//|                                            yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "yuriytokman@gmail.com"

#property indicator_chart_window
extern int       barsToProcess=24;
extern color     colir = Gray;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   int i;
  
  
  
   for (i=0;i<Bars;i++)
    {
    ObjectDelete("Line "+DoubleToStr(i,0));
    }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(),
//----
   limit,
   i=0; 
   if(counted_bars>0)
      counted_bars--;
   
   limit=Bars-counted_bars;
   
   if(limit>barsToProcess)
      limit=barsToProcess;

   while (i<limit)
   {           
      datetime t = iTime(NULL,PERIOD_H1,i);
      if (t>0)
       {
        ObjectCreate("Line "+DoubleToStr(i,0),OBJ_VLINE,0,t,0);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_STYLE,STYLE_DASHDOTDOT);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_COLOR,colir);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);
       }            
     i++;  
   }  
//----
   return(0);
  }
//+------------------------------------------------------------------+


here is my effort on conversion



//+------------------------------------------------------------------+
//|                                                      Time_H1.mq5 |
//|                                                     Yuriy Tokman |
//|                                            yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "yuriytokman@gmail.com"

#property indicator_chart_window
#property indicator_plots   1
#property indicator_buffers 1

input int       barsToProcess=24;
input color     colir = Gray;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  //:::::::::::::::::::::::::::::::::::::::::::::
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  int Bars=Bars(Symbol(),PERIOD_CURRENT);
  double Point=Point();
  //Etc.
  //:::::::::::::::::::::::::::::::::::::::::::::::

//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)

  {
  //:::::::::::::::::::::::::::::::::::::::::::::
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  int Bars=Bars(Symbol(),PERIOD_CURRENT);
  double Point=Point();
  //Etc.
  //:::::::::::::::::::::::::::::::::::::::::::::::

//----
   int i;
  
  
  
   for (i=0;i<Bars;i++)
    {
    ObjectDelete(0,"Line "+DoubleToString(i,0));
    }   
//----
  // return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
  //:::::::::::::::::::::::::::::::::::::::::::::
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  int Bars=Bars(Symbol(),PERIOD_CURRENT);
  double Point=Point();
  //Etc.
  //:::::::::::::::::::::::::::::::::::::::::::::::



   int    counted_bars=50,
//----
   limit,
   i=0; 
   if(counted_bars>0)
      counted_bars--;
   
   limit=Bars-counted_bars;
   
   if(limit>barsToProcess)
      limit=barsToProcess;

   while (i<limit)
   {           
       datetime DayTime[];
     
      if (CopyTime(NULL,PERIOD_H1,counted_bars,i,DayTime)>0)
       {
        ObjectCreate(0,"Line "+DoubleToString(i,0),OBJ_VLINE,0,0,0);
        ObjectSetInteger(0,"Line "+DoubleToString(i,0),OBJPROP_STYLE,STYLE_DASHDOTDOT);
        ObjectSetInteger(0,"Line "+DoubleToString(i,0),OBJPROP_COLOR,colir);
        ObjectSetInteger(0,"Line "+DoubleToString(i,0),OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);
       }            
     i++;  
   }  
//----
   return(rates_total);
  }
//+------------------------------------------------------------------+


 
//+------------------------------------------------------------------+
//|                                                      Time_H1.mq5 |
//|                                                        avoitenko |
//|                        https://www.mql5.com/ru/users/avoitenko |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "https://www.mql5.com/ru/users/avoitenko"
#property version   "1.01"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1

input uint   barsToProcess=24;
input color colir=clrGray;

datetime time[];
//+------------------------------------------------------------------+
int OnInit()
//+------------------------------------------------------------------+
  {
// ArraySetAsSeries(time,true);
   return(0);
  }
//+------------------------------------------------------------------+  
void OnDeinit(const int reason)
//+------------------------------------------------------------------+
  {
   for(uint i=0;i<barsToProcess;i++)
     {
      ObjectDelete(0,"Line "+DoubleToString(i,0));
     }
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
//+------------------------------------------------------------------+
  {

   uint limit;

   if(prev_calculated>rates_total || prev_calculated<=0) limit=rates_total-1;
   else limit=rates_total-prev_calculated;

   if(limit>barsToProcess)limit=barsToProcess;

   if(CopyTime(_Symbol,PERIOD_H1,0,limit,time)!=limit) return(0);

   for(uint i=0; i<limit; i++)
     {
      string name="Line "+IntegerToString(i);
      if(ObjectFind(0,name)<0) ObjectCreate(0,name,OBJ_VLINE,0,time[i],0);

      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DASHDOTDOT);
      ObjectSetInteger(0,name,OBJPROP_COLOR,colir);
      ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);
     }
//----
   return(rates_total);
  }
//+------------------------------------------------------------------+

 


Thanks for the code, :) it is working 

One small issue, the indicator doesn't update it self  for the next day or coming hours.