Request for help determining the iHH / iLL

 

Good evening all,

In order to improve the quality of my alerts I need to calculate the Highest High and the Lowest Low on every day starting from Midnight to any bar on any day, so that would be [i].

I found this thread where Whroeder explains how something like this should be done: https://www.mql5.com/en/forum/139445

Based on his explanation I wrote the following code, the code compiles without errors, but it isn't working. Can someone please tell me what I'm doing wrong here?

         bool     RangeUP      = true;
         double   factor       = 10000;
         if (Digits <=3) {factor = 100;}

         datetime now         = Time[0],
                  bod         = now - now % 86400; // Beginning of the day
         int      iBod        = iBarShift(NULL,PERIOD_M5, bod);
         int      Barsfrombod = iBod - i + 1;
         double   HHFrombod   = Close[iHighest(NULL,PERIOD_M5, MODE_CLOSE,Barsfrombod,i)];
         datetime TimeHHfb    = Time[iHighest(NULL,PERIOD_M5, MODE_CLOSE,Barsfrombod,i)];
         int      BarHHfb     = iBarShift(NULL,PERIOD_M5, TimeHHfb, false);
         double   LLFrombod   = Close[iLowest(NULL,PERIOD_M5, MODE_CLOSE, Barsfrombod,i)];
         datetime TimeLLfb    = Time[iLowest(NULL,PERIOD_M5, MODE_CLOSE,Barsfrombod,i)];
         int      BarLLfb     = iBarShift(NULL,PERIOD_M5, TimeLLfb, false);
         double   RangeHHLL   = (HHFrombod - LLFrombod) * factor;//number of pips between HH and LL since midnight
         
         if(BarHHfb < BarLLfb) {RangeUP = true;} else {RangeUP = false;}// has the range been up or down
High/low of first for bars of new day
High/low of first for bars of new day
  • 2012.05.12
  • www.mql5.com
Hi all, I was just wondering if anyone could let me know if i am on the right track...
 
ReactoFX:

Good evening all,

In order to improve the quality of my alerts I need to calculate the Highest High and the Lowest Low on every day starting from Midnight to any bar on any day, so that would be [i].

I found this thread where Whroeder explains how something like this should be done: https://www.mql5.com/en/forum/139445

Based on his explanation I wrote the following code, the code compiles without errors, but it isn't working. Can someone pleas tell me what I'm doing wrong here?

I'm not sure I follow... If all you need is the High and Low of the current day's bar then why are you using the code above? That code will give you the H/L of a rolling 24h window. This is an example of how to get the H/L from today on the the current timeframe

void OnStart()
{
   RefreshRates();
   datetime day_begin = iTime(_Symbol, PERIOD_D1, 0);
   int x = iBarShift(_Symbol, PERIOD_CURRENT, day_begin);
   int index_high = ArrayMaximum(High, x, 0);
   int index_low = ArrayMinimum(Low, x, 0);
   printf("High of Today is %.5f @ %s", 
      High[index_high],
      TimeToString(Time[index_high])
   );
   printf("Low of Today is %.5f @ %s", 
      Low[index_low],
      TimeToString(Time[index_low])
   );
}
 

Hi Nicholi Shen,


Thanks for your response.

The thing is I need the H/L of a rolling 24h window so I can check the effect of adding this condition to my existing alerts. The idea is to eliminate alerts that do not qualify as high probability.

 
ReactoFXThe thing is I need the H/L of a rolling 24h window

Then next time I'd suggest reviewing your post before you submit it. 

I need to calculate the Highest High and the Lowest Low on every day starting from Midnight

 

I need to calculate the Highest High and the Lowest Low on every day starting from Midnight

So that is not just on the current day.

 
ReactoFX:

I need to calculate the Highest High and the Lowest Low on every day starting from Midnight

So that is not just on the current day.

It's either "every day from midnight" or a "rolling 24h window", not the same thing. Make up your mind and clarify what you are looking for please.
 

It is as I wrote originally every day from midnight


I want the code to take into account the number of pips between de HH end LL formed after midnight of each day.

I want it to calculate the range on any moment of each day


I hope this clarifies my original request, because I wouldn't know how to put it any clearer.

 
nicholi shen:

Then next time I'd suggest reviewing your post before you submit it. 

Hi again Nicholi Shen,


Apparently I was tired yesterday evening and didn't understand your response correctly. I read it again today and I would like to thank you for your explanation.

It was only now I saw that I did not have coded Midnight. The example I used mentioned " Beginning of the day" and I took that for Midnight.

I'll use your code and hope to get this working.


Thanks

 

Hi Nicholi Shen,


I saw in your code you used shift zero, so that will return only the last midnight. I need every midnight, so I changed my code as shown below, but it still doesn't work. Can you tell me what I'm doing wrong her please.

         datetime DayStart    = iTime(NULL,PERIOD_D1,i);
         int      BarDS       = iBarShift(NULL,PERIOD_M5,DayStart, false);
         int      Shift       = BarDS-i+1;
         double   HHFromDS    = Close[iHighest(NULL,PERIOD_M5, MODE_CLOSE,Shift,i)];
         datetime TimeHHDS    = Time[iHighest(NULL,PERIOD_M5, MODE_CLOSE,Shift,i)];
         int      BarHHDS     = iBarShift(NULL,PERIOD_M5, TimeHHDS, false);
         double   LLFromDS    = Close[iLowest(NULL,PERIOD_M5, MODE_CLOSE, Shift,i)];
         datetime TimeLLDS    = Time[iLowest(NULL,PERIOD_M5, MODE_CLOSE,Shift,i)];
         int      BarLLDS     = iBarShift(NULL,PERIOD_M5, TimeLLDS, false);
         double   RangeHHLL   = (HHFromDS - LLFromDS) * factor;//number of pips between HH and LL since midnight
 
ReactoFX:

Hi Nicholi Shen,


I saw in your code you used shift zero, so that will return only the last midnight. I need every midnight, so I changed my code as shown below, but it still doesn't work. Can you tell me what I'm doing wrong her please.

Don't ever use the platform timeseries (High, Low, etc.) when you specify a timeframe. Instead you have to use iTimeseries functions

 

I was not familiar with those, I will study them first,


Thanks