I want this indicator to draw the first 4h range (H&L) of the day, for the rest of the day. everyday adjust to the new first 4h candle

 

Hello guys,
Im new to coding, and seeking your help with a little issue :) MT5
I want this indicator to draw two lines at the first 4H candle of the day, (one at the high & second at the low), and I want these two lines to stay fixed for the rest of the day, ( i don't want to draw the upcoming 4H candle, only the first one in the day).
Also, I want the indicator to do this process everyday.
i really appreciate any help.
The below attached code works exactly as I want, it is placed after the close of the first 4h in the day, however, it changes after another 4h close ( and i want to eliminate that)

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Files:
code.PNG  42 kb
 
Please attach the code properly if you have it, you may have noticed a </> icon on the ribbon toolbar at the top of the comment/post box.
 
Rami Khattab: Im new to coding, and seeking your help with a little issue :) MT5. I want this indicator to draw two lines at the first 4H candle of the day, (one at the high & second at the low), and I want these two lines to stay fixed for the rest of the day, ( i don't want to draw the upcoming 4H candle, only the first one in the day). Also, I want the indicator to do this process everyday. i really appreciate any help. The below attached code works exactly as I want, it is placed after the close of the first 4h in the day, however, it changes after another 4h close ( and i want to eliminate that)

The code you have shown in an image is for an EA and not an indicator. Indicators should use the the OnCalculate() event handler, not the OnTick() which is for EAs.

Also, instead of using graphic objects, use indicator buffers so that you will be able to see the values of the historical data and not just the current data.

Analyse other examples of MQL5 Indicators in the Codebase for a reference for your own code.

 
Rami Khattab: I want this indicator to draw two lines at the first 4H candle of the day, (one at the high & second at the low), and I want these two lines to stay fixed for the rest of the day,
Not compiled, not tested, just typed.
for( index ){
   datetime time     = iTime(_Symbol, _Period, index);
   datetime bod      = date(time);        // Beginning of the day.

   // Continue useing yesterday's values for the first four hours.
   if(time - bod < 4*3600) bod   = yesterday(time);

   datetime HR0359   = bod + 4*3600 - 1;  // Last bar of the first 4 hours

   int      iBod     = iBarShift(_Symbol, _Period, bod);
   int      iHR0359  = iBarShift(_Symbol, _Period, HR0359);
   int      nBars    = iBod - iHR0359 + 1;

   int      iHH      = iHighest(_Symbol, _Period, MODE_HIGH, nBars, iHR0359);
   int      iLL      = iLowest( _Symbol, _Period, MODE_LOW,  nBars, iHR0359);

   bufferHigh[index] = iHigh(_Symbol, _Period, iHH);
   bufferLow[ index] = iLow( _Symbol, _Period, iLL);
}
Not compiled, not tested, just typed.
          Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)