How to edit already calculated buffers in the indicator?

 
Hi,
I suppose my question is trivial, but I am strugglin with this. I want to draw straight lines on the chart when it hits specific hour and I want them to be longer than one bar. Lets say I have 1H Chart and when it is 12 o'clock I want lines drawn above 8:00, 9:00, 10:00 and 11:00 (I mean straight line from 8:00 to 11:00), but when I am trying to alter values in already calculated buffers everything on my chart disappears. Is there another way to achieve this? Should I call some "recalculate" function on my desired hour?
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[])
{
   MqlDateTime t;
   TimeToStruct(Time[0],t);
   if(t.hour == 12)
   {
      for( int i = 1; i <= 4; ++i )
      {
         buf0[i] = 150; // straight line at 150 height
      }  
   }
   return(rates_total);
}
 

Yes you can use a draw_once loop to draw the initial picture and then set a flag so that it doesn't run again.

Then on the next run you can overwrite the old picture with the new one.

 
Why don't you use the time buffer passed to OnCalculate?

   TimeToStruct(Time[0],t); // should be TimeToStruct(time[0],t);
 

Good point Amir time[0] sounds like more reasonable option.
Marco what do you mean exactly by draw_once loop? I tried to google it but couldn't find such thing as "draw_once".

 
use Objects
 
Mikołaj Gogola:

Good point Amir time[0] sounds like more reasonable option.
Marco what do you mean exactly by draw_once loop? I tried to google it but couldn't find such thing as "draw_once".

It's just a boolean flag you set.

Sometimes people use two loops one to draw history upon loading the expert and one that redraws a part of the current + n candles.

This is to prevent the indicator from redrawing all candles at every tick.

But i dont think it's applicable in your example.

Reason: