my first custom indicator

 

I am trying to develop my first custom indicator. I only want the indicator to show on the charts during the overnight session. Therefore I added a simple IF clause to check for the hour of the day. The problem is that the indicator shows up for each hour of the day. I made a small change shown below from the standard indicator Bands.mq4. Any help would be greatly appreciated.

original code

UpperBuffer[i]=oldval+deviation;
LowerBuffer[i]=oldval-deviation;

new code

int tHour=TimeHour(TimeCurrent());
if (tHour >= 17 || tHour <= 20)
{  UpperBuffer[i]=oldval+deviation;
   LowerBuffer[i]=oldval-deviation; }
 
Don't use the CURRENT time, use the time of the BAR you are drawing.
int tHour=TimeHour(TimeCurrent());
int tHour=TimeHour(Time[i]);