Draw highest and lowest in day

 

Hi all,

I'm try to draw 2 horizontal line of highest and lowest value . Highest and Lowest get from 7:00 GMT yesterday to 6:59 GMT today. But in my code below, it can't draw like chart example (in file attachment)

Please help me to check error in my codes and tell me how can i do that . Thanks a lot.

Bizu

extern string USAEnd       = "07:00";

double P05[];
double P06[];
datetime dt = TimeCurrent();
datetime t04=StrToTime(TimeToStr(dt, TIME_DATE)+" "+USAEnd);    

int b04=iBarShift(NULL, M5, t04);   

 for (int m=0; m<100; m++) // Draw in 100 days

   {

      double P05=High[Highest(NULL, M5, MODE_HIGH, 288, b04+288*m)];   // count 288 candle on M5 per day     

     double P06=Low [Lowest (NULL, M5, MODE_LOW , 288, b04+288*m)];

} 

And draw 2 line follow code below :

#property indicator_buffers 2

#property indicator_color1 Green
#property indicator_style1 0
#property indicator_width1 0

#property indicator_color2 Red
#property indicator_style2 1
#property indicator_width2 1
SetIndexStyle(0,DRAW_LINE);

        SetIndexBuffer(0,P05);
        SetIndexLabel(0,"P05");
        SetIndexEmptyValue(1,0.0);
        
        SetIndexStyle(1,DRAW_LINE);
        SetIndexBuffer(1,P06);
        SetIndexLabel(1,"P06");
        SetIndexEmptyValue(1,0.0);



 
bizu:

Hi all,

I'm try to draw 2 horizontal line of highest and lowest value . Highest and Lowest get from 7:00 GMT yesterday to 6:59 GMT today. But in my code below, it can't draw like chart example (in file attachment)

Please help me to check error in my codes and tell me how can i do that . Thanks a lot.

Bizu

And draw 2 line follow code below

For your 100 bars . . .

datetime t04 = StrToTime(TimeToStr(dt, TIME_DATE)+" "+USAEnd);    

int b04 = iBarShift(NULL, M5, t04);   

for (int m=0; m<100; m++) // Draw in 100 days
   {
   double P05 = High[Highest(NULL, M5, MODE_HIGH, 288, b04+288*m)];   // count 288 candle on M5 per day     
   double P06 = Low [Lowest (NULL, M5, MODE_LOW , 288, b04+288*m)];
   } 

. . . the value of t04 and hence b04 stays the same . . . so you are always using the same starting time . . . and P05 and P06 are buffers

double P05[];
double P06[];

why are you declaring them again and not using them as buffers (arrays) ?

   double P05 = High[Highest(NULL, M5, MODE_HIGH, 288, b04+288*m)];   // count 288 candle on M5 per day     
   double P06 = Low [Lowest (NULL, M5, MODE_LOW , 288, b04+288*m)];
 

Thanks RaptorUK for reply me,

I have a missed when type code. The code in below is correct ? And it can draw like my chart in previous post ?

Thanks

for (int m=0; m<100; m++) // Draw in 100 days
   {
   double P05[m] = High[Highest(NULL, M5, MODE_HIGH, 288, b04+288*m)];   // count 288 candle on M5 per day     
   double P06[m] = Low [Lowest (NULL, M5, MODE_LOW , 288, b04+288*m)];
   } 

	          
 
bizu:

Thanks RaptorUK for reply me,

I have a missed when type code. The code in below is correct ? And it can draw like my chart in previous post ?

Thanks

Please read what I wrote . . .

RaptorUK:

For your 100 bars . . .

datetime t04 = StrToTime(TimeToStr(dt, TIME_DATE)+" "+USAEnd);    

int b04 = iBarShift(NULL, M5, t04);   

for (int m=0; m<100; m++) // Draw in 100 days
   {
   double P05 = High[Highest(NULL, M5, MODE_HIGH, 288, b04+288*m)];   // count 288 candle on M5 per day     
   double P06 = Low [Lowest (NULL, M5, MODE_LOW , 288, b04+288*m)];
   } 

. . . the value of t04 and hence b04 stays the same . . . so you are always using the same starting time . . . and P05 and P06 are buffers


Also, where is M5 defined ?
 
Highest and Lowest get from 7:00 GMT yesterday to 6:59 GMT today
// count 288 candle on M5 per day  
  1. No adjustments from broker time to GMT
  2. There are NOT 288 M5 candles per day.
 

Follow your review, I correct my codes in below . In my code, I refer to a post https://www.mql5.com/en/code/7753 with indicator i-Sessions.mq4 .

Please help me to fix this codes. Thanks a lot.

//+------------------------------------------------------------------+
//|                                                         HiLo.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color2 Green
#property indicator_style2 0
#property indicator_width2 0

#property indicator_color3 Red
#property indicator_style3 1
#property indicator_width3 1

double P05[];
double P06[];

extern int    NumberOfDays = 100;
extern string USAEnd       = "07:00"; 
datetime t04;
datetime dt01;
int i;

int init() {  
  
        SetIndexStyle(0,DRAW_LINE);
        SetIndexBuffer(0,P05);
        SetIndexLabel(0,"P05");
        SetIndexEmptyValue(0,0.0);
        
        SetIndexStyle(1,DRAW_LINE);
        SetIndexBuffer(1,P06);
        SetIndexLabel(1,"P06");
        SetIndexEmptyValue(0,0.0);
  
}

//+------------------------------------------------------------------+

int start() {
   datetime dt = TimeCurrent();
   for (i=0; i<NumberOfDays; i++) 
   {  
     datetime t04=StrToTime(TimeToStr(dt, TIME_DATE)+" "+USAEnd);    
     int b04=iBarShift(NULL, 0, t04);         
     P05[i]=High[Highest(NULL, PERIOD_M5, MODE_HIGH, 288, b04+288*i)];        
     P06[i]=Low [Lowest (NULL, PERIOD_M5, MODE_LOW , 288, b04+288*i)];       
   }   
   return(0);
}

//+------------------------------------------------------------------+
 
bizu:

Follow your review, I correct my codes in below .

Please help me to fix this codes. Thanks a lot.

You didn't correct anything. There are not 288 bars in a day.

// Highest and Lowest get from 7:00 GMT yesterday to 6:59 GMT today

Do you really mean yesterday, or 0700 last trading day? What do you display when the time of a bar is 0000 - 0659?


For GMT broker only. Not compiled, not tested.

#define HR2400 86400       // 24 * 3600
int      TimeOfDay(datetime when){  return( when % HR2400          );         }
datetime DateOfDay(datetime when){  return( when - TimeOfDay(when) );         }

// Highest and Lowest get from 7:00 GMT yesterday to 6:59 GMT today
#define HR0700 25200
int start(){
   for(int iBar = Bars - 1 - IndicatorCounted(); iBar >= 0; iBar--){
      datetime now           = Time[iBar],
               bod           = DateOfDay(now),
               today0700     = bod + HR0700,
               yesterday0700 = today0700 - HR2400;
     int       iYest  = iBarShift(NULL,0, yesterday0700),
               iToday = iBarShift(NULL,0, today0700),
               nBars  = iYest - iToday,                      // excluding 0700
               iHH    = iHighest(NULL,0, nBars, iToday + 1), // 06:59
               iLL    =  iLowest(NULL,0, nBars, iToday + 1);
     P05[iBar]=High[iHH];
     P06[iBar]=Low [iLL];
   }
}

For GMT broker only. Not compiled, not tested.

 

Thanks WHRoeder for your help,

With your code, how can i draw highest and lowest on everyday likes chart here : https://c.mql5.com/mql4/forum/2013/07/2013-07-24_094943.jpg

I'm newbie. Where can i get document and example for using Object, Custom indicator in MQL4 Reference.

Regards,

Bizu

 
bizu:

Thanks WHRoeder for your help,

With your code, how can i draw highest and lowest on everyday likes chart here : https://c.mql5.com/mql4/forum/2013/07/2013-07-24_094943.jpg

I'm newbie. Where can i get document and example for using Object, Custom indicator in MQL4 Reference.

Object Functions . . . Objects in the Book
Reason: