labelling issue with code and scaling question

 

Hello forum, I put this indicator together to allow me to mark some local times on my charts that I have interest in.

Seems to work fine except for the labelling.

The lines draw where they should, but only 3 of the 6 labels work the way I hoped and I can't see the error or difference between working and non working code.

Hope someone not as close to this as me, will point out the error.

Also I set the label height as the current Ask price.

I am wondering if someone might suggest a better approach such that the labels always appear visible on the screen when price moves away from the Ask (previous charts)

thanks in advance!



//+------------------------------------------------------------------+
//|                                                                  |
//|                  local market time vertical lines                |
//|                                                                  |
//+------------------------------------------------------------------+

//---- indicator settings

#property  indicator_chart_window
#property  indicator_buffers 0
//----
//---- indicator parameters
extern int             CloseHour            = 1;
extern int             CloseMin             = 30;
extern int             CloseHour2           = 2;
extern int             CloseMin2            = 0;
extern int             CloseHour3           = 3;
extern int             CloseMin3            = 0;
extern int             CloseHour4           = 4;
extern int             CloseMin4            = 27;
extern int             CloseHour5           = 5;
extern int             CloseMin5            = 30;
extern int             CloseHour6           = 7;
extern int             CloseMin6            = 29;
extern int             Limit                = 50;
extern int             font_size            = 8;      // sets font size
extern string          help1                = "set true to show time vertical lines";
extern bool            CloseLine            = true;   // set true to display vertical lines
extern bool            CloseLine_label      = true;   // set true to display label, time of vertical line
extern bool            CloseLine2           = true;   // set true to display vertical lines
extern bool            CloseLine2_label     = true;   // set true to display label, time of vertical line
extern bool            CloseLine3           = true;   // set true to display vertical lines
extern bool            CloseLine3_label     = true;   // set true to display label, time of vertical line
extern bool            CloseLine4           = true;   // set true to display vertical lines
extern bool            CloseLine4_label     = true;   // set true to display label, time of vertical line
extern bool            CloseLine5           = true;   // set true to display vertical lines
extern bool            CloseLine5_label     = true;   // set true to display label, time of vertical line
extern bool            CloseLine6           = true;   // set true to display vertical lines
extern bool            CloseLine6_label     = true;   // set true to display label, time of vertical line
double                 CloseTime,CloseTime2,CloseTime3,CloseTime4,CloseTime5,CloseTime6;
datetime               Bar1Time;          //  used to check if the curen tick is for a new bar

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
   {
   IndicatorShortName("CloseLine");
   IndicatorShortName("CloseLine2");
   IndicatorShortName("CloseLine3");
   IndicatorShortName("CloseLine4");
   IndicatorShortName("CloseLine5");
   IndicatorShortName("CloseLine6");
   //---- initialization done
   return(0);
   }    
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
   { 
   for (int i=0; i<=Limit; i++)
   {
   ObjectDelete("CloseLine"+i);
   ObjectDelete("CloseLine2"+i);
   ObjectDelete("CloseLine3"+i);
   ObjectDelete("CloseLine4"+i);
   ObjectDelete("CloseLine5"+i);
   ObjectDelete("CloseLine6"+i);
   ObjectDelete("CloseLine_label"+i);
   ObjectDelete("CloseLine2_label"+i);
   ObjectDelete("CloseLine3_label"+i);
   ObjectDelete("CloseLine4_label"+i);
   ObjectDelete("CloseLine5_label"+i);
   ObjectDelete("CloseLine6_label"+i);
   }
   return(0);
   }
