Highest value of pair over the past 321 minutes

 
How can I get the highest value of a pair over the past 321 minutes?

I don't want the high value for 300 minutes or 360 minutes.  It has to be 321 minutes.

If it is early Monday morning then it should count the most recent minutes from Monday as well as the remaining minutes from Friday.

 
hknight:
How can I get the highest value of a pair over the past 321 minutes?

I don't want the high value for 300 minutes or 360 minutes.  It has to be 321 minutes.

If it is early Monday morning then it should count the most recent minutes from Monday as well as the remaining minutes from Friday.

Do you want the last 321 minutes while the market was open or the last 321 M1 bars ?  you need to be specific about what you want . . .  it is very possible that some minutes may not have an M1 bar at all. 
 
I want the highest value from the last 321 minutes while the market was open.  If a minute does not have an M1 bar then it should not be counted.
 
hknight:
I want the highest value from the last 321 minutes while the market was open.  If a minute does not have an M1 bar then it should not be counted.

You are going to have to compensate in code to handle the weekend . . .  but essentially what you need is the bar number for TimeCurrent() - (321 * 60) using iBarshift() and then you can use iHighest() with this bar number to get the bar number for the highest bar and then use that with High[]/iHigh()  . . . but as I said,  the weekend is going to be awkward to handle.

Perhaps a bit of reverse logic will help . . .  get the datetime for 321 bars ago and see if that is close to the datetime for 321 minutes ago,  if it's close then you don't have a weekend involved . . .  if it hours out then you do.  Just a thought. 

 
  1. hknight: If it is early Monday morning then it should count the most recent minutes from Monday as well as the remaining minutes from Friday.
  2. hknight: I want the highest value from the last 321 minutes while the market was open.
These are contradictive. You need to redefine your requirement.
  1. highest of the last 321 M1 bars
  2. highest of the last iBarShift(now - 321*60) M1 bars
 
RaptorUK:

Perhaps a bit of reverse logic will help . . .  get the datetime for 321 bars ago and see if that is close to the datetime for 321 minutes ago,  if it's close then you don't have a weekend involved . . .  if it hours out then you do.  Just a thought. 

if(TimeCurrent()- iTime(Symbol(),PERIOD_M5,64)>24*60*60)Print ("weekend or market holiday involved");

in the first 320 minutes we can still miss M1 bars  For M5 it will be less possible

a day is counting 60*60*24 seconds so that will be at least the time for market holiday.  

 
hknight:
I want the highest value from the last 321 minutes while the market was open.  If a minute does not have an M1 bar then it should not be counted.

Here is some code for you to start with:

datetime now = TimeCurrent();
if (TimeDayOfWeek(now) > 0 && TimeDayOfWeek(now - (321 * 60)) > 0)      // both dates must be greater than or equal to Monday
   if (TimeDayOfWeek(now) < 6 && TimeDayOfWeek(now - (321 * 60)) < 6) { // both dates must be less than Saturday
      int start_bar = iBarShift(Symbol(), PERIOD_M1, now - (321 * 60));
      // NOTE: need error check to determine if history is/needs updating
      if (start_bar >= 0)
         if (iTime(Symbol(), PERIOD_M1, start_bar) <= now - (321 * 60) && now - (321 * 60) > iTime(Symbol(), PERIOD_M1, start_bar + 1))
            Print ("The highest price is: ", DoubleToStr(iHigh(Symbol(), PERIOD_M1, iHighest(Symbol(), PERIOD_M1, MODE_HIGH, start_bar, 0)), Digits));
   }