Download MetaTrader 5

How to get high of a certain time period

To add comments, please log in or register
bxchen
107
bxchen  

How to get high of a certain time period

 

 I want to get the high for e.g time of my forex broker

from 00:00:00 to 00:02:00

I want get the iHighest for the time period of 00:00:00 to 00:02:00 for Today

 

How do I achieve it , sorry for asking and thanks for helping !

 

rod178
269
rod178  

Read the documentation, such as - 

 

https://docs.mql4.com/series/ihighest             to find the shift 

then use  

 https://docs.mql4.com/series/ihigh               on the shift to find the high of the bar

whroeder1
16820
whroeder1  

bxchen:

How to get high of a certain time period

I want to get the high for e.g time of my forex broker

from 00:00:00 to 00:02:00

I want get the iHighest for the time period of 00:00:00 to 00:02:00 for Today

How do I achieve it , sorry for asking and thanks for helping !

  1. Get the starting/ending times.
  2. Get the starting/ending bar index
  3. Get the high for the range.
  4. learn to code and the available functions

#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
//datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
//                                          return(DateOfDay(when) + HR2400);   }
//datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
//   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1);
//                                       return( iTime(NULL, PERIOD_D1, iD1) ); }

#define HR0000 0
#define HR0002 (2*60)  // 00:02:00
datetime bod=DateOfDay();
int iM1Bod = iBarShift(NULL, PERIOD_M1, bod + HR0000);
int iM102  = iBarShift(NULL, PERIOD_M1, bod + HT0002 -1); // [0:00 - 0:02)
int iM1HH  = iHighest( NULL, PERIOD_M1, iM102 - iM1Bod + 1, iM1Bod);
double M1HH= iHigh(NULL, PERIOD_M1, iM1HH);
gregkevin
25
gregkevin  
I don't know about this and also want to know .  I think it is a good strategy.
Jagg
114
Jagg  
whroeder1:
  1. Get the starting/ending times.
  2. Get the starting/ending bar index
  3. Get the high for the range.
  4. learn to code and the available functions

Found this thread in google and just want to correct two lines from the code from @whroeder1 (thx for that code!)

I think it should look like this 

#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
//datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
//                                          return(DateOfDay(when) + HR2400);   }
//datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
//   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1);
//                                       return( iTime(NULL, PERIOD_D1, iD1) ); }

#define HR0000 0
#define HR0002 (2*60)  // 00:02:00
datetime bod=DateOfDay();
int iM1Bod = iBarShift(NULL, PERIOD_M1, bod + HR0000);
//int iM102  = iBarShift(NULL, PERIOD_M1, bod + HT0002 -1); // [0:00 - 0:02)
int iM102  = iBarShift(NULL, PERIOD_M1, bod + HR0002 -1); // [0:00 - 0:02) // <-- this was the old line (small typo HT0002 vs. HR0002)
//int iM1HH  = iHighest( NULL, PERIOD_M1, iM102 - iM1Bod + 1, iM1Bod); // <-- this was the old line
int iM1HH  = iHighest( NULL, PERIOD_M1, MODE_HIGH, iM1Bod - iM102 + 1, iM102);
double M1HH= iHigh(NULL, PERIOD_M1, iM1HH);
To add comments, please log in or register