//+------------------------------------------------------------------+
//| Other timeframe line levels                                      |
//+------------------------------------------------------------------+
int start()
//
 {   
//-- Comment("") Only update the objects if they need updating   
       if( iTime(NULL, PERIOD_H1, 1) == Bar1Time) return(0);
          Bar1Time  = iTime(NULL,PERIOD_H1,1); 
   {
       for (int i=0; i<=Limit; i++)
       {          
       CloseTime =(iTime(Symbol(),PERIOD_D1,i)+CloseHour *60*60+CloseMin *60);
       CloseTime2=(iTime(Symbol(),PERIOD_D1,i)+CloseHour2*60*60+CloseMin2*60);
       CloseTime3=(iTime(Symbol(),PERIOD_D1,i)+CloseHour3*60*60+CloseMin3*60);
       CloseTime4=(iTime(Symbol(),PERIOD_D1,i)+CloseHour4*60*60+CloseMin4*60);
       CloseTime5=(iTime(Symbol(),PERIOD_D1,i)+CloseHour5*60*60+CloseMin5*60);
       CloseTime6=(iTime(Symbol(),PERIOD_D1,i)+CloseHour6*60*60+CloseMin6*60);
           
  //-- Draw 1st Market CloseLine;
       if (CloseLine) // draw if true
         {
          string objectname = "CloseLine"+i;
          if (ObjectFind   (objectname) == -1) 
              ObjectCreate (objectname, OBJ_VLINE, 0, CloseTime, 0);
              ObjectSet    (objectname, OBJPROP_COLOR,       Blue);
              ObjectSet    (objectname, OBJPROP_WIDTH,       1); 
         }
        //-- Draw Market CloseLine Label -----------------------------------------      
             if (CloseLine_label) // draw if true
                {
                 objectname = "CloseLine_label"+i;
          
                 if (ObjectFind   (objectname) == -1) 
                     ObjectCreate (objectname, OBJ_TEXT, 0, 0, 0);
                     ObjectSet    (objectname, OBJPROP_TIME1,CloseTime );
                     ObjectSet    (objectname, OBJPROP_PRICE1, (Ask+2*Point) );
                     ObjectSet    (objectname, OBJPROP_COLOR, Black);
                     ObjectSetText(objectname, "10:30AM:", font_size, "Arial", Black);
                }
  //-- Draw CloseLine2;         
       if (CloseLine2) // draw if true
         {
          string objectname2 = "CloseLine2"+i;
          if (ObjectFind   (objectname2) == -1) 
              ObjectCreate (objectname2, OBJ_VLINE, 0, CloseTime2, 0);
              ObjectSet    (objectname2, OBJPROP_COLOR,       Blue);
              ObjectSet    (objectname2, OBJPROP_WIDTH,       1); 
         }
        //-- Draw CloseLine2 Label -----------------------------------------      
             if (CloseLine2_label) // draw if true
                {
                 objectname2 = "CloseLine2_label"+i;
          
                 if (ObjectFind   (objectname2) == -1) 
                 ObjectCreate (objectname2, OBJ_TEXT, 0, 0, 0);
                 ObjectSet    (objectname2, OBJPROP_TIME1,CloseTime2 );
                 ObjectSet    (objectname2, OBJPROP_PRICE1, (Ask+2*Point) );
                 ObjectSet    (objectname2, OBJPROP_COLOR, Black);
                 ObjectSetText(objectname2, "11:00AM:", font_size, "Arial", Black);
                }
  //-- Draw CloseLine3          
       if (CloseLine3) // draw if true
         {
          string objectname3 = "CloseLine3"+i;
          if (ObjectFind   (objectname3) == -1) 
              ObjectCreate (objectname3, OBJ_VLINE, 0, CloseTime3, 0);
              ObjectSet    (objectname3, OBJPROP_COLOR,       Blue);
              ObjectSet    (objectname3, OBJPROP_WIDTH,       1); 
         }
        //-- Draw CloseLine3 Label -----------------------------------------      
             if (CloseLine3_label) // draw if true
                {
                 objectname3 = "CloseLine3_label"+i;
          
                 if (ObjectFind   (objectname3) == -1) 
                 ObjectCreate (objectname3, OBJ_TEXT, 0, 0, 0);
                 ObjectSet    (objectname3, OBJPROP_TIME1,CloseTime3 );
                 ObjectSet    (objectname3, OBJPROP_PRICE1, (Ask+2*Point) );
                 ObjectSet    (objectname3, OBJPROP_COLOR, Black);
                 ObjectSetText(objectname3, "12:00PM:", font_size, "Arial", Black);
          }
  //-- Draw CloseLine4
       if (CloseLine4) // draw if true
         {
          string objectname4 = "CloseLine4"+i;
          if (ObjectFind   (objectname4) == -1) 
              ObjectCreate (objectname4, OBJ_VLINE, 0, CloseTime4, 0);
              ObjectSet    (objectname4, OBJPROP_COLOR,       Blue);
              ObjectSet    (objectname4, OBJPROP_WIDTH,       1); 
         }
        //-- Draw CloseLine4 Label -----------------------------------------      
             if (CloseLine4_label) // draw if true
                {
                 objectname4 = "CloseLine4_label"+i;
          
                 if (ObjectFind   (objectname4) == -1) 
                 ObjectCreate (objectname4, OBJ_TEXT, 0, 0, 0);
                 ObjectSet    (objectname4, OBJPROP_TIME1,CloseTime4 );
                 ObjectSet    (objectname4, OBJPROP_PRICE1, (Ask+2*Point) );
                 ObjectSet    (objectname4, OBJPROP_COLOR, Black);
                 ObjectSetText(objectname4, "13:27PM:", font_size, "Arial", Black);
                }
  //-- Draw CloseLine5
       if (CloseLine5) // draw if true
         {
          string objectname5 = "CloseLine5"+i;
          if (ObjectFind   (objectname5) == -1) 
              ObjectCreate (objectname5, OBJ_VLINE, 0, CloseTime5, 0);
              ObjectSet    (objectname5, OBJPROP_COLOR,       Blue);
              ObjectSet    (objectname5, OBJPROP_WIDTH,       1); 
         }
        //-- Draw CloseLine5 Label -----------------------------------------      
             if (CloseLine5_label) // draw if true
                {
                 objectname5 = "CloseLine5_label"+i;
          
                 if (ObjectFind   (objectname5) == -1) 
                 ObjectCreate (objectname5, OBJ_TEXT, 0, 0, 0);
                 ObjectSet    (objectname5, OBJPROP_TIME1,CloseTime5 );
                 ObjectSet    (objectname5, OBJPROP_PRICE1, (Ask+2*Point) );
                 ObjectSet    (objectname5, OBJPROP_COLOR, Black);
                 ObjectSetText(objectname5, "14:30PM:", font_size, "Arial", Black);
                }
  //-- Draw CloseLine6        
       if (CloseLine6) // draw if true
         {
          string objectname6 = "CloseLine6"+i;
          if (ObjectFind   (objectname6) == -1) 
              ObjectCreate (objectname6, OBJ_VLINE, 0, CloseTime6, 0);
              ObjectSet    (objectname6, OBJPROP_COLOR,       Blue);
              ObjectSet    (objectname6, OBJPROP_WIDTH,       1); 
         }
        //-- Draw CloseLine6 Label -----------------------------------------      
             if (CloseLine6_label) // draw if true
                {
                 objectname6 = "CloseLine6_label"+i;
          
                 if (ObjectFind   (objectname6) == -1) 
                 ObjectCreate (objectname6, OBJ_TEXT, 0, 0, 0);
                 ObjectSet    (objectname6, OBJPROP_TIME1,CloseTime6 );
                 ObjectSet    (objectname6, OBJPROP_PRICE1, (Ask+2*Point) );
                 ObjectSet    (objectname6, OBJPROP_COLOR, Black);
                 ObjectSetText(objectname6, "16:29PM:", font_size, "Arial", Black);
                }
   }
 }
 //----
   return(0);
}
//+------------------------------------------------------------------+
 

