How to place text on chart using MQL

Please would some kind person explain what I’m doing wrong here (MT4 EA).

Compile 0 errors and Charts/Objects/Object List confirms the object, but no text appears on the chart (background black for clrWhite).

Tried without the if condition also with Time[0], Close[0] but no difference.

Many thanks.

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

int h=TimeHour(TimeCurrent());

void OnTick()

{

If if(h==9)

    {

ObjectCreate ("AtOpen",OBJ_TEXT,0,0,0);
ObjectCreate("AtOpen", OBJ_TEXT, 0,Time[1], Close[1] );
ObjectSetText ("AtOpen", "Opn:",10,"Calibri",clrWhite);

    }

}
ObjectCreate ("AtOpen",OBJ_TEXT,0,0,0);
ObjectCreate("AtOpen", OBJ_TEXT, 0,Time[1], Close[1] );
ObjectSetText ("AtOpen", "Opn:",10,"Calibri",clrWhite);
  1. The first created an object using time=0, it is on the extreme left, first bar of the chart.

  2. The second did nothing, you already have a object with that name.

  3. The third set the text.

Following your clue I inserted ObjectMove. Now I can see the “Opn:” text at the current bar using the CurrentTime variant.

I need the text to appear each day at 9am. Changing CurrentTime to 9 doesn’t work. Please would you show me how to do that.

ObjectCreate ("AtOpen",OBJ_TEXT,0,0,0);
ObjectMove( "AtOpen", 0, CurrentTime, High[1] );
ObjectSetText ("AtOpen", "Opn:",10,"Calibri",clrWhite);

Of course “Changing CurrentTime to 9 doesn’t work.” A datetime is seconds from 1970

#define HR0900 32400 // 9*3600
when = date() + HR0900;
if(when > TimeCurrent() when = yesterday() + HR0900;

Thanks for taking the time. Spent 2 hours trying to make it work to no avail. Whole thing just seems overly complex as mentioned in your link.

I didn’t want to sound ungrateful in any way as I appreciate the assistance offered.
As an absolute beginner I’m learning from those like @hblaise20 who are generous enough to send help to folks in this forum.

Just in case it may ever be of any interest (though I doubt it) to someone like myself who knows so very little of MQL but is attempting to learn partly by writing their EA, I discovered adjusting the ObjectCreate places the text object to the 9am bar as follows:

void OnTick()

  {
int h=TimeHour(TimeCurrent()); 
int m=TimeMinute(TimeCurrent());

//Session Open

if (h==9 && m==0)
      {
   ObjectCreate("AtOpen", OBJ_TEXT, 0, Time[0], High[0]);
   ObjectSetText ("AtOpen", "Opn:",10,"Calibri",clrWhite); 
      }

}     

Thanks again for the help, much appreciated.

int h=TimeHour(TimeCurrent()); 
int m=TimeMinute(TimeCurrent());
if (h==9 && m==0)

That only works if there is a tick during that minute, otherwise it fails. There can be minutes between ticks during the Asian session, think M1 chart.