- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Meta Trader 4 Tester Bugs
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.
- 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.
- hknight: I want the highest value from the last 321 minutes while the market was open.
- highest of the last 321 M1 bars
- highest of the last iBarShift(now - 321*60) M1 bars
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.
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)); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use