I cannot see any reason why 3 of your labels are not showing, are all the input parameters the same as in the code?

You have the datetime value for the label, so you could use iBarShift to find the bar shift, then High[shift] to find the high of that bar. You can then place the label a little above the high. That way the labels will be visible when you scroll back through the chart.

 
pullend:

Hello forum, I put this indicator together to allow me to mark some local times on my charts that I have interest in.

Seems to work fine except for the labelling.

It works for me . . . sort of, it doesn't redraw the Objects when the timeframe is changed though.
 
RaptorUK:
It works for me . . . sort of, it doesn't redraw the Objects when the timeframe is changed though.



Thank you, the problem was that I was updating a version of the code, but not the version the terminal was using.

I'm still a bit confused as to what is where (folder wise) since the last MT4 update.

May need to re-install for my sanity!

 
pullend:


Thank you, the problem was that I was updating a version of the code, but not the version the terminal was using.

I'm still a bit confused as to what is where (folder wise) since the last MT4 update.

May need to re-install for my sanity!

If in doubt where Indicators, scripts and EAs go . . . File>Open Data Folder

Add this to your deinit()

Bar1Time = 0;
 
GumRai:

I cannot see any reason why 3 of your labels are not showing, are all the input parameters the same as in the code?

You have the datetime value for the label, so you could use iBarShift to find the bar shift, then High[shift] to find the high of that bar. You can then place the label a little above the high. That way the labels will be visible when you scroll back through the chart.


Thanks GumRai, I will try your suggestion.

As per my response to RaptorUK, I was attaching a version of the code that was different to the updated compiled version. MY APOLOGIES !!!

 
  1.    IndicatorShortName("CloseLine");
       IndicatorShortName("CloseLine2");
       IndicatorShortName("CloseLine3");
       IndicatorShortName("CloseLine4");
       IndicatorShortName("CloseLine5");
       IndicatorShortName("CloseLine6");
    
    Indicator has only one name
  2.           string objectname = "CloseLine"+i;
              if (ObjectFind   (objectname) == -1) 
                  ObjectCreate (objectname, OBJ_VLINE, 0, CloseTime, 0);
    
    You create Closeline1 .. Closeline6. the next bar you try to create Closeline1..6 but they already exist and you do nothing. Make your object names unique: "CloseLine"+Time[i]
Reason: