//+------------------------------------------------------------------+
//|                                               TimeOfDayClose.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012 zznbrm"
#property indicator_chart_window
#define IND_NAME "TODC-"

//+------------------------------------------------------------------+
//| User Inputs                                                      |
//+------------------------------------------------------------------+
extern string estrTimeOfDay = "12:00";
extern int eintCode = SYMBOL_RIGHTPRICE;
extern int eintWidth = 1;
extern color eclr = White;

//+------------------------------------------------------------------+
//| Indicator Buffers                                                |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Globals                                                          |
//+------------------------------------------------------------------+
int gintHour, gintMin;

//+------------------------------------------------------------------+
//| init()                                                           |
//+------------------------------------------------------------------+
int init()
{
   IndicatorShortName( "TimeOfDayClose" );
   
   gintHour = StrToInteger( StringSubstr( estrTimeOfDay, 0, 2 ) );
   gintMin = StrToInteger( StringSubstr( estrTimeOfDay, 3, 2 ) );
   
   return( 0 );
}

//+------------------------------------------------------------------+
//| deinit()                                                         |
//+------------------------------------------------------------------+
int deinit()
{   
   ObjectsDeleteAll( 0, OBJ_ARROW );
   return( 0 );
}

//+------------------------------------------------------------------+
//| start()                                                          |
//+------------------------------------------------------------------+
int start()
{
   int intCountedBars = IndicatorCounted();

   if ( intCountedBars < 0 ) return( -1 );   
   if ( intCountedBars > 0 ) intCountedBars--;
   
   int intMax = Bars - intCountedBars;
      
   for ( int inx = intMax; inx >= 0; inx-- )
   {
      if ( ( TimeHour( Time[inx] ) == gintHour ) && ( TimeMinute( Time[inx] ) == gintMin ) )
      {
         drawArrow( IND_NAME + Time[inx], Close[inx], Time[inx] );
      }
   }
   
   return( 0 );
}

//+------------------------------------------------------------------+
//| drawArrow                                                        |
//+------------------------------------------------------------------+
void drawArrow( string strName, double dblPrice, datetime dt )
{
   if ( ObjectFind( strName ) == -1 )
   {
      ObjectCreate( strName, OBJ_ARROW, 0, dt, dblPrice );
      ObjectSet( strName, OBJPROP_ARROWCODE, eintCode );      
      ObjectSet( strName, OBJPROP_WIDTH, eintWidth );
      ObjectSet( strName, OBJPROP_COLOR, eclr );
   }
   else
      ObjectMove( strName, 0, dt, dblPrice );   
}


